Skip to content

Commit

Permalink
[SYCL][Graph] Bugfix buffer_ordering: make buffers outlives graph (in…
Browse files Browse the repository at this point in the history
…tel#11380) (#332)

`buffer_ordering.cpp` did not meet the Graph specification. Buffers must
outlive the Graph that uses them.
The buffer-ordering test has been updated to fulfill this property.
  • Loading branch information
mfrancepillois committed Oct 6, 2023
1 parent 752168a commit 95317f1
Showing 1 changed file with 62 additions and 60 deletions.
122 changes: 62 additions & 60 deletions sycl/test-e2e/Graph/Inputs/buffer_ordering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,84 +15,86 @@ int main() {

queue Queue{{sycl::ext::intel::property::queue::no_immediate_command_list{}}};

exp_ext::command_graph Graph{
Queue.get_context(),
Queue.get_device(),
{exp_ext::property::graph::assume_buffer_outlives_graph{}}};

const size_t N = 10;
std::vector<int> Arr(N, 0);

buffer<int> Buf{N};
Buf.set_write_back(false);

// Buffer elements set to 3
Queue.submit([&](handler &CGH) {
auto Acc = Buf.get_access(CGH);
CGH.parallel_for(range<1>{N}, [=](id<1> idx) {
size_t i = idx;
Acc[i] = 3;
{
exp_ext::command_graph Graph{
Queue.get_context(),
Queue.get_device(),
{exp_ext::property::graph::assume_buffer_outlives_graph{}}};

// Buffer elements set to 3
Queue.submit([&](handler &CGH) {
auto Acc = Buf.get_access(CGH);
CGH.parallel_for(range<1>{N}, [=](id<1> idx) {
size_t i = idx;
Acc[i] = 3;
});
});
});

add_node(Graph, Queue, [&](handler &CGH) {
auto Acc = Buf.get_access(CGH);
CGH.parallel_for(range<1>{N}, [=](id<1> idx) {
size_t i = idx;
Acc[i] += 2;
add_node(Graph, Queue, [&](handler &CGH) {
auto Acc = Buf.get_access(CGH);
CGH.parallel_for(range<1>{N}, [=](id<1> idx) {
size_t i = idx;
Acc[i] += 2;
});
});
});

for (size_t i = 0; i < N; i++) {
assert(Arr[i] == 0);
}

// Buffer elements set to 4
Queue.submit([&](handler &CGH) {
auto Acc = Buf.get_access(CGH);
CGH.parallel_for(range<1>{N}, [=](id<1> idx) {
size_t i = idx;
Acc[i] += 1;
for (size_t i = 0; i < N; i++) {
assert(Arr[i] == 0);
}

// Buffer elements set to 4
Queue.submit([&](handler &CGH) {
auto Acc = Buf.get_access(CGH);
CGH.parallel_for(range<1>{N}, [=](id<1> idx) {
size_t i = idx;
Acc[i] += 1;
});
});
});

auto ExecGraph = Graph.finalize();
auto ExecGraph = Graph.finalize();

for (size_t i = 0; i < N; i++) {
assert(Arr[i] == 0);
}
for (size_t i = 0; i < N; i++) {
assert(Arr[i] == 0);
}

// Buffer elements set to 8
Queue.submit([&](handler &CGH) {
auto Acc = Buf.get_access(CGH);
CGH.parallel_for(range<1>{N}, [=](id<1> idx) {
size_t i = idx;
Acc[i] *= 2;
// Buffer elements set to 8
Queue.submit([&](handler &CGH) {
auto Acc = Buf.get_access(CGH);
CGH.parallel_for(range<1>{N}, [=](id<1> idx) {
size_t i = idx;
Acc[i] *= 2;
});
});
});

// Buffer elements set to 10
auto Event =
Queue.submit([&](handler &CGH) { CGH.ext_oneapi_graph(ExecGraph); });

// Buffer elements set to 20
Queue.submit([&](handler &CGH) {
auto Acc = Buf.get_access(CGH);
CGH.parallel_for(range<1>{N}, [=](id<1> idx) {
size_t i = idx;
Acc[i] *= 2;

// Buffer elements set to 10
auto Event =
Queue.submit([&](handler &CGH) { CGH.ext_oneapi_graph(ExecGraph); });

// Buffer elements set to 20
Queue.submit([&](handler &CGH) {
auto Acc = Buf.get_access(CGH);
CGH.parallel_for(range<1>{N}, [=](id<1> idx) {
size_t i = idx;
Acc[i] *= 2;
});
});
});

Event.wait();
// Buffer elements set to 22
Queue.submit([&](handler &CGH) { CGH.ext_oneapi_graph(ExecGraph); });
Event.wait();
// Buffer elements set to 22
Queue.submit([&](handler &CGH) { CGH.ext_oneapi_graph(ExecGraph); });

Queue.submit([&](handler &CGH) {
auto Acc = Buf.get_access(CGH);
CGH.copy(Acc, Arr.data());
});
Queue.wait();
Queue.submit([&](handler &CGH) {
auto Acc = Buf.get_access(CGH);
CGH.copy(Acc, Arr.data());
});
Queue.wait();
}

for (size_t i = 0; i < N; i++) {
assert(Arr[i] == 22);
Expand Down

0 comments on commit 95317f1

Please sign in to comment.