diff --git a/openmp/libomptarget/src/api.cpp b/openmp/libomptarget/src/api.cpp --- a/openmp/libomptarget/src/api.cpp +++ b/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) { diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h --- a/openmp/runtime/src/kmp.h +++ b/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 diff --git a/openmp/runtime/src/kmp_ftn_entry.h b/openmp/runtime/src/kmp_ftn_entry.h --- a/openmp/runtime/src/kmp_ftn_entry.h +++ b/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 diff --git a/openmp/runtime/test/api/omp_pause_resource.c b/openmp/runtime/test/api/omp_pause_resource.c --- a/openmp/runtime/test/api/omp_pause_resource.c +++ b/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