Skip to content

Commit 5f0836c

Browse files
AlexeySachkovbb-sycl
authored andcommitted
[SYCL] Add test for set_arg with local_accessor (intel#1367)
Related change: intel/llvm#7313
1 parent 1feccc2 commit 5f0836c

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// REQUIRES: opencl, opencl_icd
2+
//
3+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s %opencl_lib -o %t.out
4+
// RUN: env SYCL_DEVICE_FILTER=opencl %CPU_RUN_PLACEHOLDER %t.out
5+
// RUN: env SYCL_DEVICE_FILTER=opencl %GPU_RUN_PLACEHOLDER %t.out
6+
// RUN: env SYCL_DEVICE_FILTER=opencl %ACC_RUN_PLACEHOLDER %t.out
7+
8+
#include <sycl/sycl.hpp>
9+
10+
using namespace sycl;
11+
12+
const char *clSource = R"(
13+
kernel void test(global int *a, local float *b, int n) {
14+
if (get_local_id(0) == 0) {
15+
for (int i = 0; i < n; i++)
16+
b[i] = i;
17+
}
18+
barrier(CLK_LOCAL_MEM_FENCE);
19+
20+
bool ok = true;
21+
for (int i = 0; i < n; i++)
22+
ok &= (b[i] == i);
23+
24+
a[get_global_id(0)] = ok;
25+
}
26+
)";
27+
28+
kernel getKernel(const queue &Q) {
29+
cl_int status = CL_SUCCESS;
30+
31+
auto device_cl = get_native<backend::opencl>(Q.get_device());
32+
auto context_cl = get_native<backend::opencl>(Q.get_context());
33+
auto program_cl =
34+
clCreateProgramWithSource(context_cl, 1, &clSource, nullptr, &status);
35+
assert(CL_SUCCESS == status);
36+
status = clBuildProgram(program_cl, 0, nullptr, "", nullptr, nullptr);
37+
assert(CL_SUCCESS == status);
38+
auto kernel_cl = clCreateKernel(program_cl, "test", &status);
39+
assert(CL_SUCCESS == status);
40+
41+
return make_kernel<backend::opencl>(kernel_cl, Q.get_context());
42+
}
43+
44+
int main() {
45+
queue Q;
46+
auto K = getKernel(Q);
47+
48+
constexpr cl_int N_slm = 256;
49+
constexpr int N_wg = 32;
50+
51+
cl_int init[N_wg];
52+
buffer<cl_int, 1> b(init, N_wg);
53+
54+
Q.submit([&](handler &cgh) {
55+
auto acc_global = b.get_access<access::mode::write>(cgh);
56+
local_accessor<float, 1> acc_local(N_slm, cgh);
57+
58+
cgh.set_arg(0, acc_global);
59+
cgh.set_arg(1, acc_local);
60+
cgh.set_arg(2, N_slm);
61+
62+
cgh.parallel_for(nd_range<1>(N_wg, 1), K);
63+
});
64+
65+
auto acc_global = b.get_access<access::mode::read>();
66+
for (int i = 0; i < N_wg; i++) {
67+
if (acc_global[i] != 1) {
68+
std::cerr << "Error in WG " << i << std::endl;
69+
exit(1);
70+
}
71+
}
72+
73+
std::cout << "Success" << std::endl;
74+
return 0;
75+
}

0 commit comments

Comments
 (0)