Skip to content

Commit 9eb1184

Browse files
authored
[SYCL] Update native_specialization_constant when no specialization constants are present (#8868)
From the spec update KhronosGroup/SYCL-Docs#346, `native_specialization_constant()` should return false when the kernel bundle contains no specialization constants. --------- Signed-off-by: Cai, Justin <[email protected]>
1 parent 24ec33c commit 9eb1184

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

sycl/source/detail/kernel_bundle_impl.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ class kernel_bundle_impl {
402402
}
403403

404404
bool native_specialization_constant() const noexcept {
405-
return std::all_of(MDeviceImages.begin(), MDeviceImages.end(),
405+
return contains_specialization_constants() &&
406+
std::all_of(MDeviceImages.begin(), MDeviceImages.end(),
406407
[](const device_image_plain &DeviceImage) {
407408
return getSyclObjImpl(DeviceImage)
408409
->all_specialization_constant_native();

sycl/test-e2e/SpecConstants/2020/kernel-bundle-api.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class TestSetAndGetOnDevice;
3131
bool test_default_values(sycl::queue q);
3232
bool test_set_and_get_on_host(sycl::queue q);
3333
bool test_set_and_get_on_device(sycl::queue q);
34+
bool test_native_specialization_constant(sycl::queue q);
3435

3536
int main() {
3637
auto exception_handler = [&](sycl::exception_list exceptions) {
@@ -63,6 +64,12 @@ int main() {
6364
return 1;
6465
}
6566

67+
if (!test_native_specialization_constant(q)) {
68+
std::cout << "Test for native specialization constants failed!"
69+
<< std::endl;
70+
return 1;
71+
}
72+
6673
return 0;
6774
};
6875

@@ -257,3 +264,11 @@ bool test_set_and_get_on_device(sycl::queue q) {
257264

258265
return true;
259266
}
267+
268+
bool test_native_specialization_constant(sycl::queue q) {
269+
const auto always_false_selector = [](auto device_image) { return false; };
270+
auto bundle = sycl::get_kernel_bundle<sycl::bundle_state::executable>(
271+
q.get_context(), always_false_selector);
272+
return check_value(bundle.native_specialization_constant(), false,
273+
"empty bundle native specialization constant");
274+
}

0 commit comments

Comments
 (0)