Skip to content

Commit 2333865

Browse files
authored
[Libomptarget] Fix data mapping on dynamic loads (#80559)
Summary: The current logic tries to map target mapping tables to the current device. Right now it assumes that data is only mapped a single time per device. This is only true if we have a single instance of the runtime running on a single program. However, in the case of dynamic library loads or shared libraries, this may happen multiple times. Given a case of a simple dynamic library load which has its own target kernel instruction, the current logic had only the first call to `__tgt_target_kernel` to the data mapping for that device. Then, when the next dynamic library load got called, it would see that the global were already mapped for that device and skip registering its own entires, even though they were distinct. This resulted in none of the mappings being done and hitting an assertion. This patch simply gets rid of this per-device check. The check should instead be on the host offloading entries. We already have logic that calls `continue` if we already have entries for that pointer, so we can simply rely on that instead.
1 parent 9d00c34 commit 2333865

File tree

3 files changed

+3
-7
lines changed

3 files changed

+3
-7
lines changed

openmp/libomptarget/include/device.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ struct DeviceTy {
4343
PluginAdaptorTy *RTL;
4444
int32_t RTLDeviceID;
4545

46-
bool HasMappedGlobalData = false;
47-
4846
DeviceTy(PluginAdaptorTy *RTL, int32_t DeviceID, int32_t RTLDeviceID);
4947
// DeviceTy is not copyable
5048
DeviceTy(const DeviceTy &D) = delete;

openmp/libomptarget/src/omptarget.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ static uint64_t getPartialStructRequiredAlignment(void *HstPtrBase) {
132132

133133
/// Map global data and execute pending ctors
134134
static int initLibrary(DeviceTy &Device) {
135-
if (Device.HasMappedGlobalData)
136-
return OFFLOAD_SUCCESS;
137-
138135
/*
139136
* Map global data
140137
*/
@@ -294,8 +291,6 @@ static int initLibrary(DeviceTy &Device) {
294291
if (Rc != OFFLOAD_SUCCESS)
295292
return Rc;
296293

297-
Device.HasMappedGlobalData = true;
298-
299294
static Int32Envar DumpOffloadEntries =
300295
Int32Envar("OMPTARGET_DUMP_OFFLOAD_ENTRIES", -1);
301296
if (DumpOffloadEntries.get() == DeviceId)

openmp/libomptarget/test/offloading/dynamic_module_load.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ int foo() {
1212
#include <dlfcn.h>
1313
#include <stdio.h>
1414
int main(int argc, char **argv) {
15+
#pragma omp target
16+
;
17+
1518
void *Handle = dlopen(argv[1], RTLD_NOW);
1619
int (*Foo)(void);
1720

0 commit comments

Comments
 (0)