Skip to content

Commit cb6568c

Browse files
steffenlarsenbb-sycl
authored andcommitted
[SYCL] Add regression test for get_local_linear_id (intel#1525)
This commit adds a test comparing the result of get_local_linear_id on the nd_item with that of the corresponding group. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 6e622a4 commit cb6568c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %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+
// Checks that get_local_linear_id is the same on the nd_item as on the
7+
// corresponding group.
8+
9+
#include <iostream>
10+
#include <sycl/sycl.hpp>
11+
12+
int main() {
13+
const sycl::range<3> GlobalRange(2, 8, 16);
14+
const sycl::range<3> LocalRange(2, 4, 4);
15+
sycl::queue Q;
16+
bool *ReadSame = sycl::malloc_shared<bool>(GlobalRange.size(), Q);
17+
Q.parallel_for(sycl::nd_range<3>{GlobalRange, LocalRange},
18+
[=](sycl::nd_item<3> Item) {
19+
ReadSame[Item.get_global_linear_id()] =
20+
Item.get_local_linear_id() ==
21+
Item.get_group().get_local_linear_id();
22+
})
23+
.wait();
24+
int Failures = 0;
25+
for (size_t I = 0; I < GlobalRange.size(); ++I) {
26+
if (ReadSame[I])
27+
continue;
28+
++Failures;
29+
std::cout << "Read mismatch at index " << I << std::endl;
30+
}
31+
sycl::free(ReadSame, Q);
32+
return Failures;
33+
}

0 commit comments

Comments
 (0)