Skip to content

Commit

Permalink
[SYCL][Graph] Create handler::depends_on edges in Explicit API
Browse files Browse the repository at this point in the history
An event returned from a queue submission captured by
Record & Replay should be able to create an edge to
a node created by the Explicit API.

This edge is defined by passing the event to
`handler::depends_on` inside the command-group added
explicitly to the graph.

Closes #89
  • Loading branch information
EwanC committed May 15, 2023
1 parent 94d9684 commit 7da187a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sycl/source/detail/graph_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ graph_impl::add(const std::shared_ptr<graph_impl> &Impl,
if (Handler.MSubgraphNode) {
return Handler.MSubgraphNode;
}
// TODO: Do we need to pass event dependencies here for the explicit API?

return this->add(Handler.MKernel, Handler.MNDRDesc, Handler.MOSModuleHandle,
Handler.MKernelName, Handler.MAccStorage,
Handler.MLocalAccStorage, Handler.MCGType, Handler.MArgs,
Handler.MImpl->MAuxiliaryResources, Dep);
Handler.MImpl->MAuxiliaryResources, Dep, Handler.MEvents);
}

std::shared_ptr<node_impl> graph_impl::add(
Expand Down
45 changes: 45 additions & 0 deletions sycl/test-e2e/Graph/Explicit/depends_on.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// REQUIRES: level_zero, gpu
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out

// Tests that an event returned from adding a graph node using the queue
// recording API can be passed to `handler::depends_on` inside a node
// added using the explicit API. This should create a graph edge.

#include "../graph_common.hpp"

int main() {

queue Queue{gpu_selector_v};

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

const size_t N = 10;
float *Arr = malloc_device<float>(N, Queue);

Graph.begin_recording(Queue);
// `Event` corresponds to a graph node
event Event = Queue.submit([&](handler &CGH) {
CGH.parallel_for(range<1>{N}, [=](id<1> idx) { Arr[idx] = 42.0f; });
});
Graph.end_recording(Queue);

Graph.add([&](handler &CGH) {
CGH.depends_on(Event); // creates edge to recorded graph node
CGH.parallel_for(range<1>{N}, [=](id<1> idx) { Arr[idx] *= 2.0f; });
});

auto ExecGraph = Graph.finalize();

Queue.submit([&](handler &CGH) { CGH.ext_oneapi_graph(ExecGraph); }).wait();

constexpr float ref = 42.0f * 2.0f;
std::vector<float> Output(N);
Queue.memcpy(Output.data(), Arr, N * sizeof(float)).wait();
for (int i = 0; i < N; i++)
assert(Output[i] == ref);

sycl::free(Arr, Queue);

return 0;
}

0 comments on commit 7da187a

Please sign in to comment.