Skip to content

Commit 352eea3

Browse files
committed
fix bug when writing required devicelib extension to image
Signed-off-by: jinge90 <[email protected]>
1 parent f0ecc0a commit 352eea3

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

llvm/lib/SYCLLowerIR/ComputeModuleRuntimeInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ PropSetRegTy computeModuleProperties(const Module &M,
186186
uint8_t *SPVBuffer = reinterpret_cast<uint8_t *>(
187187
std::aligned_alloc(alignof(uint32_t), SPVSize + sizeof(uint32_t)));
188188
*(reinterpret_cast<uint32_t *>(SPVBuffer)) = static_cast<uint32_t>(Ext);
189-
std::memcpy(SPVBuffer + 1, (*SPVMB)->getBufferStart(), SPVSize);
189+
std::memcpy(SPVBuffer + sizeof(uint32_t), (*SPVMB)->getBufferStart(),
190+
SPVSize);
190191
llvm::SYCLDeviceLibSPVBinary SPVBinaryObj(SPVBuffer,
191192
SPVSize + sizeof(uint32_t));
192193
PropSet.add(PropSetRegTy::SYCL_DEVICELIB_REQ_BINS, SPVFileName,

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,25 @@ getDeviceLibPrograms(const ContextImplPtr Context,
15961596
std::vector<ur_device_handle_t> &Devices,
15971597
const std::vector<const RTDeviceBinaryImage *> &Images) {
15981598
std::vector<ur_program_handle_t> Programs;
1599+
for (auto Img : Images) {
1600+
if (!Img)
1601+
continue;
1602+
const RTDeviceBinaryImage::PropertyRange &NewRange =
1603+
Img->getDeviceLibReqBins();
1604+
if (!NewRange.isAvailable())
1605+
continue;
1606+
1607+
for (const auto &DeviceLibBinProp : NewRange) {
1608+
auto DeviceLibByteArray =
1609+
DeviceBinaryProperty(DeviceLibBinProp).asByteArray();
1610+
DeviceLibByteArray.dropBytes(8);
1611+
uint32_t DeviceLibExtReq =
1612+
(static_cast<uint32_t>(DeviceLibByteArray[3]) << 24) |
1613+
(static_cast<uint32_t>(DeviceLibByteArray[2]) << 16) |
1614+
(static_cast<uint32_t>(DeviceLibByteArray[1]) << 8) |
1615+
DeviceLibByteArray[0];
1616+
}
1617+
}
15991618
return Programs;
16001619
}
16011620

@@ -1604,6 +1623,8 @@ checkDeviceLibsLinkMode(const std::vector<const RTDeviceBinaryImage *> &Images,
16041623
bool &LinkDeviceLib, bool &LegacyLinkMode) {
16051624
bool ReqMaskAvailable = false, ReqBinsAvailable = false;
16061625
for (auto Img : Images) {
1626+
if (!Img)
1627+
continue;
16071628
const RTDeviceBinaryImage::PropertyRange &LegacyRange =
16081629
Img->getDeviceLibReqMask();
16091630
if (LegacyRange.isAvailable()) {
@@ -1634,10 +1655,13 @@ static uint32_t getDeviceLibReqMaskFromImages(
16341655
const std::vector<const RTDeviceBinaryImage *> &Images) {
16351656
uint32_t DeviceLibReqMask = 0;
16361657
for (auto Img : Images) {
1658+
if (!Img)
1659+
continue;
16371660
const RTDeviceBinaryImage::PropertyRange &ReqMaskRange =
16381661
Img->getDeviceLibReqMask();
16391662
if (ReqMaskRange.isAvailable())
1640-
DeviceLibReqMask |= DeviceBinaryProperty(*(ReqMaskRange.begin())).asUint32();
1663+
DeviceLibReqMask |=
1664+
DeviceBinaryProperty(*(ReqMaskRange.begin())).asUint32();
16411665
}
16421666
return DeviceLibReqMask;
16431667
}
@@ -2929,9 +2953,7 @@ ur_kernel_handle_t ProgramManager::getOrCreateMaterializedKernel(
29292953
// An empty images vector will skip linking fallback device libraries.
29302954
auto BuildProgram =
29312955
build(std::move(ProgramManaged), detail::getSyclObjImpl(Context),
2932-
CompileOpts, LinkOpts, Devs,
2933-
ImagesVec,
2934-
ExtraProgramsToLink);
2956+
CompileOpts, LinkOpts, Devs, ImagesVec, ExtraProgramsToLink);
29352957
ur_kernel_handle_t UrKernel{nullptr};
29362958
Adapter->call<errc::kernel_not_supported, UrApiKind::urKernelCreate>(
29372959
BuildProgram.get(), KernelName.c_str(), &UrKernel);

0 commit comments

Comments
 (0)