Skip to content

Commit 6151eed

Browse files
[SYCL][NFCI] Make device binary image pointers const in more places (#19099)
This commit changes the use of RTDeviceBinaryImage pointers to be const in more places. Primary cases where we break this is for compressed images, where decompression happens semi-lazily, so const-casts are occassionally necessary. --------- Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
1 parent cc2b985 commit 6151eed

File tree

10 files changed

+97
-96
lines changed

10 files changed

+97
-96
lines changed

sycl/source/detail/device_binary_image.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ class DynRTDeviceBinaryImage : public RTDeviceBinaryImage {
296296
}
297297

298298
static DynRTDeviceBinaryImage
299-
merge(const std::vector<RTDeviceBinaryImage *> &Imgs);
299+
merge(const std::vector<const RTDeviceBinaryImage *> &Imgs);
300300

301301
protected:
302302
DynRTDeviceBinaryImage();

sycl/source/detail/device_global_map.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace detail {
2323

2424
class DeviceGlobalMap {
2525
public:
26-
void initializeEntries(RTDeviceBinaryImage *Img) {
26+
void initializeEntries(const RTDeviceBinaryImage *Img) {
2727
const auto &DeviceGlobals = Img->getDeviceGlobals();
2828
std::lock_guard<std::mutex> DeviceGlobalsGuard(MDeviceGlobalsMutex);
2929
for (const sycl_device_binary_property &DeviceGlobal : DeviceGlobals) {

sycl/source/detail/device_global_map_entry.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct DeviceGlobalMapEntry {
5555
// Pointer to the device_global on host.
5656
const void *MDeviceGlobalPtr = nullptr;
5757
// Images device_global are used by.
58-
std::unordered_set<RTDeviceBinaryImage *> MImages;
58+
std::unordered_set<const RTDeviceBinaryImage *> MImages;
5959
// The image identifiers for the images using the device_global used by in the
6060
// cache.
6161
std::set<std::uintptr_t> MImageIdentifiers;
@@ -71,7 +71,7 @@ struct DeviceGlobalMapEntry {
7171

7272
// Constructor for only initializing ID, type size, and device image scope
7373
// flag. The pointer to the device global will be initialized later.
74-
DeviceGlobalMapEntry(std::string UniqueId, RTDeviceBinaryImage *Img,
74+
DeviceGlobalMapEntry(std::string UniqueId, const RTDeviceBinaryImage *Img,
7575
std::uint32_t DeviceGlobalTSize,
7676
bool IsDeviceImageScopeDecorated)
7777
: MUniqueId(UniqueId), MImages{Img},
@@ -89,7 +89,8 @@ struct DeviceGlobalMapEntry {
8989

9090
// Initialize the device_global's element type size and the flag signalling
9191
// if the device_global has the device_image_scope property.
92-
void initialize(RTDeviceBinaryImage *Img, std::uint32_t DeviceGlobalTSize,
92+
void initialize(const RTDeviceBinaryImage *Img,
93+
std::uint32_t DeviceGlobalTSize,
9394
bool IsDeviceImageScopeDecorated) {
9495
if (MDeviceGlobalTSize != 0) {
9596
// The device global entry has already been initialized. This can happen

sycl/source/detail/device_image_impl.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,11 +1136,12 @@ class device_image_impl
11361136
// imports.
11371137
// TODO: Consider making a collectDeviceImageDeps variant that takes a
11381138
// set reference and inserts into that instead.
1139-
std::set<RTDeviceBinaryImage *> ImgDeps;
1139+
std::set<const RTDeviceBinaryImage *> ImgDeps;
11401140
for (const device &Device : DevImgImpl->get_devices()) {
1141-
std::set<RTDeviceBinaryImage *> DevImgDeps = PM.collectDeviceImageDeps(
1142-
*NewImage, *getSyclObjImpl(Device),
1143-
/*ErrorOnUnresolvableImport=*/State == bundle_state::executable);
1141+
std::set<const RTDeviceBinaryImage *> DevImgDeps =
1142+
PM.collectDeviceImageDeps(*NewImage, *getSyclObjImpl(Device),
1143+
/*ErrorOnUnresolvableImport=*/State ==
1144+
bundle_state::executable);
11441145
ImgDeps.insert(DevImgDeps.begin(), DevImgDeps.end());
11451146
}
11461147

@@ -1155,13 +1156,13 @@ class device_image_impl
11551156
if (State == bundle_state::executable) {
11561157
// If target is executable we bundle the image and dependencies together
11571158
// and bring it into state.
1158-
for (RTDeviceBinaryImage *ImgDep : ImgDeps)
1159+
for (const RTDeviceBinaryImage *ImgDep : ImgDeps)
11591160
NewImageAndDeps.push_back(PM.createDependencyImage(
11601161
MContext, SupportingDevsRef, ImgDep, bundle_state::input));
11611162
} else if (State == bundle_state::object) {
11621163
// If the target is object, we bring the dependencies into object state
11631164
// individually and put them in the bundle.
1164-
for (RTDeviceBinaryImage *ImgDep : ImgDeps) {
1165+
for (const RTDeviceBinaryImage *ImgDep : ImgDeps) {
11651166
DevImgPlainWithDeps ImgDepWithDeps{PM.createDependencyImage(
11661167
MContext, SupportingDevsRef, ImgDep, bundle_state::input)};
11671168
PM.bringSYCLDeviceImageToState(ImgDepWithDeps, State);

sycl/source/detail/helpers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ retrieveKernelBinary(queue_impl &Queue, KernelNameStrRefT KernelName,
4949
ProgramManager::getInstance().getRawDeviceImages(KernelIds);
5050
auto DeviceImage = std::find_if(
5151
DeviceImages.begin(), DeviceImages.end(),
52-
[isNvidia](RTDeviceBinaryImage *DI) {
52+
[isNvidia](const RTDeviceBinaryImage *DI) {
5353
const std::string &TargetSpec = isNvidia ? std::string("llvm_nvptx64")
5454
: std::string("llvm_amdgcn");
5555
return DI->getFormat() == SYCL_DEVICE_BINARY_TYPE_LLVMIR_BITCODE &&

sycl/source/detail/memory_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ getOrBuildProgramForDeviceGlobal(queue_impl &Queue,
11451145
// If there was no cached program, build one.
11461146
auto Context = createSyclObjFromImpl<context>(ContextImpl);
11471147
ProgramManager &PM = ProgramManager::getInstance();
1148-
RTDeviceBinaryImage &Img = PM.getDeviceImage(
1148+
const RTDeviceBinaryImage &Img = PM.getDeviceImage(
11491149
DeviceGlobalEntry->MImages, ContextImpl, *getSyclObjImpl(Device));
11501150

11511151
device_image_plain DeviceImage =

0 commit comments

Comments
 (0)