|
| 1 | +// REQUIRES: aspect-usm_shared_allocations |
| 2 | + |
| 3 | +// RUN: %{build} -o %t.out |
| 4 | +// RUN: %{run} %t.out |
| 5 | +// RUN: %if level_zero %{%{l0_leak_check} %{run} %t.out 2>&1 | FileCheck %s --implicit-check-not=LEAK %} |
| 6 | + |
| 7 | +// Tests that restricted host_task can be recorded via the command-buffer path |
| 8 | + |
| 9 | +#include "../graph_common.hpp" |
| 10 | + |
| 11 | +#include <sycl/ext/oneapi/experimental/enqueue_functions.hpp> |
| 12 | +#include <sycl/properties/all_properties.hpp> |
| 13 | + |
| 14 | +namespace syclex = sycl::ext::oneapi::experimental; |
| 15 | + |
| 16 | +constexpr size_t N = 1024; |
| 17 | + |
| 18 | +int main() { |
| 19 | + queue Queue{property::queue::in_order{}}; |
| 20 | + |
| 21 | + const sycl::context Context = Queue.get_context(); |
| 22 | + const sycl::device Device = Queue.get_device(); |
| 23 | + |
| 24 | + uint32_t *Data = malloc_shared<uint32_t>(N, Queue); |
| 25 | + std::fill(Data, Data + N, 0); |
| 26 | + |
| 27 | + exp_ext::command_graph Graph{Context, Device}; |
| 28 | + |
| 29 | + Graph.begin_recording(Queue); |
| 30 | + |
| 31 | + Queue.submit([&](handler &CGH) { |
| 32 | + CGH.parallel_for(range<1>{N}, [=](id<1> idx) { |
| 33 | + Data[idx] += static_cast<uint32_t>(idx[0]) + 1; |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + syclex::host_task(Queue, [=] { |
| 38 | + for (size_t i = 0; i < N; i++) { |
| 39 | + Data[i] *= 2; |
| 40 | + } |
| 41 | + }); |
| 42 | + |
| 43 | + Queue.submit([&](handler &CGH) { |
| 44 | + CGH.parallel_for(range<1>{N}, [=](id<1> idx) { Data[idx] += 10; }); |
| 45 | + }); |
| 46 | + |
| 47 | + Graph.end_recording(Queue); |
| 48 | + |
| 49 | + auto ExecutableGraph = Graph.finalize(); |
| 50 | + |
| 51 | + Queue.submit([&](handler &CGH) { CGH.ext_oneapi_graph(ExecutableGraph); }); |
| 52 | + Queue.wait(); |
| 53 | + |
| 54 | + for (size_t i = 0; i < N; i++) { |
| 55 | + uint32_t Expected = static_cast<uint32_t>((i + 1) * 2 + 10); |
| 56 | + assert(check_value(i, Expected, Data[i], "Data")); |
| 57 | + } |
| 58 | + |
| 59 | + // Second execution |
| 60 | + Queue.submit([&](handler &CGH) { CGH.ext_oneapi_graph(ExecutableGraph); }); |
| 61 | + Queue.wait(); |
| 62 | + |
| 63 | + for (size_t i = 0; i < N; i++) { |
| 64 | + uint32_t Expected = static_cast<uint32_t>((i + 1) * 6 + 30); |
| 65 | + assert(check_value(i, Expected, Data[i], "Data")); |
| 66 | + } |
| 67 | + |
| 68 | + free(Data, Queue); |
| 69 | + return 0; |
| 70 | +} |
0 commit comments