Skip to content

Commit c8b42fd

Browse files
committed
Update LIT tests for composite spec constants
Moved them into on-device directory as they are E2E tests required low-level runtimes and HW. Added one more test for composite spec constants.
1 parent 33d88b0 commit c8b42fd

File tree

2 files changed

+91
-8
lines changed

2 files changed

+91
-8
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// UNSUPPORTED: cuda
2+
//
3+
// RUN: %clangxx -fsycl %s -o %t.out
4+
// RUN: %RUN_ON_HOST %t.out | FileCheck %s
5+
// RUN: %CPU_RUN_PLACEHOLDER %t.out %CPU_CHECK_PLACEHOLDER
6+
// RUN: %GPU_RUN_PLACEHOLDER %t.out %GPU_CHECK_PLACEHOLDER
7+
//
8+
// The test checks that the specialization constant feature works correctly with
9+
// composite types: toolchain processes them correctly and runtime can correctly
10+
// execute the program.
11+
//
12+
// CHECK: 1 : 2
13+
// CHECK-NEXT: 3
14+
// CHECK-NEXT: 4 : 5
15+
16+
#include <CL/sycl.hpp>
17+
18+
using namespace cl::sycl;
19+
20+
struct A {
21+
float x;
22+
float y[2];
23+
};
24+
25+
struct pod_t {
26+
int f1[2];
27+
A f2;
28+
};
29+
30+
class my_kernel_t {
31+
public:
32+
using sc_t =
33+
sycl::ONEAPI::experimental::spec_constant<pod_t, class my_kernel_t>;
34+
35+
my_kernel_t(const sc_t &sc, const cl::sycl::stream &strm)
36+
: sc_(sc), strm_(strm) {}
37+
38+
void operator()(cl::sycl::id<1> i) const {
39+
auto p = sc_.get();
40+
strm_ << p.f1[0] << " : " << p.f1[1] << "\n";
41+
strm_ << p.f2.x << "\n";
42+
strm_ << p.f2.y[0] << " : " << p.f2.y[1] << "\n";
43+
strm_ << sycl::endl;
44+
}
45+
46+
sc_t sc_;
47+
cl::sycl::stream strm_;
48+
};
49+
50+
int main() {
51+
cl::sycl::queue q(default_selector{}, [](exception_list l) {
52+
for (auto ep : l) {
53+
try {
54+
std::rethrow_exception(ep);
55+
} catch (cl::sycl::exception &e0) {
56+
std::cout << e0.what();
57+
} catch (std::exception &e1) {
58+
std::cout << e1.what();
59+
} catch (...) {
60+
std::cout << "*** catch (...)\n";
61+
}
62+
}
63+
});
64+
65+
pod_t pod;
66+
pod.f1[0] = 1;
67+
pod.f1[1] = 2;
68+
pod.f2.x = 3;
69+
pod.f2.y[0] = 4;
70+
pod.f2.y[1] = 5;
71+
72+
cl::sycl::program p(q.get_context());
73+
auto sc = p.set_spec_constant<my_kernel_t>(pod);
74+
p.build_with_kernel_type<my_kernel_t>();
75+
76+
q.submit([&](cl::sycl::handler &cgh) {
77+
cl::sycl::stream strm(1024, 256, cgh);
78+
my_kernel_t func(sc, strm);
79+
80+
auto sycl_kernel = p.get_kernel<my_kernel_t>();
81+
cgh.parallel_for(sycl_kernel, cl::sycl::range<1>(1), func);
82+
});
83+
q.wait();
84+
85+
return 0;
86+
}
87+

sycl/test/composite-spec-const.cpp renamed to sycl/test/on-device/spec_const/composite-type.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
// UNSUPPORTED: cuda
22
//
3-
// TODO: this test is disabled because we need two more patches (to
4-
// sycl-post-link and llvm-spirv) to appear in the repo in order to get this
5-
// feature working.
6-
// RUN: true
7-
// RUNx: %clangxx -fsycl %s -o %t.out
8-
// RUNx: env SYCL_DEVICE_TYPE=HOST %t.out
9-
// RUNx: %CPU_RUN_PLACEHOLDER %t.out
10-
// RUNx: %GPU_RUN_PLACEHOLDER %t.out
3+
// RUN: %clangxx -fsycl %s -o %t.out
4+
// RUN: %RUN_ON_HOST %t.out
5+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
6+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
117
//
128
// The test checks that the specialization constant feature works correctly with
139
// composite types: toolchain processes them correctly and runtime can correctly

0 commit comments

Comments
 (0)