Skip to content

Commit 6233c68

Browse files
authored
[SYCL] Always let the backend choose the binary (#1587)
When there is only one binary available the backend should still choose the binary to avoid misleading cl_error_codes Signed-off-by: hiaselhans <[email protected]>
1 parent 44954af commit 6233c68

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

sycl/source/detail/device_binary_image.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ DynRTDeviceBinaryImage::DynRTDeviceBinaryImage(
2121
Bin = new pi_device_binary_struct();
2222
Bin->Version = PI_DEVICE_BINARY_VERSION;
2323
Bin->Kind = PI_DEVICE_BINARY_OFFLOAD_KIND_SYCL;
24-
Bin->DeviceTargetSpec = PI_DEVICE_BINARY_TARGET_UNKNOWN;
2524
Bin->CompileOptions = "";
2625
Bin->LinkOptions = "";
2726
Bin->ManifestStart = nullptr;
@@ -31,6 +30,13 @@ DynRTDeviceBinaryImage::DynRTDeviceBinaryImage(
3130
Bin->EntriesBegin = nullptr;
3231
Bin->EntriesEnd = nullptr;
3332
Bin->Format = pi::getBinaryImageFormat(Bin->BinaryStart, DataSize);
33+
switch (Bin->Format) {
34+
case PI_DEVICE_BINARY_TYPE_SPIRV:
35+
Bin->DeviceTargetSpec = PI_DEVICE_BINARY_TARGET_SPIRV64;
36+
break;
37+
default:
38+
Bin->DeviceTargetSpec = PI_DEVICE_BINARY_TARGET_UNKNOWN;
39+
}
3440
init(Bin);
3541
}
3642

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,13 @@ ProgramManager::ProgramManager() {
635635
RTDeviceBinaryImage &ProgramManager::getDeviceImage(OSModuleHandle M,
636636
KernelSetId KSId,
637637
const context &Context) {
638-
if (DbgProgMgr > 0)
638+
if (DbgProgMgr > 0) {
639639
std::cerr << ">>> ProgramManager::getDeviceImage(" << M << ", \"" << KSId
640640
<< "\", " << getRawSyclObjImpl(Context) << ")\n";
641+
642+
std::cerr << "available device images:\n";
643+
debugPrintBinaryImages();
644+
}
641645
std::lock_guard<std::mutex> Guard(Sync::getGlobalLock());
642646
std::vector<RTDeviceBinaryImageUPtr> &Imgs = *m_DeviceImages[KSId];
643647
const ContextImplPtr Ctx = getSyclObjImpl(Context);
@@ -650,19 +654,15 @@ RTDeviceBinaryImage &ProgramManager::getDeviceImage(OSModuleHandle M,
650654

651655
// Ask the native runtime under the given context to choose the device image
652656
// it prefers.
653-
if (Imgs.size() > 1) {
654-
std::vector<pi_device_binary> RawImgs(Imgs.size());
655-
for (unsigned I = 0; I < Imgs.size(); I++)
656-
RawImgs[I] = const_cast<pi_device_binary>(&Imgs[I]->getRawData());
657+
std::vector<pi_device_binary> RawImgs(Imgs.size());
658+
for (unsigned I = 0; I < Imgs.size(); I++)
659+
RawImgs[I] = const_cast<pi_device_binary>(&Imgs[I]->getRawData());
657660

658-
Ctx->getPlugin().call<PiApiKind::piextDeviceSelectBinary>(
659-
getFirstDevice(Ctx), RawImgs.data(), (cl_uint)RawImgs.size(), &ImgInd);
660-
}
661+
Ctx->getPlugin().call<PiApiKind::piextDeviceSelectBinary>(
662+
getFirstDevice(Ctx), RawImgs.data(), (cl_uint)RawImgs.size(), &ImgInd);
661663
Img = Imgs[ImgInd].get();
662664

663665
if (DbgProgMgr > 0) {
664-
std::cerr << "available device images:\n";
665-
debugPrintBinaryImages();
666666
std::cerr << "selected device image: " << &Img->getRawData() << "\n";
667667
Img->print();
668668
}

0 commit comments

Comments
 (0)