forked from intel/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandCleanupThreadSafety.cpp
More file actions
38 lines (31 loc) · 974 Bytes
/
CommandCleanupThreadSafety.cpp
File metadata and controls
38 lines (31 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// RUN: %clangxx -fsycl %s -o %t.out -lpthread
// RUN: %CPU_RUN_PLACEHOLDER %t.out
#include <CL/sycl.hpp>
#include <cassert>
#include <cstddef>
#include <thread>
#include <vector>
// This test checks that the command graph cleanup works properly when
// invoked from multiple threads.
using namespace cl::sycl;
class Foo;
event submitTask(queue &Q, buffer<int, 1> &Buf) {
return Q.submit([&](handler &Cgh) {
auto Acc = Buf.get_access<access::mode::read_write>(Cgh);
Cgh.single_task<Foo>([=]() { Acc[0] = 42; });
});
}
int main() {
queue Q;
buffer<int, 1> Buf(range<1>(1));
// Create multiple commands, each one dependent on the previous
std::vector<event> Events;
for (std::size_t I = 0; I < 16; ++I)
Events.push_back(submitTask(Q, Buf));
// Initiate cleanup from multiple threads
std::vector<std::thread> Threads;
for (event &E : Events)
Threads.emplace_back([&]() { E.wait(); });
for (std::thread &T : Threads)
T.join();
}