Skip to content

Commit 637cb85

Browse files
authored
[SYCL] Fix dumping of images for multiple targets (#8640)
This was identified by the Unified Runtime team, depending on the target order in `-fsycl-targets` certain binaries are not dumped. ``` -fsycl-targets=nvptx64-nvidia-cuda,spir64 ├── sycl_nvptx641.bin ├── sycl_spir642.spv └── sycl_spir643.spv ``` ``` -fsycl-targets=spir64,nvptx64-nvidia-cuda ├── sycl_spir641.spv ├── sycl_spir642.spv └── sycl_spir643.spv ``` This patch makes sure that if a kernel is compiled for multiple targets, images belonging to different targets will be dumped.
1 parent 13e5a32 commit 637cb85

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,7 @@ void ProgramManager::addImages(pi_device_binaries DeviceBinary) {
11841184
const _pi_offload_entry EntriesB = RawImg->EntriesBegin;
11851185
const _pi_offload_entry EntriesE = RawImg->EntriesEnd;
11861186
auto Img = make_unique_ptr<RTDeviceBinaryImage>(RawImg, M);
1187+
static uint32_t SequenceID = 0;
11871188

11881189
// Fill the kernel argument mask map
11891190
const RTDeviceBinaryImage::PropertyRange &KPOIRange =
@@ -1257,6 +1258,13 @@ void ProgramManager::addImages(pi_device_binaries DeviceBinary) {
12571258
if (KSIdIt != KSIdMap.end()) {
12581259
auto &Imgs = m_DeviceImages[KSIdIt->second];
12591260
assert(Imgs && "Device image vector should have been already created");
1261+
if (DumpImages) {
1262+
const bool NeedsSequenceID =
1263+
std::any_of(Imgs->begin(), Imgs->end(), [&](auto &I) {
1264+
return I->getFormat() == Img->getFormat();
1265+
});
1266+
dumpImage(*Img, KSIdIt->second, NeedsSequenceID ? ++SequenceID : 0);
1267+
}
12601268

12611269
cacheKernelUsesAssertInfo(M, *Img);
12621270

@@ -1379,12 +1387,14 @@ ProgramManager::getKernelSetId(OSModuleHandle M,
13791387
PI_ERROR_INVALID_KERNEL_NAME);
13801388
}
13811389

1382-
void ProgramManager::dumpImage(const RTDeviceBinaryImage &Img,
1383-
KernelSetId KSId) const {
1390+
void ProgramManager::dumpImage(const RTDeviceBinaryImage &Img, KernelSetId KSId,
1391+
uint32_t SequenceID) const {
13841392
std::string Fname("sycl_");
13851393
const pi_device_binary_struct &RawImg = Img.getRawData();
13861394
Fname += RawImg.DeviceTargetSpec;
13871395
Fname += std::to_string(KSId);
1396+
if (SequenceID)
1397+
Fname += '_' + std::to_string(SequenceID);
13881398
std::string Ext;
13891399

13901400
RT::PiDeviceBinaryType Format = Img.getFormat();

sycl/source/detail/program_manager/program_manager.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ class ProgramManager {
299299
KernelSetId getKernelSetId(OSModuleHandle M,
300300
const std::string &KernelName) const;
301301
/// Dumps image to current directory
302-
void dumpImage(const RTDeviceBinaryImage &Img, KernelSetId KSId) const;
302+
void dumpImage(const RTDeviceBinaryImage &Img, KernelSetId KSId,
303+
uint32_t SequenceID = 0) const;
303304

304305
/// Add info on kernels using assert into cache
305306
void cacheKernelUsesAssertInfo(OSModuleHandle M, RTDeviceBinaryImage &Img);

0 commit comments

Comments
 (0)