|
| 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 <sycl.hpp> |
| 11 | +#include <thread> |
| 12 | + |
| 13 | +static void CheckArray(int *x, size_t buffer_size, int expected) { |
| 14 | + for (size_t i = 0; i < buffer_size; ++i) { |
| 15 | + assert(x[i] == expected); |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +using namespace sycl; |
| 20 | + |
| 21 | +void TestFunc(queue &Q) { |
| 22 | + static constexpr int Size = 100; |
| 23 | + |
| 24 | + assert(Q.ext_oneapi_empty() && "Queue is expected to be empty"); |
| 25 | + |
| 26 | + int *X = malloc_host<int>(Size, Q); |
| 27 | + int *Y = malloc_host<int>(Size, Q); |
| 28 | + |
| 29 | + auto FillEv = Q.fill(X, 99, Size); |
| 30 | + auto SingleTaskEv = Q.submit([&](handler &CGH) { |
| 31 | + auto SingleTask = [=] { |
| 32 | + for (int I = 0; I < Size; I++) |
| 33 | + X[I] += 1; |
| 34 | + }; |
| 35 | + CGH.single_task(SingleTask); |
| 36 | + }); |
| 37 | + auto MemCpyEv = Q.copy(X, Y, Size); |
| 38 | + constexpr int NumIter = 5; |
| 39 | + for (int I = 0; I < NumIter; I++) { |
| 40 | + Q.submit([&](handler &CGH) { |
| 41 | + CGH.parallel_for<class Kernel1>(sycl::range<1>(Size), |
| 42 | + [=](sycl::id<1> WI) { Y[WI] *= 2; }); |
| 43 | + }); |
| 44 | + } |
| 45 | + |
| 46 | + // Wait a bit to give a chance for tasks to complete. |
| 47 | + std::this_thread::sleep_for(std::chrono::milliseconds(500)); |
| 48 | + |
| 49 | + // We expect that all submitted tasks are finished if ext_oneapi_empty is |
| 50 | + // true. |
| 51 | + if (Q.ext_oneapi_empty()) |
| 52 | + CheckArray(Y, Size, 3200); |
| 53 | + |
| 54 | + Q.wait(); |
| 55 | + |
| 56 | + // After synchronization queue must be empty. |
| 57 | + assert(Q.ext_oneapi_empty() && "Queue is expected to be empty"); |
| 58 | + |
| 59 | + free(X, Q); |
| 60 | + free(Y, Q); |
| 61 | +} |
| 62 | + |
| 63 | +int main() { |
| 64 | + // Test in-order queue. |
| 65 | + queue Q1{property::queue::in_order()}; |
| 66 | + TestFunc(Q1); |
| 67 | + |
| 68 | + // Test in-order queue with discard_events property. |
| 69 | + sycl::property_list Props{ |
| 70 | + property::queue::in_order{}, |
| 71 | + sycl::ext::oneapi::property::queue::discard_events{}}; |
| 72 | + queue Q2{Props}; |
| 73 | + |
| 74 | + bool ExceptionThrown = false; |
| 75 | + try { |
| 76 | + TestFunc(Q2); |
| 77 | + } catch (sycl::exception &E) { |
| 78 | + ExceptionThrown = true; |
| 79 | + } |
| 80 | + |
| 81 | + // Feature is not supported for OpenCL, exception must be thrown. |
| 82 | + if (Q2.get_device().get_backend() == backend::opencl) |
| 83 | + return ExceptionThrown ? 0 : -1; |
| 84 | + |
| 85 | + return 0; |
| 86 | +} |
0 commit comments