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

Commit a2bb528

Browse files
committed
[SYCL] Test queue::ext_oneapi_empty() API
1 parent 787e3c8 commit a2bb528

File tree

2 files changed

+162
-0
lines changed

2 files changed

+162
-0
lines changed

SYCL/Basic/in_order_queue_status.cpp

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
3+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
4+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
5+
6+
// Test checks that queue::ext_oneapi_empty() returns status of the in-order
7+
// queue.
8+
9+
#include <chrono>
10+
#include <iostream>
11+
#include <sycl.hpp>
12+
#include <thread>
13+
14+
static void CheckArray(int *x, size_t buffer_size, int expected) {
15+
for (size_t i = 0; i < buffer_size; ++i) {
16+
assert(x[i] == expected);
17+
}
18+
}
19+
20+
using namespace sycl;
21+
22+
void TestFunc(queue &Q) {
23+
static constexpr int Size = 100;
24+
25+
assert(Q.ext_oneapi_empty() && "Queue is expected to be empty");
26+
27+
int *X = malloc_host<int>(Size, Q);
28+
int *Y = malloc_host<int>(Size, Q);
29+
30+
auto FillEv = Q.fill(X, 99, Size);
31+
auto SingleTaskEv = Q.submit([&](handler &CGH) {
32+
auto SingleTask = [=] {
33+
for (int I = 0; I < Size; I++)
34+
X[I] += 1;
35+
};
36+
CGH.single_task(SingleTask);
37+
});
38+
auto MemCpyEv = Q.copy(X, Y, Size);
39+
constexpr int NumIter = 5;
40+
for (int I = 0; I < NumIter; I++) {
41+
Q.submit([&](handler &CGH) {
42+
CGH.parallel_for<class Kernel1>(sycl::range<1>(Size),
43+
[=](sycl::id<1> WI) { Y[WI] *= 2; });
44+
});
45+
}
46+
47+
// Wait a bit to give a chance for tasks to complete.
48+
std::this_thread::sleep_for(std::chrono::milliseconds(500));
49+
50+
// We expect that all submitted tasks are finished if ext_oneapi_empty is
51+
// true.
52+
if (Q.ext_oneapi_empty())
53+
CheckArray(Y, Size, 3200);
54+
55+
Q.wait();
56+
57+
// After synchronization queue must be empty.
58+
assert(Q.ext_oneapi_empty() && "Queue is expected to be empty");
59+
60+
free(X, Q);
61+
free(Y, Q);
62+
}
63+
64+
int main() {
65+
// Test in-order queue.
66+
queue Q1{property::queue::in_order()};
67+
TestFunc(Q1);
68+
69+
// Test in-order queue with discard_events property.
70+
sycl::property_list Props{
71+
property::queue::in_order{},
72+
sycl::ext::oneapi::property::queue::discard_events{}};
73+
queue Q2{Props};
74+
try {
75+
TestFunc(Q2);
76+
77+
} catch (sycl::exception &E) {
78+
std::cout << E.what() << std::endl;
79+
// Feature is not supported for OpenCL.
80+
assert(Q2.get_device().get_backend() == backend::opencl);
81+
}
82+
83+
return 0;
84+
}
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
3+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
4+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
5+
6+
// Test checks that queue::ext_oneapi_empty() returns status of the out-of-order
7+
// queue.
8+
9+
#include <chrono>
10+
#include <iostream>
11+
#include <sycl.hpp>
12+
#include <thread>
13+
14+
static void CheckArray(int *x, size_t buffer_size, int expected) {
15+
for (size_t i = 0; i < buffer_size; ++i) {
16+
assert(x[i] == expected);
17+
}
18+
}
19+
20+
using namespace sycl;
21+
22+
void TestFunc(queue &Q) {
23+
static constexpr int Size = 100;
24+
25+
assert(Q.ext_oneapi_empty() && "Queue is expected to be empty");
26+
27+
int *X = malloc_host<int>(Size, Q);
28+
int *Y = malloc_host<int>(Size, Q);
29+
30+
auto FillEv = Q.fill(X, 99, Size);
31+
auto HostEv = Q.submit([&](handler &CGH) {
32+
CGH.depends_on(FillEv);
33+
auto HostTask = [=] {
34+
for (int I = 0; I < Size; I++)
35+
X[I] += 1;
36+
};
37+
CGH.host_task(HostTask);
38+
});
39+
auto MemCpyEv = Q.copy(X, Y, Size, {HostEv});
40+
constexpr int NumIter = 5;
41+
for (int I = 0; I < NumIter; I++) {
42+
Q.submit([&](handler &CGH) {
43+
CGH.depends_on(MemCpyEv);
44+
CGH.parallel_for<class Kernel1>(
45+
sycl::range<1>(Size / NumIter),
46+
[=](sycl::id<1> WI) { Y[WI + I * Size / NumIter] *= 2; });
47+
});
48+
}
49+
50+
// Wait a bit to give a chance for tasks to complete.
51+
std::this_thread::sleep_for(std::chrono::milliseconds(500));
52+
53+
// We expect that all submitted tasks are finished if ext_oneapi_empty is
54+
// true.
55+
if (Q.ext_oneapi_empty())
56+
CheckArray(Y, Size, 200);
57+
58+
Q.wait();
59+
60+
// After synchronization queue must be empty.
61+
assert(Q.ext_oneapi_empty() && "Queue is expected to be empty");
62+
63+
free(X, Q);
64+
free(Y, Q);
65+
}
66+
67+
int main() {
68+
queue Q;
69+
70+
try {
71+
TestFunc(Q);
72+
} catch (sycl::exception &E) {
73+
std::cout << E.what() << std::endl;
74+
// Feature is not supported for OpenCL.
75+
assert(Q.get_device().get_backend() == backend::opencl);
76+
}
77+
return 0;
78+
}

0 commit comments

Comments
 (0)