Skip to content

Commit 14438de

Browse files
committed
[SYCL] Add regression test for collective barrier
Calls reduce, exclusive scan and inclusive scan multiple times back-to-back. Note that since we are testing for a race condition, it is possible for this test to pass even with an incorrect implementation. Signed-off-by: John Pennycook <[email protected]>
1 parent 09b4fe3 commit 14438de

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
2+
// RUN: %HOST_RUN_PLACEHOLDER %t.out
3+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
4+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
5+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
6+
7+
#include <CL/sycl.hpp>
8+
#include <numeric>
9+
#include <vector>
10+
using namespace cl::sycl;
11+
using namespace cl::sycl::ONEAPI;
12+
13+
int main() {
14+
queue q;
15+
if (q.get_device().is_host()) {
16+
std::cout << "Skipping test\n";
17+
return 0;
18+
}
19+
20+
// Use max work-group size to maximize chance of race
21+
int N = q.get_device().get_info<info::device::max_work_group_size>();
22+
23+
std::vector<int> Input(N), Sum(N), EScan(N), IScan(N);
24+
std::iota(Input.begin(), Input.end(), 0);
25+
std::fill(Sum.begin(), Sum.end(), 0);
26+
std::fill(EScan.begin(), EScan.end(), 0);
27+
std::fill(IScan.begin(), IScan.end(), 0);
28+
29+
{
30+
buffer<int> InputBuf(Input.data(), N);
31+
buffer<int> SumBuf(Sum.data(), N);
32+
buffer<int> EScanBuf(EScan.data(), N);
33+
buffer<int> IScanBuf(IScan.data(), N);
34+
q.submit([&](handler &h) {
35+
auto Input = InputBuf.get_access<access::mode::read>(h);
36+
auto Sum = SumBuf.get_access<access::mode::write>(h);
37+
auto EScan = EScanBuf.get_access<access::mode::write>(h);
38+
auto IScan = IScanBuf.get_access<access::mode::write>(h);
39+
h.parallel_for(nd_range<1>(N, N), [=](nd_item<1> it) {
40+
size_t i = it.get_global_id(0);
41+
auto g = it.get_group();
42+
// Loop to increase number of back-to-back calls
43+
for (int r = 0; r < 10; ++r) {
44+
Sum[i] = reduce(g, Input[i], plus<>());
45+
EScan[i] = exclusive_scan(g, Input[i], plus<>());
46+
IScan[i] = inclusive_scan(g, Input[i], plus<>());
47+
}
48+
});
49+
});
50+
}
51+
52+
int sum = 0;
53+
bool passed = true;
54+
for (int i = 0; i < N; ++i) {
55+
passed &= (sum == EScan[i]);
56+
sum += i;
57+
passed &= (sum == IScan[i]);
58+
}
59+
for (int i = 0; i < N; ++i) {
60+
passed &= (sum == Sum[i]);
61+
}
62+
std::cout << "Test passed." << std::endl;
63+
return 0;
64+
}

0 commit comments

Comments
 (0)