Skip to content

Commit ec9f04d

Browse files
author
Sergey Kanaev
committed
[SYCL] Add test
Signed-off-by: Sergey Kanaev <sergey.kanaev@intel.com>
1 parent 56b6fa7 commit ec9f04d

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out %threads_lib -lOpenCL
2+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
3+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
4+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
5+
6+
#include <CL/sycl.hpp>
7+
8+
using namespace cl::sycl;
9+
using namespace cl::sycl::access;
10+
11+
static constexpr size_t BUFFER_SIZE = 1024;
12+
13+
// Check that a single host-task with a buffer will work
14+
void test1() {
15+
buffer<int, 1> Buffer{BUFFER_SIZE};
16+
17+
queue Q;
18+
19+
Q.submit([&](handler &CGH) {
20+
auto Acc = Buffer.get_access<mode::write>(CGH);
21+
CGH.codeplay_host_task([=]() {
22+
// A no-op
23+
});
24+
});
25+
}
26+
27+
void test2() {
28+
buffer<int, 1> Buffer1{BUFFER_SIZE};
29+
buffer<int, 1> Buffer2{BUFFER_SIZE};
30+
31+
queue Q;
32+
33+
Q.submit([&](handler &CGH) {
34+
auto Acc = Buffer1.template get_access<mode::write>(CGH);
35+
36+
auto Kernel = [=](item<1> Id) { Acc[Id] = 123; };
37+
CGH.parallel_for<class Test6Init>(Acc.get_count(), Kernel);
38+
});
39+
40+
Q.submit([&](handler &CGH) {
41+
auto AccSrc = Buffer1.template get_access<mode::read>(CGH);
42+
auto AccDst = Buffer2.template get_access<mode::write>(CGH);
43+
44+
CGH.codeplay_host_task([=]() {
45+
for (size_t Idx = 0; Idx < AccDst.get_count(); ++Idx)
46+
AccDst[Idx] = AccSrc[Idx];
47+
});
48+
});
49+
50+
{
51+
auto Acc = Buffer2.get_access<mode::read>();
52+
53+
for (size_t Idx = 0; Idx < Acc.get_count(); ++Idx) {
54+
std::cout << "Second buffer [" << Idx << "] = " << Acc[Idx] << std::endl;
55+
assert(Acc[Idx] == 123);
56+
}
57+
}
58+
}
59+
60+
int main() {
61+
test1();
62+
test2();
63+
return 0;
64+
}

0 commit comments

Comments
 (0)