Skip to content

[SYCL] Change kernel_bundle linking restriction to check external symbols #19318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions sycl/source/detail/kernel_bundle_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,12 @@ class kernel_bundle_impl

// Due to a bug in L0, specializations with conflicting IDs will overwrite
// each other when linked together, so to avoid this issue we link
// images with specialization constants in separation.
// inline SYCL images in separation, unless they have external symbols and
// no specialization constants.
// TODO: Remove when spec const overwriting issue has been fixed in L0.
std::vector<const DevImgPlainWithDeps *> ImagesWithSpecConsts;
std::vector<const DevImgPlainWithDeps *> ImagesWithoutExtSym;
std::unordered_set<std::shared_ptr<device_image_impl>>
ImagesWithSpecConstsSet;
ImagesWithoutExtSymSet;
for (const kernel_bundle<bundle_state::object> &ObjectBundle :
ObjectBundles) {
for (const DevImgPlainWithDeps &DeviceImageWithDeps :
Expand All @@ -261,13 +262,16 @@ class kernel_bundle_impl
[](const device_image_plain &DevImg) {
const RTDeviceBinaryImage *BinImg =
getSyclObjImpl(DevImg)->get_bin_image_ref();
return BinImg && BinImg->getSpecConstants().size();
return BinImg &&
(!BinImg->getSpecConstants().empty() ||
(BinImg->getExportedSymbols().empty() &&
BinImg->getImportedSymbols().empty()));
}))
continue;

ImagesWithSpecConsts.push_back(&DeviceImageWithDeps);
ImagesWithoutExtSym.push_back(&DeviceImageWithDeps);
for (const device_image_plain &DevImg : DeviceImageWithDeps)
ImagesWithSpecConstsSet.insert(getSyclObjImpl(DevImg));
ImagesWithoutExtSymSet.insert(getSyclObjImpl(DevImg));
}
}

Expand All @@ -279,8 +283,8 @@ class kernel_bundle_impl
ObjectBundles)
for (const device_image_plain &DevImg :
getSyclObjImpl(ObjectBundle)->MUniqueDeviceImages)
if (ImagesWithSpecConstsSet.find(getSyclObjImpl(DevImg)) ==
ImagesWithSpecConstsSet.end())
if (ImagesWithoutExtSymSet.find(getSyclObjImpl(DevImg)) ==
ImagesWithoutExtSymSet.end())
DevImagesSet.insert(getSyclObjImpl(DevImg));
DevImages.reserve(DevImagesSet.size());
for (auto It = DevImagesSet.begin(); It != DevImagesSet.end();)
Expand Down Expand Up @@ -396,8 +400,7 @@ class kernel_bundle_impl
}

// ... And link the offline images in separation. (Workaround.)
for (const DevImgPlainWithDeps *DeviceImageWithDeps :
ImagesWithSpecConsts) {
for (const DevImgPlainWithDeps *DeviceImageWithDeps : ImagesWithoutExtSym) {
// Skip images which are not compatible with devices provided
if (std::none_of(MDevices.begin(), MDevices.end(),
[DeviceImageWithDeps](const device &Dev) {
Expand Down
Loading