================
@@ -561,30 +561,38 @@ Error GenericKernelTy::launch(GenericDeviceTy 
&GenericDevice, void **ArgPtrs,
                     LaunchParams, AsyncInfoWrapper);
 }
 
-KernelLaunchParamsTy GenericKernelTy::prepareArgs(
-    GenericDeviceTy &GenericDevice, void **ArgPtrs, ptrdiff_t *ArgOffsets,
-    uint32_t &NumArgs, llvm::SmallVectorImpl<void *> &Args,
-    llvm::SmallVectorImpl<void *> &Ptrs,
-    KernelLaunchEnvironmentTy *KernelLaunchEnvironment) const {
-  uint32_t KLEOffset = !!KernelLaunchEnvironment;
-  NumArgs += KLEOffset;
-
+KernelLaunchParamsTy
+GenericKernelTy::prepareArgs(GenericDeviceTy &GenericDevice, void **ArgPtrs,
+                             ptrdiff_t *ArgOffsets, uint32_t &NumArgs,
+                             llvm::SmallVectorImpl<void *> &Args,
+                             llvm::SmallVectorImpl<void *> &Ptrs,
+                             KernelLaunchEnvironmentTy 
*KernelLaunchEnvironment,
+                             uint32_t Version) const {
   if (NumArgs == 0)
     return KernelLaunchParamsTy{};
 
+  // The argument arrays already include the dyn_ptr slot at the end (appended
+  // by the host for version >= 4, or by upgradeKernelArgs for version 3).
   Args.resize(NumArgs);
   Ptrs.resize(NumArgs);
 
-  if (KernelLaunchEnvironment) {
-    Args[0] = KernelLaunchEnvironment;
-    Ptrs[0] = &Args[0];
-  }
+  for (uint32_t I = 0; I < NumArgs; ++I)
+    Args[I] = reinterpret_cast<void *>(reinterpret_cast<intptr_t>(ArgPtrs[I]) +
+                                       ArgOffsets[I]);
+
+  // Optionally assign the KernelLaunchEnvironment to the last slot (dyn_ptr).
+  if (KernelLaunchEnvironment)
+    Args[NumArgs - 1] = KernelLaunchEnvironment;
 
-  for (uint32_t I = KLEOffset; I < NumArgs; ++I) {
-    Args[I] =
-        (void *)((intptr_t)ArgPtrs[I - KLEOffset] + ArgOffsets[I - KLEOffset]);
+  // Version 3 device kernels have dyn_ptr baked in at position 0. Rotate the
+  // last element to the front to match the device ABI.
+  if (Version <= OMP_KERNEL_ARG_MIN_VERSION_WITH_DYN_PTR &&
----------------
kevinsala wrote:

Why is `<=` instead of `==`?

https://github.com/llvm/llvm-project/pull/185989
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to