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

Commit 7f2a22e

Browse files
authored
[SYCL][HIP] Improve test for barrier and enable it for HIP (#1122)
Improves the test for barrier to make it actually fail if the barrier implementation does not work. Tests intel/llvm#6490
1 parent f6dffae commit 7f2a22e

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

SYCL/Basic/barrier_order.cpp

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// UNSUPPORTED: hip
21
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
32
// RUN: %CPU_RUN_PLACEHOLDER %t.out
43
// RUN: %GPU_RUN_PLACEHOLDER %t.out
@@ -11,28 +10,57 @@ int main() {
1110
sycl::device dev{sycl::default_selector_v};
1211
sycl::queue q{dev};
1312

14-
int *x = sycl::malloc_shared<int>(1, q);
15-
int *y = sycl::malloc_shared<int>(1, q);
13+
unsigned long long *x = sycl::malloc_shared<unsigned long long>(1, q);
14+
15+
int error = 0;
16+
17+
// test barrier without arguments
1618
*x = 0;
17-
*y = 0;
19+
for (int i = 0; i < 64; i++) {
20+
q.single_task([=]() {
21+
// do some busywork
22+
volatile float y = *x;
23+
for (int j = 0; j < 100; j++) {
24+
y = sycl::cos(y);
25+
}
26+
// update the value
27+
*x *= 2;
28+
});
29+
q.ext_oneapi_submit_barrier();
30+
q.single_task([=]() { *x += 1; });
31+
q.ext_oneapi_submit_barrier();
32+
}
1833

19-
q.single_task<class kernel1>([=] { *x = 1; });
34+
std::cout << std::bitset<8 * sizeof(unsigned long long)>(*x) << std::endl;
2035

21-
q.ext_oneapi_submit_barrier();
36+
q.wait_and_throw();
37+
error |= (*x != (unsigned long long)-1);
2238

23-
q.single_task<class kernel2>([=] {
24-
if (*x == 1) {
25-
*y = 2;
26-
}
27-
});
39+
// test barrier when events are passed arguments
40+
*x = 0;
41+
for (int i = 0; i < 64; i++) {
42+
sycl::event e = q.single_task([=]() {
43+
// do some busywork
44+
volatile float y = *x;
45+
for (int j = 0; j < 100; j++) {
46+
y = sycl::cos(y);
47+
}
48+
// update the value
49+
*x *= 2;
50+
});
51+
q.ext_oneapi_submit_barrier({e});
52+
e = q.single_task([=]() { *x += 1; });
53+
q.ext_oneapi_submit_barrier({e});
54+
}
2855

2956
q.wait_and_throw();
57+
error |= (*x != (unsigned long long)-1);
58+
59+
std::cout << std::bitset<8 * sizeof(unsigned long long)>(*x) << std::endl;
3060

31-
int error = (*x != 1 || *y != 2) ? 1 : 0;
3261
std::cout << (error ? "failed\n" : "passed\n");
3362

3463
sycl::free(x, q);
35-
sycl::free(y, q);
3664

3765
return error;
3866
}

0 commit comments

Comments
 (0)