Skip to content

Commit 97c0c99

Browse files
[SYCL] Fix use-after-move bug in building for multiple devices (#7237)
The cache key used while building kernel binaries will have the spec constant data moved to it to avoid repeated copies of a potentially large data structure. However, when building for multiple devices the spec constant data is moved each time a the cache key is created, which can corrupt the cache key. This commit fixes this by creating the cache key once and mutating it for each insertion, preserving common parts of they key and preventing use-after-move. Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
1 parent 968f9e7 commit 97c0c99

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,12 +1998,12 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage,
19981998

19991999
uint32_t ImgId = Img.getImageID();
20002000
const RT::PiDevice PiDevice = getRawSyclObjImpl(Devs[0])->getHandleRef();
2001+
auto CacheKey =
2002+
std::make_pair(std::make_pair(std::move(SpecConsts), ImgId),
2003+
std::make_pair(PiDevice, CompileOpts + LinkOpts));
20012004
// TODO: Throw SYCL2020 style exception
20022005
auto BuildResult = getOrBuild<PiProgramT, compile_program_error>(
2003-
Cache,
2004-
std::make_pair(std::make_pair(std::move(SpecConsts), ImgId),
2005-
std::make_pair(PiDevice, CompileOpts + LinkOpts)),
2006-
AcquireF, GetF, BuildF);
2006+
Cache, CacheKey, AcquireF, GetF, BuildF);
20072007
// getOrBuild is not supposed to return nullptr
20082008
assert(BuildResult != nullptr && "Invalid build result");
20092009

@@ -2024,11 +2024,10 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage,
20242024
const RT::PiDevice PiDeviceAdd =
20252025
getRawSyclObjImpl(Devs[Idx])->getHandleRef();
20262026

2027-
getOrBuild<PiProgramT, compile_program_error>(
2028-
Cache,
2029-
std::make_pair(std::make_pair(std::move(SpecConsts), ImgId),
2030-
std::make_pair(PiDeviceAdd, CompileOpts + LinkOpts)),
2031-
AcquireF, GetF, CacheOtherDevices);
2027+
// Change device in the cache key to reduce copying of spec const data.
2028+
CacheKey.second.first = PiDeviceAdd;
2029+
getOrBuild<PiProgramT, compile_program_error>(Cache, CacheKey, AcquireF,
2030+
GetF, CacheOtherDevices);
20322031
// getOrBuild is not supposed to return nullptr
20332032
assert(BuildResult != nullptr && "Invalid build result");
20342033
}

0 commit comments

Comments
 (0)