Skip to content

Commit 8110c20

Browse files
author
Victor Lomuller
committed
Add test for sycl-graph
1 parent 033f773 commit 8110c20

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// RUN: %{build} -o %t.out
2+
// RUN: %{run} %t.out
3+
//
4+
5+
// Test work_group_static extension with allocation size specified at runtime.
6+
7+
#include <sycl/detail/core.hpp>
8+
#include <sycl/ext/oneapi/work_group_static.hpp>
9+
#include "../graph_common.hpp"
10+
11+
#include <vector>
12+
13+
constexpr size_t WgSize = 32;
14+
constexpr size_t WgCount = 4;
15+
constexpr size_t RepeatWG = 16;
16+
constexpr size_t ElemPerWG = WgSize * RepeatWG;
17+
constexpr size_t Size = WgSize * WgCount * RepeatWG;
18+
19+
using namespace sycl;
20+
21+
namespace exp_ext = sycl::ext::oneapi::experimental;
22+
23+
int main() {
24+
queue Q;
25+
exp_ext::command_graph Graph{Queue.get_context(), Queue.get_device()};
26+
27+
std::vector<int> Vec(Size, 0);
28+
buffer<int, 1> Buf{Vec.data(), range<1>(Size)};
29+
30+
auto NodeA = Graph.add([&](handler &Cgh) {
31+
auto Acc = Buf.get_access<access::mode::read_write>(Cgh);
32+
exp_ext::work_group_static_size static_size(WgSize * RepeatWG *
33+
sizeof(int));
34+
exp_ext::properties properties{static_size};
35+
Cgh.parallel_for(nd_range<1>(range<1>(Size), range<1>(WgSize)), properties,
36+
[=](nd_item<1> Item) {
37+
int *Ptr = reinterpret_cast<int *>(
38+
exp_ext::get_dynamic_work_group_memory());
39+
size_t GroupOffset =
40+
Item.get_group_linear_id() * ElemPerWG;
41+
for (size_t I = 0; I < RepeatWG; ++I) {
42+
Ptr[WgSize * I + Item.get_local_linear_id()] =
43+
Item.get_local_linear_id();
44+
}
45+
46+
Item.barrier();
47+
for (size_t I = 0; I < RepeatWG; ++I) {
48+
// Check that the memory is accessible from other
49+
// work-items
50+
size_t BaseIdx = GroupOffset + (I * WgSize);
51+
size_t LocalIdx = Item.get_local_linear_id() ^ 1;
52+
size_t GlobalIdx = BaseIdx + LocalIdx;
53+
Acc[GlobalIdx] = Ptr[WgSize * I + LocalIdx];
54+
}
55+
});
56+
});
57+
auto ExecGraph = Graph.finalize();
58+
59+
Queue.ext_oneapi_graph(ExecGraph).wait();
60+
61+
host_accessor Acc(Buf, read_only);
62+
for (size_t I = 0; I < Size; ++I) {
63+
assert(Acc[I] == I % WgSize);
64+
}
65+
}

0 commit comments

Comments
 (0)