[Openmp-commits] [openmp] bfe5452 - [OpenMP] Fix lone target exit data

Joel E. Denny via Openmp-commits openmp-commits at lists.llvm.org
Thu Mar 4 09:12:59 PST 2021


Author: Joel E. Denny
Date: 2021-03-04T12:03:42-05:00
New Revision: bfe5452b93a7d859f612bf7e8b46aa626c8c8e83

URL: https://github.com/llvm/llvm-project/commit/bfe5452b93a7d859f612bf7e8b46aa626c8c8e83
DIFF: https://github.com/llvm/llvm-project/commit/bfe5452b93a7d859f612bf7e8b46aa626c8c8e83.diff

LOG: [OpenMP] Fix lone target exit data

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 many other runtime routines.

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

Reviewed By: grokos

Differential Revision: https://reviews.llvm.org/D97907

Added: 
    openmp/libomptarget/test/offloading/lone_target_exit_data.c

Modified: 
    openmp/libomptarget/src/interface.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/src/interface.cpp b/openmp/libomptarget/src/interface.cpp
index 233ef23083a3..24706009ecf0 100644
--- a/openmp/libomptarget/src/interface.cpp
+++ b/openmp/libomptarget/src/interface.cpp
@@ -272,21 +272,13 @@ EXTERN void __tgt_target_data_end_mapper(ident_t *loc, int64_t device_id,
     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,

diff  --git a/openmp/libomptarget/test/offloading/lone_target_exit_data.c b/openmp/libomptarget/test/offloading/lone_target_exit_data.c
new file mode 100644
index 000000000000..0bbbb9ef5f20
--- /dev/null
+++ b/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;
+}


        


More information about the Openmp-commits mailing list