[Openmp-commits] [llvm] [clang] [openmp] [OpenMP] Rework handling of global ctor/dtors in OpenMP (PR #71739)

Jan Patrick Lehr via Openmp-commits openmp-commits at lists.llvm.org
Thu Nov 9 01:40:43 PST 2023


================
@@ -2627,6 +2637,48 @@ struct AMDGPUDeviceTy : public GenericDeviceTy, AMDGenericDeviceTy {
   using AMDGPUEventRef = AMDGPUResourceRef<AMDGPUEventTy>;
   using AMDGPUEventManagerTy = GenericDeviceResourceManagerTy<AMDGPUEventRef>;
 
+  /// Common method to invoke a single threaded constructor or destructor
+  /// kernel by name.
+  Error callGlobalCtorDtorCommon(GenericPluginTy &Plugin, DeviceImageTy &Image,
+                                 const char *Name) {
+    // Perform a quick check for the named kernel in the image. The kernel
+    // should be created by the 'amdgpu-lower-ctor-dtor' pass.
+    GenericGlobalHandlerTy &Handler = Plugin.getGlobalHandler();
+    GlobalTy Global(Name, sizeof(void *));
+    if (auto Err = Handler.getGlobalMetadataFromImage(*this, Image, Global)) {
+      consumeError(std::move(Err));
+      return Error::success();
+    }
+
+    // Allocate and construct the AMDGPU kernel.
+    GenericKernelTy *AMDGPUKernel = Plugin.allocate<AMDGPUKernelTy>();
+    if (!AMDGPUKernel)
+      return Plugin::error("Failed to allocate memory for AMDGPU kernel");
+
+    new (AMDGPUKernel) AMDGPUKernelTy(Name);
+    if (auto Err = AMDGPUKernel->initImpl(*this, Image))
+      return std::move(Err);
+
+    auto *AsyncInfoPtr = Plugin.allocate<__tgt_async_info>();
+    AsyncInfoWrapperTy AsyncInfoWrapper(*this, AsyncInfoPtr);
+
+    if (auto Err = initAsyncInfoImpl(AsyncInfoWrapper))
+      return std::move(Err);
+
+    KernelArgsTy KernelArgs = {};
+    if (auto Err = AMDGPUKernel->launchImpl(*this, /*NumThread=*/1u,
+                                            /*NumBlocks=*/1ul, KernelArgs,
+                                            /*Args=*/nullptr, AsyncInfoWrapper))
+      return std::move(Err);
+
+    if (auto Err = synchronize(AsyncInfoPtr))
+      return std::move(Err);
+    Error Err = Error::success();
----------------
jplehr wrote:

Should this be `Plugin::success()` instead here as well?

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


More information about the Openmp-commits mailing list