Skip to content

Commit 385be5b

Browse files
committed
[SYCL][test-e2e <latch> is a C++20 header
<latch> requires c++20 support in the standard library which is not a guarantee on all implementations. Fake latch support for the empty_command test with a simple atomic int wrapper. It's rough but doesn't need to support all generality of the standard version
1 parent 19c371e commit 385be5b

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

sycl/test-e2e/Basic/empty_command.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
1-
// RUN: %{build} -o %t.out %cxx_std_optionc++20
1+
// RUN: %{build} -o %t.out
22
// RUN: %{run} %t.out
33

44
#include <sycl/detail/core.hpp>
55
#include <sycl/usm.hpp>
66

7-
#include <latch>
87
#include <thread>
98

109
using namespace sycl;
1110

11+
// std::latch is not available until c++20
12+
class simple_latch {
13+
std::atomic<unsigned> counter;
14+
15+
public:
16+
simple_latch(unsigned init) : counter(init) {}
17+
18+
void wait() {
19+
// block until the counter reaches zero;
20+
while (counter)
21+
std::this_thread::yield();
22+
}
23+
void count_down(unsigned by = 1) { counter.fetch_sub(by); }
24+
};
25+
1226
void test_host_task_dep() {
1327
queue q;
1428

15-
std::latch start_execution{1};
29+
simple_latch start_execution{1};
1630

1731
int x = 0;
1832

@@ -36,7 +50,7 @@ void test_host_task_dep() {
3650
void test_device_event_dep() {
3751
queue q;
3852

39-
std::latch start_execution{1};
53+
simple_latch start_execution{1};
4054
auto *p = sycl::malloc_shared<int>(1, q);
4155
*p = 0;
4256

@@ -58,7 +72,7 @@ void test_device_event_dep() {
5872
void test_accessor_dep() {
5973
queue q;
6074

61-
std::latch start_execution{1};
75+
simple_latch start_execution{1};
6276
auto *p = sycl::malloc_shared<int>(1, q);
6377
*p = 0;
6478

0 commit comments

Comments
 (0)