Skip to content

Commit d21082f

Browse files
[SYCL] Fix linking of kernel-bundles (#4398)
when fsycl-device-code-split=per_kernel is used in conjunction with multiple kernels, then explicit sycl::link(sycl::compile(my-kernel-bundle)) will fail, because we link all device images in a kernel together. But, the device-images are independent, there is presently no known situation where they should be linked together. So this PR works around this limitation by linking them separately. This may have to be revisited once shared library style linking is supported, but that is likely true whether this bug is fixed or not. Signed-off-by: Chris Perkins <[email protected]>
1 parent 6ff9cf7 commit d21082f

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

sycl/source/detail/kernel_bundle_impl.hpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,13 @@ class kernel_bundle_impl {
192192
// TODO: Unify with c'tor for sycl::comile and sycl::build by calling
193193
// sycl::join on vector of kernel_bundles
194194

195-
std::vector<device_image_plain> DeviceImages;
195+
// The loop below just links each device image separately, not linking any
196+
// two device images together. This is correct so long as each device image
197+
// has no unresolved symbols. That's the case when device images are created
198+
// from generic SYCL APIs. There's no way in generic SYCL to create a kernel
199+
// which references an undefined symbol. If we decide in the future to allow
200+
// a backend interop API to create a "sycl::kernel_bundle" that references
201+
// undefined symbols, then the logic in this loop will need to be changed.
196202
for (const kernel_bundle<bundle_state::object> &ObjectBundle :
197203
ObjectBundles) {
198204
for (const device_image_plain &DeviceImage : ObjectBundle) {
@@ -205,13 +211,15 @@ class kernel_bundle_impl {
205211
}))
206212
continue;
207213

208-
DeviceImages.insert(DeviceImages.end(), DeviceImage);
214+
const std::vector<device_image_plain> VectorOfOneImage{DeviceImage};
215+
std::vector<device_image_plain> LinkedResults =
216+
detail::ProgramManager::getInstance().link(VectorOfOneImage,
217+
MDevices, PropList);
218+
MDeviceImages.insert(MDeviceImages.end(), LinkedResults.begin(),
219+
LinkedResults.end());
209220
}
210221
}
211222

212-
MDeviceImages = detail::ProgramManager::getInstance().link(
213-
std::move(DeviceImages), MDevices, PropList);
214-
215223
for (const kernel_bundle<bundle_state::object> &Bundle : ObjectBundles) {
216224
const KernelBundleImplPtr BundlePtr = getSyclObjImpl(Bundle);
217225
for (const std::pair<const std::string, std::vector<unsigned char>>

0 commit comments

Comments
 (0)