diff options
| author | Ross Brunton <ross@codeplay.com> | 2025-07-10 12:05:31 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-10 12:05:31 +0100 |
| commit | abb878438ae853fc068aa16e862b30c8d9ae04e1 (patch) | |
| tree | 6258173be014ca6e3fc1cbf589d2457b3e029fc7 /offload/plugins-nextgen/common | |
| parent | 343e3c6bb827fb2c969f7399bef448bd58e1e43f (diff) | |
[Offload] Allow querying the size of globals (#147698)
The `GlobalTy` helper has been extended to make both the Size and Ptr be
optional. Now `getGlobalMetadataFromDevice`/`Image` is able to write the
size of the global to the struct, instead of just verifying it.
Diffstat (limited to 'offload/plugins-nextgen/common')
| -rw-r--r-- | offload/plugins-nextgen/common/include/GlobalHandler.h | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/offload/plugins-nextgen/common/include/GlobalHandler.h b/offload/plugins-nextgen/common/include/GlobalHandler.h index 5d6109df49da..af7dac66ca85 100644 --- a/offload/plugins-nextgen/common/include/GlobalHandler.h +++ b/offload/plugins-nextgen/common/include/GlobalHandler.h @@ -37,6 +37,8 @@ using namespace llvm::object; /// Common abstraction for globals that live on the host and device. /// It simply encapsulates the symbol name, symbol size, and symbol address /// (which might be host or device depending on the context). +/// Both size and address may be absent (signified by 0/nullptr), and can be +/// populated with getGlobalMetadataFromDevice/Image. class GlobalTy { // NOTE: Maybe we can have a pointer to the offload entry name instead of // holding a private copy of the name as a std::string. @@ -45,7 +47,7 @@ class GlobalTy { void *Ptr; public: - GlobalTy(const std::string &Name, uint32_t Size, void *Ptr = nullptr) + GlobalTy(const std::string &Name, uint32_t Size = 0, void *Ptr = nullptr) : Name(Name), Size(Size), Ptr(Ptr) {} const std::string &getName() const { return Name; } @@ -139,8 +141,11 @@ public: bool isSymbolInImage(GenericDeviceTy &Device, DeviceImageTy &Image, StringRef SymName); - /// Get the address and size of a global in the image. Address and size are - /// return in \p ImageGlobal, the global name is passed in \p ImageGlobal. + /// Get the address and size of a global in the image. Address is + /// returned in \p ImageGlobal and the global name is passed in \p + /// ImageGlobal. If no size is present in \p ImageGlobal, then the size of the + /// global will be stored there. If it is present, it will be validated + /// against the real size of the global. Error getGlobalMetadataFromImage(GenericDeviceTy &Device, DeviceImageTy &Image, GlobalTy &ImageGlobal); @@ -149,9 +154,11 @@ public: Error readGlobalFromImage(GenericDeviceTy &Device, DeviceImageTy &Image, const GlobalTy &HostGlobal); - /// Get the address and size of a global from the device. Address is return in - /// \p DeviceGlobal, the global name and expected size are passed in - /// \p DeviceGlobal. + /// Get the address and size of a global from the device. Address is + /// returned in \p ImageGlobal and the global name is passed in \p + /// ImageGlobal. If no size is present in \p ImageGlobal, then the size of the + /// global will be stored there. If it is present, it will be validated + /// against the real size of the global. virtual Error getGlobalMetadataFromDevice(GenericDeviceTy &Device, DeviceImageTy &Image, GlobalTy &DeviceGlobal) = 0; |
