Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit a8a50ef

Browse files
authored
[ESIMD] Add a test specialization constant that is set but not used (#1108)
* [ESIMD] Add a test for specialization const that is set but not used The test verifies that SegFault is not happening on the host side due to attempt to dereference the pointer to non-existing buffer that is supposed to be used for spec constants, but not allocated in the binary image when spec const is not used. Signed-off-by: Vyacheslav N Klochkov <[email protected]>
1 parent 86df4d0 commit a8a50ef

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

SYCL/ESIMD/unused_spec_const.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// REQUIRES: gpu
2+
// UNSUPPORTED: cuda || hip
3+
// RUN: %clangxx -fsycl %s -o %t.out
4+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
5+
6+
// This test checks that if specialization constant is set but not used, then
7+
// 1) The kernel still works properly;
8+
// 2) The kernel parameter holding the buffer for specialization constants is
9+
// optimized away.
10+
// TODO: the second part of the check should be added to this test when
11+
// DAE (Dead Arguments Elimination) optimization is enabled for ESIMD.
12+
13+
#include <CL/sycl.hpp>
14+
#include <iostream>
15+
#include <sycl/ext/intel/esimd.hpp>
16+
17+
constexpr sycl::specialization_id<int> Spec;
18+
19+
int main() {
20+
sycl::queue Q;
21+
std::cout << "Running on: "
22+
<< Q.get_device().get_info<sycl::info::device::name>() << std::endl;
23+
24+
int *A = sycl::malloc_shared<int>(1, Q);
25+
*A = 123;
26+
Q.submit([&](sycl::handler &CGH) {
27+
CGH.set_specialization_constant<Spec>(42);
28+
CGH.single_task([=](sycl::kernel_handler KH) SYCL_ESIMD_KERNEL {
29+
// This use of get_specializaiton_constant is commented out.
30+
// Thus the device code doen't have info about it and cannot allocate
31+
// memory/buffer for it on device side.
32+
// The test checks that the unused kernel parameter is either
33+
// eliminated by DAE optimization OR nullptr is passed for that argument.
34+
35+
// KH.get_specialization_constant<Spec>();
36+
sycl::ext::intel::esimd::simd<int, 1> V(A);
37+
V += 2;
38+
V.copy_to(A);
39+
});
40+
}).wait();
41+
42+
int AVal = *A;
43+
sycl::free(A, Q);
44+
45+
if (AVal != 125) {
46+
std::cout << "Failed: " << AVal << " != 125" << std::endl;
47+
return 1;
48+
}
49+
std::cout << "Passed" << std::endl;
50+
return 0;
51+
}

0 commit comments

Comments
 (0)