[Openmp-commits] [PATCH] D97907: [OpenMP] Fix lone target exit data

Joel E. Denny via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Wed Mar 3 19:42:42 PST 2021


jdenny created this revision.
jdenny added reviewers: grokos, RaviNarayanaswamy, jdoerfert.
Herald added subscribers: guansong, yaxunl.
jdenny requested review of this revision.
Herald added a subscriber: sstefan1.
Herald added a project: OpenMP.

Without this patch, an `omp target exit data` before the runtime is
initialized produces a runtime error.  This patch fixes that by
changing `__tgt_target_data_end_mapper` to call `CheckDeviceAndCtors`
like other many other runtime routines.

Discussed at
https://lists.llvm.org/pipermail/openmp-dev/2021-March/003920.html.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97907

Files:
  openmp/libomptarget/src/interface.cpp
  openmp/libomptarget/test/offloading/lone_target_exit_data.c


Index: openmp/libomptarget/test/offloading/lone_target_exit_data.c
===================================================================
--- /dev/null
+++ openmp/libomptarget/test/offloading/lone_target_exit_data.c
@@ -0,0 +1,18 @@
+// Check that a target exit data directive behaves correctly when the runtime
+// has not yet been initialized.
+
+// RUN: %libomptarget-compile-run-and-check-aarch64-unknown-linux-gnu
+// RUN: %libomptarget-compile-run-and-check-powerpc64-ibm-linux-gnu
+// RUN: %libomptarget-compile-run-and-check-powerpc64le-ibm-linux-gnu
+// RUN: %libomptarget-compile-run-and-check-x86_64-pc-linux-gnu
+// RUN: %libomptarget-compile-run-and-check-nvptx64-nvidia-cuda
+
+#include <stdio.h>
+
+int main() {
+  // CHECK: x = 98
+  int x = 98;
+  #pragma omp target exit data map(from:x)
+  printf("x = %d\n", x);
+  return 0;
+}
Index: openmp/libomptarget/src/interface.cpp
===================================================================
--- openmp/libomptarget/src/interface.cpp
+++ openmp/libomptarget/src/interface.cpp
@@ -272,21 +272,13 @@
     return;
   }
 
-  PM->RTLsMtx.lock();
-  size_t DevicesSize = PM->Devices.size();
-  PM->RTLsMtx.unlock();
-  if (DevicesSize <= (size_t)device_id) {
-    DP("Device ID  %" PRId64 " does not have a matching RTL.\n", device_id);
+  if (CheckDeviceAndCtors(device_id) != OFFLOAD_SUCCESS) {
+    DP("Failed to get device %" PRId64 " ready\n", device_id);
     HandleTargetOutcome(false, loc);
     return;
   }
 
   DeviceTy &Device = PM->Devices[device_id];
-  if (!Device.IsInit) {
-    DP("Uninit device: ignore");
-    HandleTargetOutcome(false, loc);
-    return;
-  }
 
   if (getInfoLevel() & OMP_INFOTYPE_KERNEL_ARGS)
     printKernelArguments(loc, device_id, arg_num, arg_sizes, arg_types,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97907.327994.patch
Type: text/x-patch
Size: 1765 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210304/de885577/attachment-0001.bin>


More information about the Openmp-commits mailing list