|
| 1 | +// RUN: %{build} %threads_lib -o %t.out |
| 2 | +// RUN: %{run} %t.out |
| 3 | + |
| 4 | +// Check that ext_oneapi_submit_barrier works fine in the scenarios |
| 5 | +// when provided waitlist consists of only empty events. |
| 6 | + |
| 7 | +#include <iostream> |
| 8 | +#include <mutex> |
| 9 | +#include <sycl/sycl.hpp> |
| 10 | +#include <thread> |
| 11 | + |
| 12 | +static constexpr int niter = 1024; |
| 13 | +static constexpr int nthreads = 2; |
| 14 | + |
| 15 | +std::array<std::mutex, nthreads> mutexes; |
| 16 | +std::array<std::optional<sycl::event>, nthreads> events; |
| 17 | + |
| 18 | +void threadFunction(int tid) { |
| 19 | + sycl::device dev; |
| 20 | + std::cout << dev.get_info<sycl::info::device::name>() << std::endl; |
| 21 | + sycl::context ctx{dev}; |
| 22 | + sycl::queue q1{ctx, dev, {sycl::property::queue::in_order()}}; |
| 23 | + sycl::queue q2{ctx, dev, {sycl::property::queue::in_order()}}; |
| 24 | + for (int i = 0; i < niter; i++) { |
| 25 | + sycl::event ev1 = q1.ext_oneapi_submit_barrier(); |
| 26 | + q2.ext_oneapi_submit_barrier({ev1}); |
| 27 | + sycl::event ev2 = q2.ext_oneapi_submit_barrier(); |
| 28 | + q1.ext_oneapi_submit_barrier({ev2}); |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +int main() { |
| 33 | + std::array<std::thread, nthreads> threads; |
| 34 | + |
| 35 | + for (int i = 0; i < nthreads; i++) { |
| 36 | + threads[i] = std::thread{threadFunction, i}; |
| 37 | + } |
| 38 | + |
| 39 | + for (int i = 0; i < nthreads; i++) { |
| 40 | + threads[i].join(); |
| 41 | + } |
| 42 | + std::cout << "All threads have finished." << std::endl; |
| 43 | + |
| 44 | + return 0; |
| 45 | +} |
0 commit comments