Skip to content

Commit 01310ee

Browse files
EwanCBensuo
andauthored
[SYCL][Graph] Finalize Graph for single device (#11565)
Only finalize a modifiable `command_graph` for the SYCL device that was passed on construction. We currently finalize for every device in the context, which is unnecessary overhead and may lead to unintended interactions with buffers used in these contexts. PR also includes code to start waiting on for deps when adding commands to a command graph. This prevents issues where allocation commands with dependent copies could be delayed due to device being busy and execute in an incorrect order with regards to future command graph executions. --------- Co-authored-by: Ben Tracy <[email protected]>
1 parent 3c213d2 commit 01310ee

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

sycl/source/detail/graph_impl.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -865,22 +865,20 @@ void executable_command_graph::finalizeImpl() {
865865
// Create PI command-buffers for each device in the finalized context
866866
impl->schedule();
867867

868-
auto Context = impl->getContext();
869-
for (const auto &Device : Context.get_devices()) {
870-
bool CmdBufSupport =
871-
Device.get_info<
872-
ext::oneapi::experimental::info::device::graph_support>() ==
873-
graph_support_level::native;
868+
auto Device = impl->getGraphImpl()->getDevice();
869+
bool CmdBufSupport =
870+
Device
871+
.get_info<ext::oneapi::experimental::info::device::graph_support>() ==
872+
graph_support_level::native;
874873

875874
#if FORCE_EMULATION_MODE
876-
// Above query should still succeed in emulation mode, but ignore the
877-
// result and use emulation.
878-
CmdBufSupport = false;
875+
// Above query should still succeed in emulation mode, but ignore the
876+
// result and use emulation.
877+
CmdBufSupport = false;
879878
#endif
880879

881-
if (CmdBufSupport) {
882-
impl->createCommandBuffers(Device);
883-
}
880+
if (CmdBufSupport) {
881+
impl->createCommandBuffers(Device);
884882
}
885883
}
886884

sycl/source/detail/scheduler/commands.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,6 +2641,11 @@ pi_int32 ExecCGCommand::enqueueImpCommandBuffer() {
26412641
auto RawEvents = getPiEvents(EventImpls);
26422642
flushCrossQueueDeps(EventImpls, getWorkerQueue());
26432643

2644+
// Any non-allocation dependencies need to be waited on here since subsequent
2645+
// submissions of the command buffer itself will not receive dependencies on
2646+
// them, e.g. initial copies from host to device
2647+
waitForEvents(MQueue, MPreparedDepsEvents, MEvent->getHandleRef());
2648+
26442649
sycl::detail::pi::PiEvent *Event =
26452650
(MQueue->has_discard_events_support() &&
26462651
MCommandGroup->getRequirements().size() == 0)

0 commit comments

Comments
 (0)