Skip to content

[Offload] Provide proper memory management for Images on host device #146066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions offload/plugins-nextgen/common/include/PluginInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,8 @@ struct GenericPluginTy {
return reinterpret_cast<Ty *>(Allocator.Allocate(sizeof(Ty), alignof(Ty)));
}

template <typename Ty> void free(Ty *Mem) { Allocator.Deallocate(Mem); }

/// Get the reference to the global handler of this plugin.
GenericGlobalHandlerTy &getGlobalHandler() {
assert(GlobalHandler && "Global handler not initialized");
Expand Down
10 changes: 7 additions & 3 deletions offload/plugins-nextgen/host/src/rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,12 @@ struct GenELF64DeviceTy : public GenericDeviceTy {
///
/// TODO: This currently does nothing, and should be implemented as part of
/// broader memory handling logic for this plugin
Error unloadBinaryImpl(DeviceImageTy *) override { return Plugin::success(); }
Error unloadBinaryImpl(DeviceImageTy *Image) override {
auto Elf = reinterpret_cast<GenELF64DeviceImageTy *>(Image);
DynamicLibrary::closeLibrary(Elf->getDynamicLibrary());
Plugin.free(Elf);
return Plugin::success();
}

/// Deinitialize the device, which is a no-op
Error deinitImpl() override { return Plugin::success(); }
Expand Down Expand Up @@ -212,8 +217,7 @@ struct GenELF64DeviceTy : public GenericDeviceTy {

// Load the temporary file as a dynamic library.
std::string ErrMsg;
DynamicLibrary DynLib =
DynamicLibrary::getPermanentLibrary(TmpFileName, &ErrMsg);
DynamicLibrary DynLib = DynamicLibrary::getLibrary(TmpFileName, &ErrMsg);

// Check if the loaded library is valid.
if (!DynLib.isValid())
Expand Down
Loading