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

Commit 9f84342

Browse files
authored
[SYCL] Add test for multiple compiler targets (#593)
1 parent 68295c0 commit 9f84342

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

SYCL/Regression/multiple-targets.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// This test checks if CUDA and HIP can be compiled and run with spirv.
2+
// It tests if the target triples can be specified with any order.
3+
// The test is repeated for per_kernel device code splitting.
4+
//
5+
// REQUIRES: CUDA || HIP
6+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple,spirv64 -o %t.out %s \
7+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
8+
//
9+
// RUN: %clangxx -fsycl -fsycl-targets=spirv64,%sycl_triple -o %t.out %s \
10+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
11+
//
12+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple,spirv64 -fsycl-device-code-split=per_kernel -o %t.out %s \
13+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
14+
//
15+
// RUN: %clangxx -fsycl -fsycl-targets=spirv64,%sycl_triple -fsycl-device-code-split=per_kernel -o %t.out %s \
16+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
17+
//
18+
// XFAIL: hip_nvidia
19+
//
20+
21+
#include <CL/sycl.hpp>
22+
23+
int main() {
24+
cl::sycl::queue Q;
25+
int A_Data[10] = {0};
26+
int B_Data[10] = {4};
27+
int C_Data[10] = {-1};
28+
29+
{
30+
cl::sycl::buffer<int, 1> A_Buf(A_Data, cl::sycl::range<1>(10));
31+
32+
Q.submit([&](cl::sycl::handler &Cgh) {
33+
auto A_Acc = A_Buf.get_access<cl::sycl::access::mode::write>(Cgh);
34+
Cgh.parallel_for(cl::sycl::range<1>{5},
35+
[=](cl::sycl::id<1> index) { A_Acc[index] = 5; });
36+
});
37+
}
38+
39+
assert(A_Data[0] == 5);
40+
41+
{
42+
cl::sycl::buffer<int, 1> B_Buf(B_Data, cl::sycl::range<1>(10));
43+
cl::sycl::buffer<int, 1> C_Buf(C_Data, cl::sycl::range<1>(10));
44+
45+
Q.submit([&](cl::sycl::handler &Cgh) {
46+
auto B_Acc = B_Buf.get_access<cl::sycl::access::mode::read_write>(Cgh);
47+
auto C_Acc = C_Buf.get_access<cl::sycl::access::mode::read>(Cgh);
48+
Cgh.parallel_for(cl::sycl::range<1>{5}, [=](cl::sycl::id<1> index) {
49+
B_Acc[index] += C_Acc[index];
50+
});
51+
});
52+
}
53+
54+
assert(B_Data[0] == 3);
55+
56+
{
57+
cl::sycl::buffer<int, 1> B_Buf(B_Data, cl::sycl::range<1>(10));
58+
cl::sycl::buffer<int, 1> C_Buf(C_Data, cl::sycl::range<1>(10));
59+
60+
Q.submit([&](cl::sycl::handler &Cgh) {
61+
auto B_Acc = B_Buf.get_access<cl::sycl::access::mode::read>(Cgh);
62+
auto C_Acc = C_Buf.get_access<cl::sycl::access::mode::write>(Cgh);
63+
Cgh.parallel_for(cl::sycl::range<1>{5}, [=](cl::sycl::id<1> index) {
64+
C_Acc[index] = B_Acc[index];
65+
});
66+
});
67+
}
68+
69+
assert(C_Data[0] == 3);
70+
71+
return 0;
72+
}

0 commit comments

Comments
 (0)