Skip to content

Commit 53859b6

Browse files
ThorBlronlieb
authored andcommitted
[OpenMP][libomptarget] Restored code from patch "suprress unnecessary 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
1 parent c080109 commit 53859b6

File tree

3 files changed

+55
-41
lines changed

3 files changed

+55
-41
lines changed

openmp/libomptarget/include/Shared/PluginAPI.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,8 @@ int32_t __tgt_rtl_initialize_record_replay(int32_t DeviceId, int64_t MemorySize,
249249

250250
bool __tgt_rtl_requested_prepopulate_gpu_page_table();
251251

252-
#if 1
253-
bool __tgt_rtl_exists_valid_binary_for_RTL(void*, void *);
254-
#endif
252+
bool __tgt_rtl_exists_valid_binary_for_RTL(void *, void *);
253+
255254
bool __tgt_rtl_is_system_supporting_managed_memory();
256255

257256
int32_t __tgt_rtl_launch_kernel_sync(int32_t, void *, void **, ptrdiff_t *,

openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,18 +1807,24 @@ int32_t __tgt_rtl_is_valid_binary_info(__tgt_device_image *TgtImage,
18071807
}
18081808

18091809
bool __tgt_rtl_exists_valid_binary_for_RTL(void *VImages, void *VValidImages) {
1810-
std::list<std::pair<__tgt_device_image, __tgt_image_info> *> *Images =
1811-
(std::list<std::pair<__tgt_device_image, __tgt_image_info> *> *) VImages;
1812-
std::list<std::pair<__tgt_device_image, __tgt_image_info> *> *ValidImages =
1813-
(std::list<std::pair<__tgt_device_image, __tgt_image_info> *> *) VValidImages;
1810+
llvm::SmallVector<std::tuple<__tgt_device_image *, __tgt_image_info *,
1811+
DeviceImageTy *>> *Images =
1812+
(llvm::SmallVector<std::tuple<__tgt_device_image *, __tgt_image_info *,
1813+
DeviceImageTy *>> *)VImages;
1814+
llvm::SmallVector<std::tuple<__tgt_device_image *, __tgt_image_info *,
1815+
DeviceImageTy *>> *ValidImages =
1816+
(llvm::SmallVector<std::tuple<__tgt_device_image *, __tgt_image_info *,
1817+
DeviceImageTy *>> *)VValidImages;
18141818

18151819
bool IsValidImageAvailable = false;
1816-
std::list<std::pair<__tgt_device_image, __tgt_image_info> *> InvalidImages;
1820+
llvm::SmallVector<
1821+
std::tuple<__tgt_device_image *, __tgt_image_info *, DeviceImageTy *>>
1822+
InvalidImages;
18171823

18181824
auto It = std::begin(*Images);
18191825
while (It != std::end(*Images)) {
1820-
__tgt_device_image *Img = &((*It)->first);
1821-
__tgt_image_info *Info = &((*It)->second);
1826+
__tgt_device_image *Img = (std::get<0>(*It));
1827+
__tgt_image_info *Info = (std::get<1>(*It));
18221828

18231829
if (__tgt_rtl_is_valid_binary_info(Img, Info)) {
18241830
ValidImages->push_back(*It);
@@ -1834,8 +1840,8 @@ bool __tgt_rtl_exists_valid_binary_for_RTL(void *VImages, void *VValidImages) {
18341840
if (!IsValidImageAvailable)
18351841
for (auto targetImage : InvalidImages) {
18361842
// Check if the image was rejected because of conflicting XNACK modes.
1837-
Plugin::get().checkInvalidImage(&targetImage->second,
1838-
&targetImage->first);
1843+
Plugin::get().checkInvalidImage(std::get<1>(targetImage),
1844+
std::get<0>(targetImage));
18391845
}
18401846

18411847
return IsValidImageAvailable;

openmp/libomptarget/src/PluginManager.cpp

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -156,32 +156,36 @@ static void registerImageIntoTranslationTable(TranslationTable &TT,
156156
void PluginManager::registerLib(__tgt_bin_desc *Desc) {
157157
PM->RTLsMtx.lock();
158158

159+
llvm::SmallVector<
160+
std::tuple<__tgt_device_image *, __tgt_image_info *, DeviceImageTy *>>
161+
RemainingImages;
162+
159163
// Extract the exectuable image and extra information if availible.
160-
for (int32_t i = 0; i < Desc->NumDeviceImages; ++i)
164+
for (int32_t i = 0; i < Desc->NumDeviceImages; ++i) {
161165
PM->addDeviceImage(*Desc, Desc->DeviceImages[i]);
166+
}
162167

163-
// Register the images with the RTLs that understand them, if any.
164-
for (DeviceImageTy &DI : PM->deviceImages()) {
165-
// Obtain the image and information that was previously extracted.
166-
__tgt_device_image *Img = &DI.getExecutableImage();
167-
__tgt_image_info *Info = &DI.getImageInfo();
168+
for (auto &DI : PM->deviceImages()) {
169+
RemainingImages.emplace_back(&DI.getExecutableImage(), &DI.getImageInfo(),
170+
&DI);
171+
}
168172

169-
PluginAdaptorTy *FoundRTL = nullptr;
173+
// Scan the RTLs that have associated images until we find one that supports
174+
// the current image.
175+
for (auto &R : PM->pluginAdaptors()) {
170176

171-
// Scan the RTLs that have associated images until we find one that supports
172-
// the current image.
173-
for (auto &R : PM->pluginAdaptors()) {
174-
if (R.is_valid_binary_info) {
175-
if (!R.is_valid_binary_info(Img, Info)) {
176-
DP("Image " DPxMOD " is NOT compatible with RTL %s!\n",
177-
DPxPTR(Img->ImageStart), R.Name.c_str());
178-
continue;
179-
}
180-
} else if (!R.is_valid_binary(Img)) {
181-
DP("Image " DPxMOD " is NOT compatible with RTL %s!\n",
182-
DPxPTR(Img->ImageStart), R.Name.c_str());
183-
continue;
184-
}
177+
llvm::SmallVector<
178+
std::tuple<__tgt_device_image *, __tgt_image_info *, DeviceImageTy *>>
179+
ValidImages;
180+
181+
R.exists_valid_binary_for_RTL(&RemainingImages, &ValidImages);
182+
183+
for (auto &VI : ValidImages) {
184+
185+
// Register the images with the RTLs that understand them, if any.
186+
// Obtain the image and information that was previously extracted.
187+
__tgt_device_image *Img = std::get<0>(VI);
188+
__tgt_image_info *Info = std::get<1>(VI);
185189

186190
DP("Image " DPxMOD " is compatible with RTL %s!\n",
187191
DPxPTR(Img->ImageStart), R.Name.c_str());
@@ -208,19 +212,24 @@ void PluginManager::registerLib(__tgt_bin_desc *Desc) {
208212
R.UsedImages.insert(Img);
209213

210214
PM->TrlTblMtx.unlock();
211-
FoundRTL = &R;
212215

213216
// Register all offload entries with the devices handled by the plugin.
214-
R.addOffloadEntries(DI);
215-
216-
// if an RTL was found we are done - proceed to register the next image
217-
break;
217+
R.addOffloadEntries(*std::get<2>(VI));
218218
}
219219

220-
if (!FoundRTL) {
221-
DP("No RTL found for image " DPxMOD "!\n", DPxPTR(Img->ImageStart));
222-
}
220+
#ifdef OMPTARGET_DEBUG
221+
for (auto Img : RemainingImages)
222+
DP("Image " DPxMOD " is NOT compatible with RTL %s!\n",
223+
DPxPTR(std::get<0>(Img)->ImageStart), R.Name.c_str());
224+
#endif
223225
}
226+
227+
#ifdef OMPTARGET_DEBUG
228+
for (auto RI : RemainingImages)
229+
DP("No RTL found for image " DPxMOD "!\n",
230+
DPxPTR((std::get<0>(RI))->ImageStart));
231+
#endif
232+
224233
PM->RTLsMtx.unlock();
225234

226235
DP("Done registering entries!\n");

0 commit comments

Comments
 (0)