Skip to content

Commit c9eb12f

Browse files
authored
[SYCL] add extra tests (intel#37)
- add tests from intel/llvm; - make SYCL/ESIMD/mandelbrot tests generate data files in build directory and remove data file from GIT; - rename regression directory to match llvm-test-suite naming (Regression); - fix clang-format issues.
1 parent a750778 commit c9eb12f

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Test1 - check that kernel can call a SYCL_EXTERNAL function defined in a
2+
// different object file.
3+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -DSOURCE1 -c %s -o %t1.o
4+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -DSOURCE2 -c %s -o %t2.o
5+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %t1.o %t2.o -o %t.exe
6+
// RUN: %CPU_RUN_PLACEHOLDER %t.exe
7+
// RUN: %GPU_RUN_PLACEHOLDER %t.exe
8+
// RUN: %ACC_RUN_PLACEHOLDER %t.exe
9+
//
10+
// Test2 - check that kernel can call a SYCL_EXTERNAL function defined in a
11+
// static library.
12+
// RUN: rm -f %t.a
13+
// RUN: llvm-ar crv %t.a %t1.o
14+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %t2.o -foffload-static-lib=%t.a -o %t.exe
15+
// RUN: %CPU_RUN_PLACEHOLDER %t.exe
16+
// RUN: %GPU_RUN_PLACEHOLDER %t.exe
17+
// RUN: %ACC_RUN_PLACEHOLDER %t.exe
18+
19+
#include <CL/sycl.hpp>
20+
#include <iostream>
21+
22+
#ifdef SOURCE1
23+
int bar(int b);
24+
25+
SYCL_EXTERNAL
26+
int foo(int a, int b) { return a + bar(b); }
27+
28+
int bar(int b) { return b + 5; }
29+
#endif // SOURCE1
30+
31+
#ifdef SOURCE2
32+
SYCL_EXTERNAL
33+
int foo(int A, int B);
34+
35+
int main(void) {
36+
constexpr unsigned Size = 4;
37+
int A[Size] = {1, 2, 3, 4};
38+
int B[Size] = {1, 2, 3, 4};
39+
int C[Size];
40+
41+
{
42+
cl::sycl::range<1> range{Size};
43+
cl::sycl::buffer<int, 1> bufA(A, range);
44+
cl::sycl::buffer<int, 1> bufB(B, range);
45+
cl::sycl::buffer<int, 1> bufC(C, range);
46+
47+
cl::sycl::queue().submit([&](cl::sycl::handler &cgh) {
48+
auto accA = bufA.get_access<cl::sycl::access::mode::read>(cgh);
49+
auto accB = bufB.get_access<cl::sycl::access::mode::read>(cgh);
50+
auto accC = bufC.get_access<cl::sycl::access::mode::write>(cgh);
51+
52+
cgh.parallel_for<class Test>(range, [=](cl::sycl::id<1> ID) {
53+
accC[ID] = foo(accA[ID], accB[ID]);
54+
});
55+
});
56+
}
57+
58+
for (unsigned I = 0; I < Size; ++I) {
59+
int Ref = foo(A[I], B[I]);
60+
if (C[I] != Ref) {
61+
std::cout << "fail: [" << I << "] == " << C[I] << ", expected " << Ref
62+
<< "\n";
63+
return 1;
64+
}
65+
}
66+
std::cout << "pass\n";
67+
return 0;
68+
}
69+
#endif // SOURCE2

0 commit comments

Comments
 (0)