Skip to content

Commit

Permalink
[OpenMP][libomptarget] Restored code from patch "suprress unnecessary…
Browse files Browse the repository at this point in the history
… warnings"

Some code of the patch https://gerrit-git.amd.com/c/lightning/ec/llvm-project/+/956630  got lost during a merge. This causes some xnack related tests to fail. This patch restores the missing code.

Change-Id: Ib727d47369506f05e1c963c54467adb64447815e
  • Loading branch information
ThorBl authored and ronlieb committed Dec 5, 2023
1 parent c080109 commit 53859b6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 41 deletions.
5 changes: 2 additions & 3 deletions openmp/libomptarget/include/Shared/PluginAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *,
Expand Down
24 changes: 15 additions & 9 deletions openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::pair<__tgt_device_image, __tgt_image_info> *> *Images =
(std::list<std::pair<__tgt_device_image, __tgt_image_info> *> *) VImages;
std::list<std::pair<__tgt_device_image, __tgt_image_info> *> *ValidImages =
(std::list<std::pair<__tgt_device_image, __tgt_image_info> *> *) VValidImages;
llvm::SmallVector<std::tuple<__tgt_device_image *, __tgt_image_info *,
DeviceImageTy *>> *Images =
(llvm::SmallVector<std::tuple<__tgt_device_image *, __tgt_image_info *,
DeviceImageTy *>> *)VImages;
llvm::SmallVector<std::tuple<__tgt_device_image *, __tgt_image_info *,
DeviceImageTy *>> *ValidImages =
(llvm::SmallVector<std::tuple<__tgt_device_image *, __tgt_image_info *,
DeviceImageTy *>> *)VValidImages;

bool IsValidImageAvailable = false;
std::list<std::pair<__tgt_device_image, __tgt_image_info> *> 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);
Expand All @@ -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;
Expand Down
67 changes: 38 additions & 29 deletions openmp/libomptarget/src/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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");
Expand Down

0 comments on commit 53859b6

Please sign in to comment.