Skip to content

Commit d58eb78

Browse files
[SYCL] Fix over-allocation in spec consts (#8546)
This commit fixes an issue where specialization constants would over-allocate memory. To avoid this causing errors this commit also fixes an issue where setting specialization constants would prepend the new value to the previous one. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent ecb148b commit d58eb78

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

sycl/include/sycl/kernel_bundle.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,7 @@ class kernel_bundle : public detail::kernel_bundle_plain,
315315
using SCType =
316316
typename std::remove_reference_t<decltype(SpecName)>::value_type;
317317

318-
std::array<char *, sizeof(SCType)> RetValue;
319-
318+
std::array<char, sizeof(SCType)> RetValue;
320319
get_specialization_constant_impl(SpecSymName, RetValue.data());
321320

322321
return *reinterpret_cast<SCType *>(RetValue.data());

sycl/source/detail/kernel_bundle_impl.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,9 @@ class kernel_bundle_impl {
425425
getSyclObjImpl(DeviceImage)
426426
->set_specialization_constant_raw_value(SpecName, Value);
427427
else {
428-
const auto *DataPtr = static_cast<const unsigned char *>(Value);
429428
std::vector<unsigned char> &Val = MSpecConstValues[std::string{SpecName}];
430429
Val.resize(Size);
431-
Val.insert(Val.begin(), DataPtr, DataPtr + Size);
430+
std::memcpy(Val.data(), Value, Size);
432431
}
433432
}
434433

0 commit comments

Comments
 (0)