|
| 1 | +// RUN: %{build} -o %t.out %cxx_std_optionc++20 |
| 2 | +// RUN: %{run} %t.out |
| 3 | + |
| 4 | +#include <sycl/detail/core.hpp> |
| 5 | +#include <sycl/usm.hpp> |
| 6 | + |
| 7 | +#include <latch> |
| 8 | +#include <thread> |
| 9 | + |
| 10 | +using namespace sycl; |
| 11 | + |
| 12 | +void test_host_task_dep() { |
| 13 | + queue q; |
| 14 | + |
| 15 | + std::latch start_execution{1}; |
| 16 | + |
| 17 | + int x = 0; |
| 18 | + |
| 19 | + auto host_event = q.submit([&](handler &cgh) { |
| 20 | + cgh.host_task([&]() { |
| 21 | + start_execution.wait(); |
| 22 | + x = 42; |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + auto empty_cg_event = |
| 27 | + q.submit([&](handler &cgh) { cgh.depends_on(host_event); }); |
| 28 | + |
| 29 | + // FIXME: This should deadlock, but the dependency is ignored currently. |
| 30 | + empty_cg_event.wait(); |
| 31 | + |
| 32 | + assert(x == 0); |
| 33 | + start_execution.count_down(); |
| 34 | + |
| 35 | + empty_cg_event.wait(); |
| 36 | + // FIXME: uncomment once the bug mentioned above is fixed. |
| 37 | + // assert(x == 42); |
| 38 | + |
| 39 | + // I'm seeing some weird hang without this: |
| 40 | + host_event.wait(); |
| 41 | +} |
| 42 | + |
| 43 | +void test_device_event_dep() { |
| 44 | + queue q; |
| 45 | + |
| 46 | + std::latch start_execution{1}; |
| 47 | + auto *p = sycl::malloc_shared<int>(1, q); |
| 48 | + *p = 0; |
| 49 | + |
| 50 | + auto host_event = q.submit( |
| 51 | + [&](handler &cgh) { cgh.host_task([&]() { start_execution.wait(); }); }); |
| 52 | + auto device_event = q.single_task(host_event, [=]() { *p = 42; }); |
| 53 | + auto empty_cg_event = |
| 54 | + q.submit([&](handler &cgh) { cgh.depends_on(device_event); }); |
| 55 | + |
| 56 | + // FIXME: This should deadlock, but the dependency is ignored currently. |
| 57 | + empty_cg_event.wait(); |
| 58 | + |
| 59 | + assert(*p == 0); |
| 60 | + start_execution.count_down(); |
| 61 | + |
| 62 | + empty_cg_event.wait(); |
| 63 | + // FIXME: uncomment once the bug mentioned above is fixed. |
| 64 | + // assert(*p == 42); |
| 65 | + |
| 66 | + q.wait(); |
| 67 | + sycl::free(p, q); |
| 68 | +} |
| 69 | + |
| 70 | +void test_accessor_dep() { |
| 71 | + queue q; |
| 72 | + |
| 73 | + std::latch start_execution{1}; |
| 74 | + auto *p = sycl::malloc_shared<int>(1, q); |
| 75 | + *p = 0; |
| 76 | + |
| 77 | + auto host_event = q.submit( |
| 78 | + [&](handler &cgh) { cgh.host_task([&]() { start_execution.wait(); }); }); |
| 79 | + |
| 80 | + sycl::buffer<int, 1> b{1}; |
| 81 | + auto device_event = q.submit([&](auto &cgh) { |
| 82 | + cgh.depends_on(host_event); |
| 83 | + sycl::accessor a{b, cgh}; |
| 84 | + |
| 85 | + cgh.single_task([=]() { |
| 86 | + *p = 42; |
| 87 | + a[0] = 42; |
| 88 | + }); |
| 89 | + }); |
| 90 | + auto empty_cg_event = |
| 91 | + q.submit([&](handler &cgh) { sycl::accessor a{b, cgh}; }); |
| 92 | + |
| 93 | + // FIXME: This should deadlock, but the dependency is ignored currently. |
| 94 | + empty_cg_event.wait(); |
| 95 | + |
| 96 | + assert(*p == 0); |
| 97 | + start_execution.count_down(); |
| 98 | + |
| 99 | + empty_cg_event.wait(); |
| 100 | + // FIXME: uncomment once the bug mentioned above is fixed. |
| 101 | + // assert(*p == 42); |
| 102 | + |
| 103 | + q.wait(); |
| 104 | + sycl::free(p, q); |
| 105 | +} |
| 106 | + |
| 107 | +int main() { |
| 108 | + test_host_task_dep(); |
| 109 | + test_device_event_dep(); |
| 110 | + test_accessor_dep(); |
| 111 | + return 0; |
| 112 | +} |
0 commit comments