Skip to content

[SYCL][NFCI] Make device binary image pointers const in more places #19099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sycl/source/detail/device_binary_image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class DynRTDeviceBinaryImage : public RTDeviceBinaryImage {
}

static DynRTDeviceBinaryImage
merge(const std::vector<RTDeviceBinaryImage *> &Imgs);
merge(const std::vector<const RTDeviceBinaryImage *> &Imgs);

protected:
DynRTDeviceBinaryImage();
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/device_global_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace detail {

class DeviceGlobalMap {
public:
void initializeEntries(RTDeviceBinaryImage *Img) {
void initializeEntries(const RTDeviceBinaryImage *Img) {
const auto &DeviceGlobals = Img->getDeviceGlobals();
std::lock_guard<std::mutex> DeviceGlobalsGuard(MDeviceGlobalsMutex);
for (const sycl_device_binary_property &DeviceGlobal : DeviceGlobals) {
Expand Down
7 changes: 4 additions & 3 deletions sycl/source/detail/device_global_map_entry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct DeviceGlobalMapEntry {
// Pointer to the device_global on host.
const void *MDeviceGlobalPtr = nullptr;
// Images device_global are used by.
std::unordered_set<RTDeviceBinaryImage *> MImages;
std::unordered_set<const RTDeviceBinaryImage *> MImages;
// The image identifiers for the images using the device_global used by in the
// cache.
std::set<std::uintptr_t> MImageIdentifiers;
Expand All @@ -71,7 +71,7 @@ struct DeviceGlobalMapEntry {

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

// Initialize the device_global's element type size and the flag signalling
// if the device_global has the device_image_scope property.
void initialize(RTDeviceBinaryImage *Img, std::uint32_t DeviceGlobalTSize,
void initialize(const RTDeviceBinaryImage *Img,
std::uint32_t DeviceGlobalTSize,
bool IsDeviceImageScopeDecorated) {
if (MDeviceGlobalTSize != 0) {
// The device global entry has already been initialized. This can happen
Expand Down
13 changes: 7 additions & 6 deletions sycl/source/detail/device_image_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,11 +1125,12 @@ class device_image_impl {
// imports.
// TODO: Consider making a collectDeviceImageDeps variant that takes a
// set reference and inserts into that instead.
std::set<RTDeviceBinaryImage *> ImgDeps;
std::set<const RTDeviceBinaryImage *> ImgDeps;
for (const device &Device : DevImgImpl->get_devices()) {
std::set<RTDeviceBinaryImage *> DevImgDeps = PM.collectDeviceImageDeps(
*NewImage, *getSyclObjImpl(Device),
/*ErrorOnUnresolvableImport=*/State == bundle_state::executable);
std::set<const RTDeviceBinaryImage *> DevImgDeps =
PM.collectDeviceImageDeps(*NewImage, *getSyclObjImpl(Device),
/*ErrorOnUnresolvableImport=*/State ==
bundle_state::executable);
ImgDeps.insert(DevImgDeps.begin(), DevImgDeps.end());
}

Expand All @@ -1144,13 +1145,13 @@ class device_image_impl {
if (State == bundle_state::executable) {
// If target is executable we bundle the image and dependencies together
// and bring it into state.
for (RTDeviceBinaryImage *ImgDep : ImgDeps)
for (const RTDeviceBinaryImage *ImgDep : ImgDeps)
NewImageAndDeps.push_back(PM.createDependencyImage(
MContext, SupportingDevsRef, ImgDep, bundle_state::input));
} else if (State == bundle_state::object) {
// If the target is object, we bring the dependencies into object state
// individually and put them in the bundle.
for (RTDeviceBinaryImage *ImgDep : ImgDeps) {
for (const RTDeviceBinaryImage *ImgDep : ImgDeps) {
DevImgPlainWithDeps ImgDepWithDeps{PM.createDependencyImage(
MContext, SupportingDevsRef, ImgDep, bundle_state::input)};
PM.bringSYCLDeviceImageToState(ImgDepWithDeps, State);
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ retrieveKernelBinary(queue_impl &Queue, KernelNameStrRefT KernelName,
ProgramManager::getInstance().getRawDeviceImages(KernelIds);
auto DeviceImage = std::find_if(
DeviceImages.begin(), DeviceImages.end(),
[isNvidia](RTDeviceBinaryImage *DI) {
[isNvidia](const RTDeviceBinaryImage *DI) {
const std::string &TargetSpec = isNvidia ? std::string("llvm_nvptx64")
: std::string("llvm_amdgcn");
return DI->getFormat() == SYCL_DEVICE_BINARY_TYPE_LLVMIR_BITCODE &&
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ getOrBuildProgramForDeviceGlobal(queue_impl &Queue,
// If there was no cached program, build one.
auto Context = createSyclObjFromImpl<context>(ContextImpl);
ProgramManager &PM = ProgramManager::getInstance();
RTDeviceBinaryImage &Img = PM.getDeviceImage(
const RTDeviceBinaryImage &Img = PM.getDeviceImage(
DeviceGlobalEntry->MImages, ContextImpl, *getSyclObjImpl(Device));

device_image_plain DeviceImage =
Expand Down
Loading