Skip to content

Commit 30215eb

Browse files
authored
[SYCL] Graph recording support for handler-less kernel submission path (#20250)
This is a folllow-up PR to [#19294](#19294)
1 parent f1ebef0 commit 30215eb

File tree

4 files changed

+68
-51
lines changed

4 files changed

+68
-51
lines changed

sycl/source/detail/queue_impl.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,61 @@ queue_impl::submit_impl(const detail::type_erased_cgfo_ty &CGF,
420420
return EventImpl;
421421
}
422422

423+
EventImplPtr queue_impl::submit_command_to_graph(
424+
ext::oneapi::experimental::detail::graph_impl &GraphImpl,
425+
std::unique_ptr<detail::CG> CommandGroup, sycl::detail::CGType CGType,
426+
sycl::ext::oneapi::experimental::node_type UserFacingNodeType) {
427+
auto EventImpl = detail::event_impl::create_completed_host_event();
428+
EventImpl->setSubmittedQueue(weak_from_this());
429+
ext::oneapi::experimental::detail::node_impl *NodeImpl = nullptr;
430+
431+
// GraphImpl is read and written in this scope so we lock this graph
432+
// with full priviledges.
433+
ext::oneapi::experimental::detail::graph_impl::WriteLock Lock(
434+
GraphImpl.MMutex);
435+
436+
ext::oneapi::experimental::node_type NodeType =
437+
UserFacingNodeType != ext::oneapi::experimental::node_type::empty
438+
? UserFacingNodeType
439+
: ext::oneapi::experimental::detail::getNodeTypeFromCG(CGType);
440+
441+
// Create a new node in the graph representing this command-group
442+
if (isInOrder()) {
443+
// In-order queues create implicit linear dependencies between nodes.
444+
// Find the last node added to the graph from this queue, so our new
445+
// node can set it as a predecessor.
446+
std::vector<ext::oneapi::experimental::detail::node_impl *> Deps;
447+
if (ext::oneapi::experimental::detail::node_impl *DependentNode =
448+
GraphImpl.getLastInorderNode(this)) {
449+
Deps.push_back(DependentNode);
450+
}
451+
NodeImpl = &GraphImpl.add(NodeType, std::move(CommandGroup), Deps);
452+
453+
// If we are recording an in-order queue remember the new node, so it
454+
// can be used as a dependency for any more nodes recorded from this
455+
// queue.
456+
GraphImpl.setLastInorderNode(*this, *NodeImpl);
457+
} else {
458+
ext::oneapi::experimental::detail::node_impl *LastBarrierRecordedFromQueue =
459+
GraphImpl.getBarrierDep(weak_from_this());
460+
std::vector<ext::oneapi::experimental::detail::node_impl *> Deps;
461+
462+
if (LastBarrierRecordedFromQueue) {
463+
Deps.push_back(LastBarrierRecordedFromQueue);
464+
}
465+
NodeImpl = &GraphImpl.add(NodeType, std::move(CommandGroup), Deps);
466+
467+
if (NodeImpl->MCGType == sycl::detail::CGType::Barrier) {
468+
GraphImpl.setBarrierDep(weak_from_this(), *NodeImpl);
469+
}
470+
}
471+
472+
// Associate an event with this new node and return the event.
473+
GraphImpl.addEventForNode(EventImpl, *NodeImpl);
474+
475+
return EventImpl;
476+
}
477+
423478
detail::EventImplPtr queue_impl::submit_kernel_direct_impl(
424479
const NDRDescT &NDRDesc, detail::HostKernelRefBase &HostKernel,
425480
detail::DeviceKernelInfo *DeviceKernelInfo, bool CallerNeedsEvent,
@@ -456,6 +511,11 @@ detail::EventImplPtr queue_impl::submit_kernel_direct_impl(
456511
CodeLoc));
457512
CommandGroup->MIsTopCodeLoc = IsTopCodeLoc;
458513

514+
if (auto GraphImpl = getCommandGraph(); GraphImpl) {
515+
return submit_command_to_graph(*GraphImpl, std::move(CommandGroup),
516+
detail::CGType::Kernel);
517+
}
518+
459519
return detail::Scheduler::getInstance().addCG(std::move(CommandGroup),
460520
*this, true);
461521
};

sycl/source/detail/queue_impl.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,12 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
624624

625625
bool hasCommandGraph() const { return !MGraph.expired(); }
626626

627+
EventImplPtr submit_command_to_graph(
628+
ext::oneapi::experimental::detail::graph_impl &GraphImpl,
629+
std::unique_ptr<detail::CG> CommandGroup, sycl::detail::CGType CGType,
630+
sycl::ext::oneapi::experimental::node_type UserFacingNodeType =
631+
ext::oneapi::experimental::node_type::empty);
632+
627633
unsigned long long getQueueID() { return MQueueID; }
628634

629635
void *getTraceEvent() { return MTraceEvent; }

sycl/source/handler.cpp

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -955,54 +955,8 @@ event handler::finalize() {
955955
// If the queue has an associated graph then we need to take the CG and pass
956956
// it to the graph to create a node, rather than submit it to the scheduler.
957957
if (auto GraphImpl = Queue->getCommandGraph(); GraphImpl) {
958-
auto EventImpl = detail::event_impl::create_completed_host_event();
959-
EventImpl->setSubmittedQueue(Queue->weak_from_this());
960-
ext::oneapi::experimental::detail::node_impl *NodeImpl = nullptr;
961-
962-
// GraphImpl is read and written in this scope so we lock this graph
963-
// with full priviledges.
964-
ext::oneapi::experimental::detail::graph_impl::WriteLock Lock(
965-
GraphImpl->MMutex);
966-
967-
ext::oneapi::experimental::node_type NodeType =
968-
impl->MUserFacingNodeType != ext::oneapi::experimental::node_type::empty
969-
? impl->MUserFacingNodeType
970-
: ext::oneapi::experimental::detail::getNodeTypeFromCG(getType());
971-
972-
// Create a new node in the graph representing this command-group
973-
if (Queue->isInOrder()) {
974-
// In-order queues create implicit linear dependencies between nodes.
975-
// Find the last node added to the graph from this queue, so our new
976-
// node can set it as a predecessor.
977-
std::vector<ext::oneapi::experimental::detail::node_impl *> Deps;
978-
if (ext::oneapi::experimental::detail::node_impl *DependentNode =
979-
GraphImpl->getLastInorderNode(Queue)) {
980-
Deps.push_back(DependentNode);
981-
}
982-
NodeImpl = &GraphImpl->add(NodeType, std::move(CommandGroup), Deps);
983-
984-
// If we are recording an in-order queue remember the new node, so it
985-
// can be used as a dependency for any more nodes recorded from this
986-
// queue.
987-
GraphImpl->setLastInorderNode(*Queue, *NodeImpl);
988-
} else {
989-
ext::oneapi::experimental::detail::node_impl
990-
*LastBarrierRecordedFromQueue =
991-
GraphImpl->getBarrierDep(Queue->weak_from_this());
992-
std::vector<ext::oneapi::experimental::detail::node_impl *> Deps;
993-
994-
if (LastBarrierRecordedFromQueue) {
995-
Deps.push_back(LastBarrierRecordedFromQueue);
996-
}
997-
NodeImpl = &GraphImpl->add(NodeType, std::move(CommandGroup), Deps);
998-
999-
if (NodeImpl->MCGType == sycl::detail::CGType::Barrier) {
1000-
GraphImpl->setBarrierDep(Queue->weak_from_this(), *NodeImpl);
1001-
}
1002-
}
1003-
1004-
// Associate an event with this new node and return the event.
1005-
GraphImpl->addEventForNode(EventImpl, *NodeImpl);
958+
auto EventImpl = Queue->submit_command_to_graph(
959+
*GraphImpl, std::move(CommandGroup), type, impl->MUserFacingNodeType);
1006960

1007961
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
1008962
return EventImpl;

sycl/unittests/Extensions/CommandGraph/CommandGraph.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,6 @@ TEST_F(CommandGraphTest, AccessorModeEdges) {
626626

627627
// Tests the transitive queue recording behaviour with queue shortcuts.
628628
TEST_F(CommandGraphTest, TransitiveRecordingShortcuts) {
629-
// Graphs not supported yet for the no-handler submit path
630-
#ifndef __DPCPP_ENABLE_UNFINISHED_NO_CGH_SUBMIT
631629
device Dev;
632630
context Ctx{{Dev}};
633631
queue Q1{Ctx, Dev};
@@ -671,7 +669,6 @@ TEST_F(CommandGraphTest, TransitiveRecordingShortcuts) {
671669
ext::oneapi::experimental::queue_state::executing);
672670
ASSERT_EQ(Q3.ext_oneapi_get_state(),
673671
ext::oneapi::experimental::queue_state::executing);
674-
#endif
675672
}
676673

677674
// Tests that dynamic_work_group_memory.get() will throw on the host side.

0 commit comments

Comments
 (0)