|
| 1 | +// REQUIRES: level_zero, gpu |
| 2 | +// RUN: %{build} -o %t.out |
| 3 | +// RUN: %{run} %t.out |
| 4 | + |
| 5 | +// Tests that calling handler::depends_on() for events not part of the graph |
| 6 | +// throws. |
| 7 | + |
| 8 | +#include "graph_common.hpp" |
| 9 | + |
| 10 | +int main() { |
| 11 | + queue Queue; |
| 12 | + |
| 13 | + ext::oneapi::experimental::command_graph Graph{Queue.get_context(), |
| 14 | + Queue.get_device()}; |
| 15 | + ext::oneapi::experimental::command_graph Graph2{Queue.get_context(), |
| 16 | + Queue.get_device()}; |
| 17 | + |
| 18 | + auto NormalEvent = Queue.submit( |
| 19 | + [&](handler &CGH) { CGH.single_task<class TestKernel1>([=]() {}); }); |
| 20 | + |
| 21 | + Graph2.begin_recording(Queue); |
| 22 | + |
| 23 | + auto OtherGraphEvent = Queue.submit( |
| 24 | + [&](handler &CGH) { CGH.single_task<class TestKernel2>([=]() {}); }); |
| 25 | + |
| 26 | + Graph2.end_recording(Queue); |
| 27 | + |
| 28 | + Graph.begin_recording(Queue); |
| 29 | + |
| 30 | + // Test that depends_on in explicit and record and replay throws from an event |
| 31 | + // outside any graph. |
| 32 | + |
| 33 | + std::error_code ErrorCode = make_error_code(sycl::errc::success); |
| 34 | + try { |
| 35 | + auto GraphEvent = Queue.submit([&](handler &CGH) { |
| 36 | + CGH.depends_on(NormalEvent); |
| 37 | + CGH.single_task<class TestKernel3>([=]() {}); |
| 38 | + }); |
| 39 | + } catch (const sycl::exception &e) { |
| 40 | + ErrorCode = e.code(); |
| 41 | + } |
| 42 | + assert(ErrorCode == sycl::errc::invalid); |
| 43 | + |
| 44 | + ErrorCode = make_error_code(sycl::errc::success); |
| 45 | + try { |
| 46 | + Graph.add([&](handler &CGH) { |
| 47 | + CGH.depends_on(NormalEvent); |
| 48 | + CGH.single_task<class TestKernel4>([=]() {}); |
| 49 | + }); |
| 50 | + } catch (const sycl::exception &e) { |
| 51 | + ErrorCode = e.code(); |
| 52 | + } |
| 53 | + assert(ErrorCode == sycl::errc::invalid); |
| 54 | + |
| 55 | + // Test that depends_on throws from an event from another graph. |
| 56 | + ErrorCode = make_error_code(sycl::errc::success); |
| 57 | + try { |
| 58 | + auto GraphEvent = Queue.submit([&](handler &CGH) { |
| 59 | + CGH.depends_on(OtherGraphEvent); |
| 60 | + CGH.single_task<class TestKernel5>([=]() {}); |
| 61 | + }); |
| 62 | + } catch (const sycl::exception &e) { |
| 63 | + ErrorCode = e.code(); |
| 64 | + } |
| 65 | + assert(ErrorCode == sycl::errc::invalid); |
| 66 | + |
| 67 | + ErrorCode = make_error_code(sycl::errc::success); |
| 68 | + try { |
| 69 | + Graph.add([&](handler &CGH) { |
| 70 | + CGH.depends_on(OtherGraphEvent); |
| 71 | + CGH.single_task<class TestKernel6>([=]() {}); |
| 72 | + }); |
| 73 | + } catch (const sycl::exception &e) { |
| 74 | + ErrorCode = e.code(); |
| 75 | + } |
| 76 | + assert(ErrorCode == sycl::errc::invalid); |
| 77 | + |
| 78 | + return 0; |
| 79 | +} |
0 commit comments