Skip to content

[Offload] Do not load images from the same descriptor on the same device #139147

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

Merged
merged 1 commit into from
May 9, 2025
Merged
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
17 changes: 15 additions & 2 deletions offload/libomptarget/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,10 @@ void PluginManager::registerLib(__tgt_bin_desc *Desc) {
PM->addDeviceImage(*Desc, Desc->DeviceImages[i]);

// Register the images with the RTLs that understand them, if any.
for (DeviceImageTy &DI : PM->deviceImages()) {
llvm::DenseMap<GenericPluginTy *, llvm::DenseSet<int32_t>> UsedDevices;
for (int32_t i = 0; i < Desc->NumDeviceImages; ++i) {
// Obtain the image and information that was previously extracted.
__tgt_device_image *Img = &DI.getExecutableImage();
__tgt_device_image *Img = &Desc->DeviceImages[i];

GenericPluginTy *FoundRTL = nullptr;

Expand All @@ -223,6 +224,17 @@ void PluginManager::registerLib(__tgt_bin_desc *Desc) {
}

for (int32_t DeviceId = 0; DeviceId < R.number_of_devices(); ++DeviceId) {
// We only want a single matching image to be registered for each binary
// descriptor. This prevents multiple of the same image from being
// registered for the same device in the case that they are mutually
// compatible, such as sm_80 and sm_89.
if (UsedDevices[&R].contains(DeviceId)) {
DP("Image " DPxMOD
" is a duplicate, not loaded on RTL %s device %d!\n",
DPxPTR(Img->ImageStart), R.getName(), DeviceId);
continue;
}

if (!R.is_device_compatible(DeviceId, Img))
continue;

Expand Down Expand Up @@ -262,6 +274,7 @@ void PluginManager::registerLib(__tgt_bin_desc *Desc) {
TT.TargetsImages[UserId] = Img;
TT.TargetsTable[UserId] = nullptr;

UsedDevices[&R].insert(DeviceId);
PM->UsedImages.insert(Img);
FoundRTL = &R;

Expand Down
Loading