[Openmp-commits] [PATCH] D88149: [OpenMP][libomptarget] make omp_get_initial_device 5.1 compliant

Joachim Protze via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Wed Sep 30 15:58:42 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG55cff5b28865: [OpenMP][libomptarget] make omp_get_initial_device 5.1 compliant (authored by protze.joachim).

Changed prior to commit:
  https://reviews.llvm.org/D88149?vs=294014&id=295429#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88149/new/

https://reviews.llvm.org/D88149

Files:
  openmp/libomptarget/include/omptarget.h
  openmp/libomptarget/src/api.cpp
  openmp/runtime/src/kmp.h
  openmp/runtime/src/kmp_ftn_entry.h


Index: openmp/runtime/src/kmp_ftn_entry.h
===================================================================
--- openmp/runtime/src/kmp_ftn_entry.h
+++ openmp/runtime/src/kmp_ftn_entry.h
@@ -966,13 +966,15 @@
 int FTN_STDCALL FTN_GET_INITIAL_DEVICE(void) KMP_WEAK_ATTRIBUTE_EXTERNAL;
 int FTN_STDCALL FTN_GET_INITIAL_DEVICE(void) {
 #if KMP_MIC || KMP_OS_DARWIN || KMP_OS_WINDOWS || defined(KMP_STUB)
-  return KMP_HOST_DEVICE;
+  // same as omp_get_num_devices()
+  return 0;
 #else
   int (*fptr)();
   if ((*(void **)(&fptr) = dlsym(RTLD_NEXT, "omp_get_initial_device"))) {
     return (*fptr)();
   } else { // liboffload & libomptarget don't exist
-    return KMP_HOST_DEVICE;
+    // same as omp_get_num_devices()
+    return 0;
   }
 #endif
 }
@@ -1319,14 +1321,14 @@
 // loaded, we assume we are on the host and return KMP_HOST_DEVICE.
 // Compiler/libomptarget will handle this if called inside target.
 int FTN_STDCALL FTN_GET_DEVICE_NUM(void) KMP_WEAK_ATTRIBUTE_EXTERNAL;
-int FTN_STDCALL FTN_GET_DEVICE_NUM(void) { return KMP_HOST_DEVICE; }
+int FTN_STDCALL FTN_GET_DEVICE_NUM(void) { return FTN_GET_INITIAL_DEVICE(); }
 
 // Compiler will ensure that this is only called from host in sequential region
 int FTN_STDCALL FTN_PAUSE_RESOURCE(kmp_pause_status_t kind, int device_num) {
 #ifdef KMP_STUB
   return 1; // just fail
 #else
-  if (device_num == KMP_HOST_DEVICE)
+  if (device_num == FTN_GET_INITIAL_DEVICE())
     return __kmpc_pause_resource(kind);
   else {
 #if !KMP_OS_WINDOWS
Index: openmp/runtime/src/kmp.h
===================================================================
--- openmp/runtime/src/kmp.h
+++ openmp/runtime/src/kmp.h
@@ -3876,7 +3876,6 @@
 
 // Constants used in libomptarget
 #define KMP_DEVICE_DEFAULT -1 // This is libomptarget's default device.
-#define KMP_HOST_DEVICE -10 // This is what it is in libomptarget, go figure.
 #define KMP_DEVICE_ALL -11 // This is libomptarget's "all devices".
 
 // OMP Pause Resource
Index: openmp/libomptarget/src/api.cpp
===================================================================
--- openmp/libomptarget/src/api.cpp
+++ openmp/libomptarget/src/api.cpp
@@ -29,8 +29,9 @@
 }
 
 EXTERN int omp_get_initial_device(void) {
-  DP("Call to omp_get_initial_device returning %d\n", HOST_DEVICE);
-  return HOST_DEVICE;
+  int hostDevice = omp_get_num_devices();
+  DP("Call to omp_get_initial_device returning %d\n", hostDevice);
+  return hostDevice;
 }
 
 EXTERN void *omp_target_alloc(size_t size, int device_num) {
Index: openmp/libomptarget/include/omptarget.h
===================================================================
--- openmp/libomptarget/include/omptarget.h
+++ openmp/libomptarget/include/omptarget.h
@@ -21,7 +21,6 @@
 #define OFFLOAD_FAIL (~0)
 
 #define OFFLOAD_DEVICE_DEFAULT     -1
-#define HOST_DEVICE                -10
 
 /// Data attributes for each data reference used in an OpenMP target region.
 enum tgt_map_type {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88149.295429.patch
Type: text/x-patch
Size: 2932 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20200930/9edcd04f/attachment-0001.bin>


More information about the Openmp-commits mailing list