[clang] [OpenMP] Associate the KernelEnvironment with the GenericKernelTy (PR #70383)

Joseph Huber via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 29 10:43:06 PDT 2023


================
@@ -339,9 +339,33 @@ Error GenericKernelTy::init(GenericDeviceTy &GenericDevice,
 
   ImagePtr = &Image;
 
-  PreferredNumThreads = GenericDevice.getDefaultNumThreads();
+  // Retrieve kernel environment object for the kernel.
+  GlobalTy KernelEnv(std::string(Name) + "_kernel_environment",
+                     sizeof(KernelEnvironment), &KernelEnvironment);
+  GenericGlobalHandlerTy &GHandler = Plugin::get().getGlobalHandler();
+  if (auto Err =
+          GHandler.readGlobalFromImage(GenericDevice, *ImagePtr, KernelEnv)) {
+    [[maybe_unused]] std::string ErrStr = toString(std::move(Err));
+    DP("Failed to read kernel environment for '%s': %s\n"
+       "Using default SPMD (2) execution mode\n",
+       Name, ErrStr.data());
+    KernelEnvironment.Configuration.ExecMode = OMP_TGT_EXEC_MODE_SPMD;
+    KernelEnvironment.Configuration.MayUseNestedParallelism = /* Unknown */ 2;
----------------
jhuber6 wrote:

```suggestion
    KernelEnvironment.Configuration.MayUseNestedParallelism = /*Unknown=*/2;
```

https://github.com/llvm/llvm-project/pull/70383


More information about the cfe-commits mailing list