Skip to content

Commit a58c1af

Browse files
committed
[Offload] Do not load images from the same descriptor on the same device
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 dfcb8cb commit a58c1af

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

offload/libomptarget/PluginManager.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ 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+
llvm::DenseMap<GenericPluginTy *, llvm::DenseSet<int32_t>> UsedDevices;
205206
for (DeviceImageTy &DI : PM->deviceImages()) {
206207
// Obtain the image and information that was previously extracted.
207208
__tgt_device_image *Img = &DI.getExecutableImage();
@@ -232,6 +233,17 @@ void PluginManager::registerLib(__tgt_bin_desc *Desc) {
232233
if (!initializeDevice(R, DeviceId))
233234
continue;
234235

236+
// We only want a single matching image to be registered for each binary
237+
// descriptor. This prevents multiple of the same image from being
238+
// registered for the same device in the case that they are mutually
239+
// compatible, such as sm_80 and sm_89.
240+
if (!UsedDevices[&R].insert(DeviceId).second) {
241+
DP("Image " DPxMOD
242+
" is a duplicate, not loaded on RTL %s device %d!\n",
243+
DPxPTR(Img->ImageStart), R.getName(), DeviceId);
244+
continue;
245+
}
246+
235247
// Initialize (if necessary) translation table for this library.
236248
PM->TrlTblMtx.lock();
237249
if (!PM->HostEntriesBeginToTransTable.count(Desc->HostEntriesBegin)) {

0 commit comments

Comments
 (0)