|
| 1 | +// Tests enqueueing an eager buffer submission followed by two executions |
| 2 | +// of the same graph which also use the buffer. |
| 3 | + |
| 4 | +#include "../graph_common.hpp" |
| 5 | + |
| 6 | +int main() { |
| 7 | + queue Queue{}; |
| 8 | + |
| 9 | + const size_t N = 10; |
| 10 | + std::vector<int> Arr(N, 0); |
| 11 | + |
| 12 | + buffer<int> Buf{N}; |
| 13 | + Buf.set_write_back(false); |
| 14 | + |
| 15 | + { |
| 16 | + // Buffer elements set to 8 |
| 17 | + Queue.submit([&](handler &CGH) { |
| 18 | + auto Acc = Buf.get_access(CGH); |
| 19 | + CGH.parallel_for(range<1>{N}, [=](id<1> idx) { |
| 20 | + size_t i = idx; |
| 21 | + Acc[i] = 8; |
| 22 | + }); |
| 23 | + }); |
| 24 | + |
| 25 | + // Create graph than adds 2 to buffer elements |
| 26 | + exp_ext::command_graph Graph{ |
| 27 | + Queue.get_context(), |
| 28 | + Queue.get_device(), |
| 29 | + {exp_ext::property::graph::assume_buffer_outlives_graph{}}}; |
| 30 | + |
| 31 | + add_node(Graph, Queue, [&](handler &CGH) { |
| 32 | + auto Acc = Buf.get_access(CGH); |
| 33 | + CGH.parallel_for(range<1>{N}, [=](id<1> idx) { |
| 34 | + size_t i = idx; |
| 35 | + Acc[i] += 2; |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + auto ExecGraph = Graph.finalize(); |
| 40 | + |
| 41 | + // Buffer elements set to 10 |
| 42 | + Queue.ext_oneapi_graph(ExecGraph); |
| 43 | + |
| 44 | + // Buffer elements set to 12 |
| 45 | + Queue.ext_oneapi_graph(ExecGraph); |
| 46 | + |
| 47 | + // Copy results back |
| 48 | + Queue.submit([&](handler &CGH) { |
| 49 | + auto Acc = Buf.get_access(CGH); |
| 50 | + CGH.copy(Acc, Arr.data()); |
| 51 | + }); |
| 52 | + Queue.wait(); |
| 53 | + } |
| 54 | + |
| 55 | + const int Expected = 12; |
| 56 | + for (size_t i = 0; i < N; i++) { |
| 57 | + assert(check_value(i, Expected, Arr[i], "Arr")); |
| 58 | + } |
| 59 | + |
| 60 | + return 0; |
| 61 | +} |
0 commit comments