Skip to content
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

[SYCL] Fix get_specialization_constant segmentation fault #8542

Merged
merged 5 commits into from
Mar 21, 2023
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
12 changes: 7 additions & 5 deletions sycl/include/sycl/kernel_bundle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,17 +308,19 @@ class kernel_bundle : public detail::kernel_bundle_plain,
template <auto &SpecName>
typename std::remove_reference_t<decltype(SpecName)>::value_type
get_specialization_constant() const {
const char *SpecSymName = detail::get_spec_constant_symbolic_ID<SpecName>();
if (!is_specialization_constant_set(SpecSymName))
return SpecName.getDefaultValue();

using SCType =
typename std::remove_reference_t<decltype(SpecName)>::value_type;

const char *SpecSymName = detail::get_spec_constant_symbolic_ID<SpecName>();
SCType Res{SpecName.getDefaultValue()};
if (!is_specialization_constant_set(SpecSymName))
return Res;

std::array<char, sizeof(SCType)> RetValue;
get_specialization_constant_impl(SpecSymName, RetValue.data());
std::memcpy(&Res, RetValue.data(), sizeof(SCType));

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

/// \returns an iterator to the first device image kernel_bundle contains
Expand Down
6 changes: 5 additions & 1 deletion sycl/unittests/kernel-and-program/Cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ template <> const char *get_spec_constant_symbolic_ID<SpecConst1>() {
static sycl::unittest::PiImage generateDefaultImage() {
using namespace sycl::unittest;

std::vector<char> SpecConstData;
PiProperty SC1 = makeSpecConstant<int>(SpecConstData, "SC1", {0}, {0}, {42});

PiPropertySet PropSet;
addSpecConstants({SC1}, std::move(SpecConstData), PropSet);

std::vector<unsigned char> Bin{0, 1, 2, 3, 4, 5}; // Random data

Expand Down Expand Up @@ -256,7 +260,7 @@ TEST_F(KernelAndProgramCacheTest, SpecConstantCacheNegative) {
detail::KernelProgramCache::ProgramCache &Cache =
CtxImpl->getKernelProgramCache().acquireCachedPrograms().get();

EXPECT_EQ(Cache.size(), 1U) << "Expect non-empty cache";
EXPECT_EQ(Cache.size(), 2U) << "Expect an entry for each build in the cache.";
}

// Check that kernel_bundle created through join() is not cached.
Expand Down