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

Commit 02a20e6

Browse files
[SYCL] Add a test for group local memory w/o device code opt (#217)
1 parent 33c7aed commit 02a20e6

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -fno-sycl-early-optimizations %s -o %t.out
2+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
3+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
4+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
5+
6+
// The test checks that multiple calls to the same template instantiation of a
7+
// group local memory function result in separate allocations, even with device
8+
// code optimizations disabled (the implementation relies on inlining these
9+
// functions regardless of device code optimization settings).
10+
11+
#include <CL/sycl.hpp>
12+
13+
#include <cassert>
14+
#include <vector>
15+
16+
constexpr size_t WgSize = 32;
17+
constexpr size_t WgCount = 4;
18+
constexpr size_t Size = WgSize * WgCount;
19+
20+
class KernelA;
21+
22+
using namespace sycl;
23+
24+
int main() {
25+
queue Q;
26+
{
27+
std::vector<int *> VecA(Size, 0);
28+
std::vector<int *> VecB(Size, 0);
29+
buffer<int *, 1> BufA{VecA.data(), range<1>(Size)};
30+
buffer<int *, 1> BufB{VecB.data(), range<1>(Size)};
31+
32+
Q.submit([&](handler &Cgh) {
33+
auto AccA = BufA.get_access<access::mode::read_write>(Cgh);
34+
auto AccB = BufB.get_access<access::mode::read_write>(Cgh);
35+
Cgh.parallel_for<KernelA>(
36+
nd_range<1>(range<1>(Size), range<1>(WgSize)), [=](nd_item<1> Item) {
37+
multi_ptr<int, access::address_space::local_space> PtrA =
38+
group_local_memory_for_overwrite<int>(Item.get_group());
39+
multi_ptr<int, access::address_space::local_space> PtrB =
40+
group_local_memory_for_overwrite<int>(Item.get_group());
41+
42+
size_t GlobalId = Item.get_global_linear_id();
43+
AccA[GlobalId] = PtrA;
44+
AccB[GlobalId] = PtrB;
45+
});
46+
});
47+
48+
auto AccA = BufA.get_access<access::mode::read>();
49+
auto AccB = BufB.get_access<access::mode::read>();
50+
for (size_t I = 0; I < Size; ++I)
51+
assert(AccA[I] != AccB[I]);
52+
}
53+
}

0 commit comments

Comments
 (0)