diff --git a/openmp/libomptarget/include/Shared/PluginAPI.h b/openmp/libomptarget/include/Shared/PluginAPI.h index eb1682fa631fd7..df376af1bd50b4 100644 --- a/openmp/libomptarget/include/Shared/PluginAPI.h +++ b/openmp/libomptarget/include/Shared/PluginAPI.h @@ -249,9 +249,8 @@ int32_t __tgt_rtl_initialize_record_replay(int32_t DeviceId, int64_t MemorySize, bool __tgt_rtl_requested_prepopulate_gpu_page_table(); -#if 1 -bool __tgt_rtl_exists_valid_binary_for_RTL(void*, void *); -#endif +bool __tgt_rtl_exists_valid_binary_for_RTL(void *, void *); + bool __tgt_rtl_is_system_supporting_managed_memory(); int32_t __tgt_rtl_launch_kernel_sync(int32_t, void *, void **, ptrdiff_t *, diff --git a/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp b/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp index 2a181f114f19ec..413b57a5488ee9 100644 --- a/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp +++ b/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp @@ -1807,18 +1807,24 @@ int32_t __tgt_rtl_is_valid_binary_info(__tgt_device_image *TgtImage, } bool __tgt_rtl_exists_valid_binary_for_RTL(void *VImages, void *VValidImages) { - std::list *> *Images = - (std::list *> *) VImages; - std::list *> *ValidImages = - (std::list *> *) VValidImages; + llvm::SmallVector> *Images = + (llvm::SmallVector> *)VImages; + llvm::SmallVector> *ValidImages = + (llvm::SmallVector> *)VValidImages; bool IsValidImageAvailable = false; - std::list *> InvalidImages; + llvm::SmallVector< + std::tuple<__tgt_device_image *, __tgt_image_info *, DeviceImageTy *>> + InvalidImages; auto It = std::begin(*Images); while (It != std::end(*Images)) { - __tgt_device_image *Img = &((*It)->first); - __tgt_image_info *Info = &((*It)->second); + __tgt_device_image *Img = (std::get<0>(*It)); + __tgt_image_info *Info = (std::get<1>(*It)); if (__tgt_rtl_is_valid_binary_info(Img, Info)) { ValidImages->push_back(*It); @@ -1834,8 +1840,8 @@ bool __tgt_rtl_exists_valid_binary_for_RTL(void *VImages, void *VValidImages) { if (!IsValidImageAvailable) for (auto targetImage : InvalidImages) { // Check if the image was rejected because of conflicting XNACK modes. - Plugin::get().checkInvalidImage(&targetImage->second, - &targetImage->first); + Plugin::get().checkInvalidImage(std::get<1>(targetImage), + std::get<0>(targetImage)); } return IsValidImageAvailable; diff --git a/openmp/libomptarget/src/PluginManager.cpp b/openmp/libomptarget/src/PluginManager.cpp index 781ee9a9ad9bed..042729ae504d1a 100644 --- a/openmp/libomptarget/src/PluginManager.cpp +++ b/openmp/libomptarget/src/PluginManager.cpp @@ -156,32 +156,36 @@ static void registerImageIntoTranslationTable(TranslationTable &TT, void PluginManager::registerLib(__tgt_bin_desc *Desc) { PM->RTLsMtx.lock(); + llvm::SmallVector< + std::tuple<__tgt_device_image *, __tgt_image_info *, DeviceImageTy *>> + RemainingImages; + // Extract the exectuable image and extra information if availible. - for (int32_t i = 0; i < Desc->NumDeviceImages; ++i) + for (int32_t i = 0; i < Desc->NumDeviceImages; ++i) { PM->addDeviceImage(*Desc, Desc->DeviceImages[i]); + } - // Register the images with the RTLs that understand them, if any. - for (DeviceImageTy &DI : PM->deviceImages()) { - // Obtain the image and information that was previously extracted. - __tgt_device_image *Img = &DI.getExecutableImage(); - __tgt_image_info *Info = &DI.getImageInfo(); + for (auto &DI : PM->deviceImages()) { + RemainingImages.emplace_back(&DI.getExecutableImage(), &DI.getImageInfo(), + &DI); + } - PluginAdaptorTy *FoundRTL = nullptr; + // Scan the RTLs that have associated images until we find one that supports + // the current image. + for (auto &R : PM->pluginAdaptors()) { - // Scan the RTLs that have associated images until we find one that supports - // the current image. - for (auto &R : PM->pluginAdaptors()) { - if (R.is_valid_binary_info) { - if (!R.is_valid_binary_info(Img, Info)) { - DP("Image " DPxMOD " is NOT compatible with RTL %s!\n", - DPxPTR(Img->ImageStart), R.Name.c_str()); - continue; - } - } else if (!R.is_valid_binary(Img)) { - DP("Image " DPxMOD " is NOT compatible with RTL %s!\n", - DPxPTR(Img->ImageStart), R.Name.c_str()); - continue; - } + llvm::SmallVector< + std::tuple<__tgt_device_image *, __tgt_image_info *, DeviceImageTy *>> + ValidImages; + + R.exists_valid_binary_for_RTL(&RemainingImages, &ValidImages); + + for (auto &VI : ValidImages) { + + // Register the images with the RTLs that understand them, if any. + // Obtain the image and information that was previously extracted. + __tgt_device_image *Img = std::get<0>(VI); + __tgt_image_info *Info = std::get<1>(VI); DP("Image " DPxMOD " is compatible with RTL %s!\n", DPxPTR(Img->ImageStart), R.Name.c_str()); @@ -208,19 +212,24 @@ void PluginManager::registerLib(__tgt_bin_desc *Desc) { R.UsedImages.insert(Img); PM->TrlTblMtx.unlock(); - FoundRTL = &R; // Register all offload entries with the devices handled by the plugin. - R.addOffloadEntries(DI); - - // if an RTL was found we are done - proceed to register the next image - break; + R.addOffloadEntries(*std::get<2>(VI)); } - if (!FoundRTL) { - DP("No RTL found for image " DPxMOD "!\n", DPxPTR(Img->ImageStart)); - } +#ifdef OMPTARGET_DEBUG + for (auto Img : RemainingImages) + DP("Image " DPxMOD " is NOT compatible with RTL %s!\n", + DPxPTR(std::get<0>(Img)->ImageStart), R.Name.c_str()); +#endif } + +#ifdef OMPTARGET_DEBUG + for (auto RI : RemainingImages) + DP("No RTL found for image " DPxMOD "!\n", + DPxPTR((std::get<0>(RI))->ImageStart)); +#endif + PM->RTLsMtx.unlock(); DP("Done registering entries!\n");