Skip to content

Commit

Permalink
[SYCL] Fix use-after-move bug in building for multiple devices (#7237)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
steffenlarsen authored Nov 1, 2022
1 parent 968f9e7 commit 97c0c99
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions sycl/source/detail/program_manager/program_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1998,12 +1998,12 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage,

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

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

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

0 comments on commit 97c0c99

Please sign in to comment.