Skip to content

Commit d60eeda

Browse files
authored
[Offload] Do not load images from the same descriptor on the same device (llvm#139147)
Summary: Right now we generally assume that we have one image per device. The binary descriptor represents a single 'compilation'. This means that each image is going to contain the same code built for different architectures when used through the OpenMP interface. This is problematic when we have cases where the same code will then be loaded multiple times (like wiht sm_80, sm_89 or the generic GFX ISAs). This patch is the quick and dirty slution, we just prevent this from happening at all. This means we use the first one we find, which might not be overly optimal, but it should be better than the alternative. Note that this does not affect shared library loads as it is per binary descriptor, not per device.
1 parent 806b491 commit d60eeda

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

offload/libomptarget/PluginManager.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,10 @@ void PluginManager::registerLib(__tgt_bin_desc *Desc) {
202202
PM->addDeviceImage(*Desc, Desc->DeviceImages[i]);
203203

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

209210
GenericPluginTy *FoundRTL = nullptr;
210211

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

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

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

277+
UsedDevices[&R].insert(DeviceId);
265278
PM->UsedImages.insert(Img);
266279
FoundRTL = &R;
267280

0 commit comments

Comments
 (0)