Skip to content

Commit 1c77f9a

Browse files
[SYCL] Select a more consistent image ID for caching (#7154)
The program cache was recently changed to use the device image pointer as part of its cache key. However, the `RTDeviceBinaryImage` class has move constructor and assignment operator defined to allow them to transition between collections, so the pointers can change, making them an unreliable cache key. This commit changes the selected identifier to be the pointer to the underlying binary image instead. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 5034705 commit 1c77f9a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

sycl/source/detail/device_binary_image.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <sycl/detail/os_util.hpp>
1111
#include <sycl/detail/pi.hpp>
1212

13+
#include <atomic>
1314
#include <cstring>
1415
#include <memory>
1516

@@ -220,6 +221,11 @@ class RTDeviceBinaryImage {
220221
return DeviceRequirements;
221222
}
222223

224+
std::uintptr_t getImageID() const {
225+
assert(Bin && "Image ID is not available without a binary image.");
226+
return reinterpret_cast<std::uintptr_t>(Bin);
227+
}
228+
223229
protected:
224230
void init(pi_device_binary Bin);
225231
pi_device_binary get() const { return Bin; }

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ RT::PiProgram ProgramManager::getBuiltPIProgram(
642642

643643
const RT::PiDevice PiDevice = Dev->getHandleRef();
644644

645-
std::uintptr_t ImgId = reinterpret_cast<uintptr_t>(&Img);
645+
uint32_t ImgId = Img.getImageID();
646646
auto BuildResult = getOrBuild<PiProgramT, compile_program_error>(
647647
Cache,
648648
std::make_pair(std::make_pair(std::move(SpecConsts), ImgId),
@@ -1996,7 +1996,7 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage,
19961996
return BuiltProgram.release();
19971997
};
19981998

1999-
std::uintptr_t ImgId = reinterpret_cast<uintptr_t>(ImgPtr);
1999+
uint32_t ImgId = Img.getImageID();
20002000
const RT::PiDevice PiDevice = getRawSyclObjImpl(Devs[0])->getHandleRef();
20012001
// TODO: Throw SYCL2020 style exception
20022002
auto BuildResult = getOrBuild<PiProgramT, compile_program_error>(

0 commit comments

Comments
 (0)