Skip to content

Commit 4e11774

Browse files
[NFC][SYCL] Clarify intent of device_image_impl::get_kernel_ids_ptr
1 parent 22ee417 commit 4e11774

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

sycl/source/detail/device_image_impl.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,12 @@ class device_image_impl
417417
const std::vector<kernel_id> &get_kernel_ids() const noexcept {
418418
return *MKernelIDs;
419419
}
420+
// This should only be used when creating new device_image_impls that have the
421+
// exact same set of kernels as the source one. In all other scenarios the
422+
// getter above is the one needed:
423+
std::shared_ptr<std::vector<kernel_id>> &get_kernel_ids_ptr() noexcept {
424+
return MKernelIDs;
425+
}
420426

421427
bool has_specialization_constants() const noexcept {
422428
// Lock the mutex to prevent when one thread in the middle of writing a
@@ -563,10 +569,6 @@ class device_image_impl
563569

564570
const context &get_context() const noexcept { return MContext; }
565571

566-
std::shared_ptr<std::vector<kernel_id>> &get_kernel_ids_ptr() noexcept {
567-
return MKernelIDs;
568-
}
569-
570572
std::vector<unsigned char> &get_spec_const_blob_ref() noexcept {
571573
return MSpecConstsBlob;
572574
}
@@ -1300,7 +1302,9 @@ class device_image_impl
13001302
ur_program_handle_t MProgram = nullptr;
13011303

13021304
// List of kernel ids available in this image, elements should be sorted
1303-
// according to LessByNameComp
1305+
// according to LessByNameComp. Shared between images for performance reasons
1306+
// (e.g. when we compile a single image it keeps the same kernels in it as the
1307+
// original source image).
13041308
std::shared_ptr<std::vector<kernel_id>> MKernelIDs;
13051309

13061310
// List of known kernel names.

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2905,10 +2905,8 @@ mergeImageData(const std::vector<device_image_plain> &Imgs,
29052905
for (const device_image_plain &Img : Imgs) {
29062906
device_image_impl &DeviceImageImpl = *getSyclObjImpl(Img);
29072907
// Duplicates are not expected here, otherwise urProgramLink should fail
2908-
if (DeviceImageImpl.get_kernel_ids_ptr())
2909-
KernelIDs.insert(KernelIDs.end(),
2910-
DeviceImageImpl.get_kernel_ids_ptr()->begin(),
2911-
DeviceImageImpl.get_kernel_ids_ptr()->end());
2908+
KernelIDs.insert(KernelIDs.end(), DeviceImageImpl.get_kernel_ids().begin(),
2909+
DeviceImageImpl.get_kernel_ids().end());
29122910
// To be able to answer queries about specialziation constants, the new
29132911
// device image should have the specialization constants from all the linked
29142912
// images.

sycl/source/kernel_bundle.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ bool has_kernel_bundle_impl(const context &Ctx, const std::vector<device> &Devs,
288288
const std::shared_ptr<device_image_impl> &DeviceImageImpl =
289289
getSyclObjImpl(DeviceImage);
290290

291-
CombinedKernelIDs.insert(DeviceImageImpl->get_kernel_ids_ptr()->begin(),
292-
DeviceImageImpl->get_kernel_ids_ptr()->end());
291+
CombinedKernelIDs.insert(DeviceImageImpl->get_kernel_ids().begin(),
292+
DeviceImageImpl->get_kernel_ids().end());
293293
}
294294
}
295295

0 commit comments

Comments
 (0)