Skip to content

Commit 3b3af0e

Browse files
committed
Revert "Revert plugin changes"
This reverts commit 44122e1.
1 parent 0ca7527 commit 3b3af0e

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

offload/plugins-nextgen/common/include/GlobalHandler.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ class GenericGlobalHandlerTy {
131131

132132
/// Get the address and size of a global in the image. Address and size are
133133
/// return in \p ImageGlobal, the global name is passed in \p ImageGlobal.
134-
Error getGlobalMetadataFromImage(GenericDeviceTy &Device,
135-
DeviceImageTy &Image, GlobalTy &ImageGlobal);
134+
virtual Error getGlobalMetadataFromImage(GenericDeviceTy &Device,
135+
DeviceImageTy &Image,
136+
GlobalTy &ImageGlobal);
136137

137138
/// Read the memory associated with a global from the image and store it on
138139
/// the host. The name, size, and destination are defined by \p HostGlobal.

offload/plugins-nextgen/cuda/src/rtl.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,34 @@ class CUDAGlobalHandlerTy final : public GenericGlobalHandlerTy {
13271327
DeviceGlobal.setPtr(reinterpret_cast<void *>(CUPtr));
13281328
return Plugin::success();
13291329
}
1330+
1331+
Error getGlobalMetadataFromImage(GenericDeviceTy &Device,
1332+
DeviceImageTy &Image,
1333+
GlobalTy &ImageGlobal) override {
1334+
// If the image is an ELF we can use the generic path, otherwise fall back
1335+
// and use cuModuleGetGlobal to query the image.
1336+
if (utils::elf::isELF(Image.getMemoryBuffer().getBuffer())) {
1337+
return GenericGlobalHandlerTy::getGlobalMetadataFromImage(Device, Image,
1338+
ImageGlobal);
1339+
}
1340+
1341+
CUDADeviceImageTy &CUDAImage = static_cast<CUDADeviceImageTy &>(Image);
1342+
1343+
const char *GlobalName = ImageGlobal.getName().data();
1344+
1345+
size_t CUSize;
1346+
CUdeviceptr CUPtr;
1347+
CUresult Res =
1348+
cuModuleGetGlobal(&CUPtr, &CUSize, CUDAImage.getModule(), GlobalName);
1349+
if (auto Err = Plugin::check(Res, "Error in cuModuleGetGlobal for '%s': %s",
1350+
GlobalName))
1351+
return Err;
1352+
1353+
// Setup the global symbol's address and size.
1354+
ImageGlobal.setPtr(reinterpret_cast<void *>(CUPtr));
1355+
ImageGlobal.setSize(CUSize);
1356+
return Plugin::success();
1357+
}
13301358
};
13311359

13321360
/// Class implementing the CUDA-specific functionalities of the plugin.

offload/plugins-nextgen/host/src/rtl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ struct GenELF64DeviceTy : public GenericDeviceTy {
289289

290290
/// This plugin does not support interoperability, do nothing
291291
Error initAsyncInfoImpl(AsyncInfoWrapperTy &AsyncInfoWrapper) override {
292-
return Plugin::error("initAsyncInfoImpl not supported");
292+
return Plugin::success();
293293
}
294294

295295
/// This plugin does not support interoperability

0 commit comments

Comments
 (0)