[Openmp-commits] [openmp] 738734f - [libomptarget][amdgpu] Report zero devices if plugin construction fails, instead of segv
Jon Chesterfield via Openmp-commits
openmp-commits at lists.llvm.org
Mon Sep 27 14:13:21 PDT 2021
Author: Jon Chesterfield
Date: 2021-09-27T22:13:12+01:00
New Revision: 738734f655d3a13dbc2a2dd851a7e907ddcf3fb8
URL: https://github.com/llvm/llvm-project/commit/738734f655d3a13dbc2a2dd851a7e907ddcf3fb8
DIFF: https://github.com/llvm/llvm-project/commit/738734f655d3a13dbc2a2dd851a7e907ddcf3fb8.diff
LOG: [libomptarget][amdgpu] Report zero devices if plugin construction fails, instead of segv
Added:
Modified:
openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
Removed:
################################################################################
diff --git a/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp b/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
index f96087cb93db..c0edc9c6478f 100644
--- a/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
+++ b/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
@@ -449,6 +449,8 @@ class RTLDeviceInfoTy {
};
public:
+ bool ConstructionSucceeded = false;
+
// load binary populates symbol tables and mutates various global state
// run uses those symbol tables
std::shared_timed_mutex load_run_lock;
@@ -817,6 +819,8 @@ class RTLDeviceInfoTy {
// Default state.
RequiresFlags = OMP_REQ_UNDEFINED;
+
+ ConstructionSucceeded = true;
}
~RTLDeviceInfoTy() {
@@ -974,7 +978,15 @@ int32_t __tgt_rtl_is_valid_binary(__tgt_device_image *image) {
return elf_machine_id_is_amdgcn(image);
}
-int __tgt_rtl_number_of_devices() { return DeviceInfo.NumberOfDevices; }
+int __tgt_rtl_number_of_devices() {
+ // If the construction failed, no methods are safe to call
+ if (DeviceInfo.ConstructionSucceeded) {
+ return DeviceInfo.NumberOfDevices;
+ } else {
+ DP("AMDGPU plugin construction failed. Zero devices available\n");
+ return 0;
+ }
+}
int64_t __tgt_rtl_init_requires(int64_t RequiresFlags) {
DP("Init requires flags to %ld\n", RequiresFlags);
More information about the Openmp-commits
mailing list