@@ -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+
423478detail::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 };
0 commit comments