forked from OSchip/llvm-project
[OpenMP][libomptarget] make omp_get_initial_device 5.1 compliant
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. Differential Revision: https://reviews.llvm.org/D88149
This commit is contained in:
parent
37b2e2b04c
commit
55cff5b288
|
@ -21,7 +21,6 @@
|
||||||
#define OFFLOAD_FAIL (~0)
|
#define OFFLOAD_FAIL (~0)
|
||||||
|
|
||||||
#define OFFLOAD_DEVICE_DEFAULT -1
|
#define OFFLOAD_DEVICE_DEFAULT -1
|
||||||
#define HOST_DEVICE -10
|
|
||||||
|
|
||||||
/// Data attributes for each data reference used in an OpenMP target region.
|
/// Data attributes for each data reference used in an OpenMP target region.
|
||||||
enum tgt_map_type {
|
enum tgt_map_type {
|
||||||
|
|
|
@ -29,8 +29,9 @@ EXTERN int omp_get_num_devices(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
EXTERN int omp_get_initial_device(void) {
|
EXTERN int omp_get_initial_device(void) {
|
||||||
DP("Call to omp_get_initial_device returning %d\n", HOST_DEVICE);
|
int hostDevice = omp_get_num_devices();
|
||||||
return HOST_DEVICE;
|
DP("Call to omp_get_initial_device returning %d\n", hostDevice);
|
||||||
|
return hostDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
EXTERN void *omp_target_alloc(size_t size, int device_num) {
|
EXTERN void *omp_target_alloc(size_t size, int device_num) {
|
||||||
|
|
|
@ -3876,7 +3876,6 @@ extern int __kmpc_get_target_offload();
|
||||||
|
|
||||||
// Constants used in libomptarget
|
// Constants used in libomptarget
|
||||||
#define KMP_DEVICE_DEFAULT -1 // This is libomptarget's default device.
|
#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".
|
#define KMP_DEVICE_ALL -11 // This is libomptarget's "all devices".
|
||||||
|
|
||||||
// OMP Pause Resource
|
// OMP Pause Resource
|
||||||
|
|
|
@ -966,13 +966,15 @@ int FTN_STDCALL KMP_EXPAND_NAME(FTN_IS_INITIAL_DEVICE)(void) {
|
||||||
int FTN_STDCALL FTN_GET_INITIAL_DEVICE(void) KMP_WEAK_ATTRIBUTE_EXTERNAL;
|
int FTN_STDCALL FTN_GET_INITIAL_DEVICE(void) KMP_WEAK_ATTRIBUTE_EXTERNAL;
|
||||||
int FTN_STDCALL FTN_GET_INITIAL_DEVICE(void) {
|
int FTN_STDCALL FTN_GET_INITIAL_DEVICE(void) {
|
||||||
#if KMP_MIC || KMP_OS_DARWIN || KMP_OS_WINDOWS || defined(KMP_STUB)
|
#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
|
#else
|
||||||
int (*fptr)();
|
int (*fptr)();
|
||||||
if ((*(void **)(&fptr) = dlsym(RTLD_NEXT, "omp_get_initial_device"))) {
|
if ((*(void **)(&fptr) = dlsym(RTLD_NEXT, "omp_get_initial_device"))) {
|
||||||
return (*fptr)();
|
return (*fptr)();
|
||||||
} else { // liboffload & libomptarget don't exist
|
} else { // liboffload & libomptarget don't exist
|
||||||
return KMP_HOST_DEVICE;
|
// same as omp_get_num_devices()
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -1319,14 +1321,14 @@ int FTN_STDCALL KMP_EXPAND_NAME(FTN_GET_MAX_TASK_PRIORITY)(void) {
|
||||||
// loaded, we assume we are on the host and return KMP_HOST_DEVICE.
|
// loaded, we assume we are on the host and return KMP_HOST_DEVICE.
|
||||||
// Compiler/libomptarget will handle this if called inside target.
|
// 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) 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
|
// 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) {
|
int FTN_STDCALL FTN_PAUSE_RESOURCE(kmp_pause_status_t kind, int device_num) {
|
||||||
#ifdef KMP_STUB
|
#ifdef KMP_STUB
|
||||||
return 1; // just fail
|
return 1; // just fail
|
||||||
#else
|
#else
|
||||||
if (device_num == KMP_HOST_DEVICE)
|
if (device_num == FTN_GET_INITIAL_DEVICE())
|
||||||
return __kmpc_pause_resource(kind);
|
return __kmpc_pause_resource(kind);
|
||||||
else {
|
else {
|
||||||
#if !KMP_OS_WINDOWS
|
#if !KMP_OS_WINDOWS
|
||||||
|
|
Loading…
Reference in New Issue