[Openmp-commits] [PATCH] D91713: [libomptarget] Implement get_device_num for amdgcn, nvptx
Jon Chesterfield via Phabricator via Openmp-commits
openmp-commits at lists.llvm.org
Wed Nov 18 08:07:51 PST 2020
JonChesterfield created this revision.
JonChesterfield added reviewers: jdoerfert, ABataev, grokos.
Herald added subscribers: openmp-commits, kerbowa, nhaehnle, jvesely.
Herald added a project: OpenMP.
JonChesterfield requested review of this revision.
Herald added a subscriber: sstefan1.
[libomptarget] Implement get_device_num for amdgcn, nvptx
Adds a field to the existing environment struct which is used for debug_level.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D91713
Files:
openmp/libomptarget/deviceRTLs/common/device_environment.h
openmp/libomptarget/deviceRTLs/common/src/libcall.cu
openmp/libomptarget/deviceRTLs/interface.h
openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
openmp/libomptarget/plugins/cuda/src/rtl.cpp
Index: openmp/libomptarget/plugins/cuda/src/rtl.cpp
===================================================================
--- openmp/libomptarget/plugins/cuda/src/rtl.cpp
+++ openmp/libomptarget/plugins/cuda/src/rtl.cpp
@@ -83,6 +83,7 @@
/// file later.
struct omptarget_device_environmentTy {
int32_t debug_level;
+ int32_t device_num;
};
namespace {
@@ -684,6 +685,7 @@
if (const char *EnvStr = getenv("LIBOMPTARGET_DEVICE_RTL_DEBUG"))
DeviceEnv.debug_level = std::stoi(EnvStr);
#endif
+ DeviceEnv.device_num = DeviceId;
const char *DeviceEnvName = "omptarget_device_environment";
CUdeviceptr DeviceEnvPtr;
Index: openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
===================================================================
--- openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
+++ openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
@@ -527,12 +527,12 @@
pthread_mutex_t SignalPoolT::mutex = PTHREAD_MUTEX_INITIALIZER;
-// TODO: May need to drop the trailing to fields until deviceRTL is updated
+/// Device environment data
+/// Manually sync with the deviceRTL side for now, move to a dedicated header
+/// file later.
struct omptarget_device_environmentTy {
- int32_t debug_level; // gets value of envvar LIBOMPTARGET_DEVICE_RTL_DEBUG
- // only useful for Debug build of deviceRTLs
- int32_t num_devices; // gets number of active offload devices
- int32_t device_num; // gets a value 0 to num_devices-1
+ int32_t debug_level;
+ int32_t device_num;
};
static RTLDeviceInfoTy DeviceInfo;
@@ -941,7 +941,6 @@
}
omptarget_device_environmentTy host_device_env;
- host_device_env.num_devices = DeviceInfo.NumberOfDevices;
host_device_env.device_num = device_id;
host_device_env.debug_level = 0;
#ifdef OMPTARGET_DEBUG
Index: openmp/libomptarget/deviceRTLs/interface.h
===================================================================
--- openmp/libomptarget/deviceRTLs/interface.h
+++ openmp/libomptarget/deviceRTLs/interface.h
@@ -86,6 +86,7 @@
EXTERN int omp_get_cancellation(void);
EXTERN void omp_set_default_device(int deviceId);
EXTERN int omp_get_default_device(void);
+EXTERN int omp_get_device_num(void);
EXTERN int omp_get_num_devices(void);
EXTERN int omp_get_num_teams(void);
EXTERN int omp_get_team_num(void);
Index: openmp/libomptarget/deviceRTLs/common/src/libcall.cu
===================================================================
--- openmp/libomptarget/deviceRTLs/common/src/libcall.cu
+++ openmp/libomptarget/deviceRTLs/common/src/libcall.cu
@@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
+#include "common/device_environment.h"
#include "common/omptarget.h"
#include "common/target_atomic.h"
#include "target_impl.h"
@@ -299,6 +300,12 @@
return 0;
}
+EXTERN int omp_get_device_num(void) {
+ int32_t num = omptarget_device_environment.device_num;
+ PRINT(LD_IO, "call omp_get_device_num() returns %d\n", num);
+ return num;
+}
+
EXTERN int omp_get_num_devices(void) {
PRINT0(LD_IO, "call omp_get_num_devices() is undef on device, returns 0\n");
return 0;
Index: openmp/libomptarget/deviceRTLs/common/device_environment.h
===================================================================
--- openmp/libomptarget/deviceRTLs/common/device_environment.h
+++ openmp/libomptarget/deviceRTLs/common/device_environment.h
@@ -17,6 +17,7 @@
struct omptarget_device_environmentTy {
int32_t debug_level;
+ int32_t device_num;
};
extern DEVICE omptarget_device_environmentTy omptarget_device_environment;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91713.306116.patch
Type: text/x-patch
Size: 3611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20201118/0c0baa88/attachment.bin>
More information about the Openmp-commits
mailing list