Skip to content

Commit 81c87e5

Browse files
authored
[SYCL] Switch NativePrograms back to using multimap (#14951)
4f86ab replaced `insert` with `[]` in order to fix a pointer re-use issue, however that was not the correct fix. Instead, a multimap was incorrectly converted to a regular map during the PI->UR conversion. This change reverts the rest of 4f86ab (besides the test, which is still valid), and converts NativePrograms back to a multimap. --- Thanks to @AlexeySachkov for finding the real issue in #14873 (comment)
1 parent ce23765 commit 81c87e5

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ ProgramManager::createURProgram(const RTDeviceBinaryImage &Img,
229229
{
230230
std::lock_guard<std::mutex> Lock(MNativeProgramsMutex);
231231
// associate the UR program with the image it was created for
232-
NativePrograms[Res] = &Img;
232+
NativePrograms.insert({Res, &Img});
233233
}
234234

235235
Ctx->addDeviceGlobalInitializer(Res, {Device}, &Img);
@@ -840,7 +840,7 @@ ur_program_handle_t ProgramManager::getBuiltURProgram(
840840

841841
{
842842
std::lock_guard<std::mutex> Lock(MNativeProgramsMutex);
843-
NativePrograms[BuiltProgram.get()] = &Img;
843+
NativePrograms.insert({BuiltProgram.get(), &Img});
844844
for (RTDeviceBinaryImage *LinkedImg : DeviceImagesToLink) {
845845
NativePrograms.insert({BuiltProgram.get(), LinkedImg});
846846
}
@@ -2500,7 +2500,7 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage,
25002500

25012501
{
25022502
std::lock_guard<std::mutex> Lock(MNativeProgramsMutex);
2503-
NativePrograms[BuiltProgram.get()] = &Img;
2503+
NativePrograms.insert({BuiltProgram.get(), &Img});
25042504
}
25052505

25062506
ContextImpl->addDeviceGlobalInitializer(BuiltProgram.get(), Devs, &Img);

sycl/source/detail/program_manager/program_manager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ class ProgramManager {
398398
// the underlying program disposed of), so the map can't be used in any way
399399
// other than binary image lookup with known live UrProgram as the key.
400400
// NOTE: access is synchronized via the MNativeProgramsMutex
401-
std::unordered_map<ur_program_handle_t, const RTDeviceBinaryImage *>
401+
std::unordered_multimap<ur_program_handle_t, const RTDeviceBinaryImage *>
402402
NativePrograms;
403403

404404
/// Protects NativePrograms that can be changed by class' methods.

0 commit comments

Comments
 (0)