[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 23 06:03:58 PDT 2020
protze.joachim created this revision.
protze.joachim added reviewers: jdoerfert, AndreyChurbanov, ABataev.
protze.joachim added a project: OpenMP.
Herald added subscribers: guansong, yaxunl.
protze.joachim requested review of this revision.
Herald added a subscriber: sstefan1.
OpenMP 5.1 defines `omp_get_initial_device` to return the same value as `omp_get_num_devices`.
Since this change is also 5.0 compliant, no versioning is needed.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D88149
Files:
openmp/libomptarget/src/api.cpp
openmp/runtime/src/kmp.h
openmp/runtime/src/kmp_ftn_entry.h
openmp/runtime/test/api/omp_pause_resource.c
Index: openmp/runtime/test/api/omp_pause_resource.c
===================================================================
--- openmp/runtime/test/api/omp_pause_resource.c
+++ openmp/runtime/test/api/omp_pause_resource.c
@@ -13,8 +13,10 @@
#pragma omp single
nthreads = omp_get_num_threads();
- if (omp_pause_resource(omp_pause_soft, my_dev))
+ if (omp_pause_resource(omp_pause_soft, my_dev)) {
+ printf("omp_pause_resource(omp_pause_soft, my_dev)");
fails++;
+ }
#pragma omp parallel shared(nthreads)
#pragma omp single
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,13 @@
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;
+ return 0; // omp_get_num_devices()
#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;
+ return 0; // omp_get_num_devices()
}
#endif
}
@@ -1319,14 +1319,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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88149.293708.patch
Type: text/x-patch
Size: 3017 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20200923/f242a104/attachment.bin>
More information about the Openmp-commits
mailing list