Index: openmp/libomptarget/src/rtl.cpp =================================================================== --- openmp/libomptarget/src/rtl.cpp +++ openmp/libomptarget/src/rtl.cpp @@ -231,31 +231,12 @@ } void RTLsTy::RegisterLib(__tgt_bin_desc *desc) { - // Attempt to load all plugins available in the system. - std::call_once(initFlag, &RTLsTy::LoadRTLs, this); - - if (desc->HostEntriesBegin == desc->HostEntriesEnd) - return; - RTLsMtx.lock(); - // Register the images with the RTLs that understand them, if any. - for (int32_t i = 0; i < desc->NumDeviceImages; ++i) { - // Obtain the image. - __tgt_device_image *img = &desc->DeviceImages[i]; - - RTLInfoTy *FoundRTL = NULL; - - // Scan the RTLs that have associated images until we find one that supports - // the current image. + // Load all plugins available in the system and initialize them + std::call_once(initFlag, [this]() { + // 1. Load plugins + this->LoadRTLs(); + // 2. Initialize them if any one has not been initialized yet for (auto &R : RTLs.AllRTLs) { - if (!R.is_valid_binary(img)) { - DP("Image " DPxMOD " is NOT compatible with RTL %s!\n", - DPxPTR(img->ImageStart), R.RTLName.c_str()); - continue; - } - - DP("Image " DPxMOD " is compatible with RTL %s!\n", - DPxPTR(img->ImageStart), R.RTLName.c_str()); - // If this RTL is not already in use, initialize it. if (!R.isUsed) { // Initialize the device information for the RTL we are about to use. @@ -263,7 +244,7 @@ size_t start = Devices.size(); Devices.resize(start + R.NumberOfDevices, device); for (int32_t device_id = 0; device_id < R.NumberOfDevices; - device_id++) { + device_id++) { // global device ID Devices[start + device_id].DeviceID = start + device_id; // RTL local device ID @@ -275,17 +256,43 @@ ? 0 : RTLs.UsedRTLs.back()->Idx + RTLs.UsedRTLs.back()->NumberOfDevices; - assert((size_t) R.Idx == start && - "RTL index should equal the number of devices used so far."); + assert((size_t)R.Idx == start && + "RTL index should equal the number of devices used so far."); R.isUsed = true; RTLs.UsedRTLs.push_back(&R); DP("RTL " DPxMOD " has index %d!\n", DPxPTR(R.LibraryHandler), R.Idx); } + } + }); + + if (desc->HostEntriesBegin == desc->HostEntriesEnd) + return; + RTLsMtx.lock(); + // Register the images with the RTLs that understand them, if any. + for (int32_t i = 0; i < desc->NumDeviceImages; ++i) { + // Obtain the image. + __tgt_device_image *img = &desc->DeviceImages[i]; + + RTLInfoTy *FoundRTL = NULL; + + // Scan the RTLs that have associated images until we find one that supports + // the current image. + for (auto &R : RTLs.AllRTLs) { + if (!R.is_valid_binary(img)) { + DP("Image " DPxMOD " is NOT compatible with RTL %s!\n", + DPxPTR(img->ImageStart), R.RTLName.c_str()); + continue; + } + + DP("Image " DPxMOD " is compatible with RTL %s!\n", + DPxPTR(img->ImageStart), R.RTLName.c_str()); + + assert(R.isUsed && "RTL should have already been initialized!"); // Initialize (if necessary) translation table for this library. TrlTblMtx.lock(); - if(!HostEntriesBeginToTransTable.count(desc->HostEntriesBegin)){ + if (!HostEntriesBeginToTransTable.count(desc->HostEntriesBegin)) { TranslationTable &tt = HostEntriesBeginToTransTable[desc->HostEntriesBegin]; tt.HostTable.EntriesBegin = desc->HostEntriesBegin;