Skip to content

Commit 7bfcce3

Browse files
authored
[OpenMP] Tear down GenericDeviceTy's with GenericPluginTy (#73557)
There is no point in keeping GenericDeviceTy objects alive longer than the associated GenericPluginTy. Instead of the old API we now tear them down with the plugin, avoiding ordering issues.
1 parent e3f16de commit 7bfcce3

File tree

6 files changed

+5
-24
lines changed

6 files changed

+5
-24
lines changed

openmp/libomptarget/include/omptargetplugin.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ int64_t __tgt_rtl_init_requires(int64_t RequiresFlags);
5757
// return an error code.
5858
int32_t __tgt_rtl_init_device(int32_t ID);
5959

60-
// Deinitialize the specified device. In case of success return 0; otherwise
61-
// return an error code.
62-
int32_t __tgt_rtl_deinit_device(int32_t ID);
63-
6460
// Pass an executable image section described by image to the specified
6561
// device and prepare an address table of target entities. In case of error,
6662
// return NULL. Otherwise, return a pointer to the built address table.

openmp/libomptarget/include/rtl.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ struct RTLInfoTy {
3737
typedef int32_t(is_data_exchangable_ty)(int32_t, int32_t);
3838
typedef int32_t(number_of_devices_ty)();
3939
typedef int32_t(init_device_ty)(int32_t);
40-
typedef int32_t(deinit_device_ty)(int32_t);
4140
typedef __tgt_target_table *(load_binary_ty)(int32_t, void *);
4241
typedef void *(data_alloc_ty)(int32_t, int64_t, void *, int32_t);
4342
typedef int32_t(data_submit_ty)(int32_t, void *, void *, int64_t);
@@ -94,7 +93,6 @@ struct RTLInfoTy {
9493
is_data_exchangable_ty *is_data_exchangable = nullptr;
9594
number_of_devices_ty *number_of_devices = nullptr;
9695
init_device_ty *init_device = nullptr;
97-
deinit_device_ty *deinit_device = nullptr;
9896
load_binary_ty *load_binary = nullptr;
9997
data_alloc_ty *data_alloc = nullptr;
10098
data_submit_ty *data_submit = nullptr;

openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,17 +1688,6 @@ int32_t __tgt_rtl_init_device(int32_t DeviceId) {
16881688
return OFFLOAD_SUCCESS;
16891689
}
16901690

1691-
int32_t __tgt_rtl_deinit_device(int32_t DeviceId) {
1692-
auto Err = Plugin::get().deinitDevice(DeviceId);
1693-
if (Err) {
1694-
REPORT("Failure to deinitialize device %d: %s\n", DeviceId,
1695-
toString(std::move(Err)).data());
1696-
return OFFLOAD_FAIL;
1697-
}
1698-
1699-
return OFFLOAD_SUCCESS;
1700-
}
1701-
17021691
int32_t __tgt_rtl_number_of_devices() { return Plugin::get().getNumDevices(); }
17031692

17041693
int64_t __tgt_rtl_init_requires(int64_t RequiresFlags) {

openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,11 @@ class Plugin {
11441144
static Error deinit() {
11451145
assert(SpecificPlugin && "Plugin no longer valid");
11461146

1147+
for (int32_t DevNo = 0, NumDev = SpecificPlugin->getNumDevices();
1148+
DevNo < NumDev; ++DevNo)
1149+
if (auto Err = SpecificPlugin->deinitDevice(DevNo))
1150+
return Err;
1151+
11471152
// Deinitialize the plugin.
11481153
if (auto Err = SpecificPlugin->deinit())
11491154
return Err;

openmp/libomptarget/src/device.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -563,11 +563,6 @@ int32_t DeviceTy::initOnce() {
563563
return OFFLOAD_FAIL;
564564
}
565565

566-
void DeviceTy::deinit() {
567-
if (RTL->deinit_device)
568-
RTL->deinit_device(RTLDeviceID);
569-
}
570-
571566
// Load binary to device.
572567
__tgt_target_table *DeviceTy::loadBinary(void *Img) {
573568
std::lock_guard<decltype(RTL->Mtx)> LG(RTL->Mtx);

openmp/libomptarget/src/rtl.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ bool RTLsTy::attemptLoadRTL(const std::string &RTLName, RTLInfoTy &RTL) {
195195
// Optional functions
196196
*((void **)&RTL.is_valid_binary_info) =
197197
DynLibrary->getAddressOfSymbol("__tgt_rtl_is_valid_binary_info");
198-
*((void **)&RTL.deinit_device) =
199-
DynLibrary->getAddressOfSymbol("__tgt_rtl_deinit_device");
200198
*((void **)&RTL.init_requires) =
201199
DynLibrary->getAddressOfSymbol("__tgt_rtl_init_requires");
202200
*((void **)&RTL.data_submit_async) =

0 commit comments

Comments
 (0)