From 090f029f42748de451d310a441f9eb300071a45a Mon Sep 17 00:00:00 2001 From: "Larsen, Steffen" Date: Sun, 6 Jul 2025 22:06:13 -0700 Subject: [PATCH] [SYCL] Change kernel_bundle linking restriction to check external symbols This commit changes the recent linking separation of offline images to be based on whether the images have external symbols, in addition to whether they have specialization constants. Signed-off-by: Larsen, Steffen --- sycl/source/detail/kernel_bundle_impl.hpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/sycl/source/detail/kernel_bundle_impl.hpp b/sycl/source/detail/kernel_bundle_impl.hpp index 0d144ac47a18d..5690bfab02276 100644 --- a/sycl/source/detail/kernel_bundle_impl.hpp +++ b/sycl/source/detail/kernel_bundle_impl.hpp @@ -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 ImagesWithSpecConsts; + std::vector ImagesWithoutExtSym; std::unordered_set> - ImagesWithSpecConstsSet; + ImagesWithoutExtSymSet; for (const kernel_bundle &ObjectBundle : ObjectBundles) { for (const DevImgPlainWithDeps &DeviceImageWithDeps : @@ -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)); } } @@ -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();) @@ -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) {