From f464a6ade6915538bb870f8f1697a7a13bc0d453 Mon Sep 17 00:00:00 2001 From: Anusha GodavarthySurya Date: Mon, 28 Aug 2023 12:13:20 +0000 Subject: [PATCH] SWDEV-301667 - Optimize performance when graph has single branch Three for loops iterate over all graph nodes for UpdateStream, FillCommands and EnqueueCommands has performance drop for large graphs. Change-Id: I077accf3a4680d5d944b73200fd6498a7a48f25c [ROCm/clr commit: 530dc6de2a08a115bcc0b6d28230e3c775f02dbf] --- .../clr/hipamd/src/hip_graph_internal.cpp | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/projects/clr/hipamd/src/hip_graph_internal.cpp b/projects/clr/hipamd/src/hip_graph_internal.cpp index 9dba23ae1c..70fe657064 100644 --- a/projects/clr/hipamd/src/hip_graph_internal.cpp +++ b/projects/clr/hipamd/src/hip_graph_internal.cpp @@ -602,23 +602,12 @@ hipError_t GraphExec::Run(hipStream_t stream) { } else { repeatLaunch_ = true; } - - UpdateStream(parallelLists_, hip_stream, this); - amd::Command* rootCommand = nullptr; - amd::Command* endCommand = nullptr; - status = FillCommands(parallelLists_, nodeWaitLists_, topoOrder_, clonedGraph_, rootCommand, - endCommand, hip_stream); - if (status != hipSuccess) { - return status; - } - if (rootCommand != nullptr) { - rootCommand->enqueue(); - rootCommand->release(); - } - for (int i = 0; i < topoOrder_.size(); i++) { - if (DEBUG_CLR_GRAPH_ENABLE_BUFFERING) { - // Enable buffering for graph with single branch - if (parallelLists_.size() == 1) { + if (parallelLists_.size() == 1) { + for (int i = 0; i < topoOrder_.size(); i++) { + topoOrder_[i]->SetStream(hip_stream, this); + status = topoOrder_[i]->CreateCommand(topoOrder_[i]->GetQueue()); + if (DEBUG_CLR_GRAPH_ENABLE_BUFFERING) { + // Enable buffering for graph with single branch // Peep through the next node. If current and next node are kernel then enable AQL // buffering if (((i + 1) != topoOrder_.size()) && topoOrder_[i]->GetType() == hipGraphNodeTypeKernel && @@ -626,12 +615,28 @@ hipError_t GraphExec::Run(hipStream_t stream) { topoOrder_[i]->EnableBuffering(); } } + topoOrder_[i]->EnqueueCommands(stream); + } + } else { + UpdateStream(parallelLists_, hip_stream, this); + amd::Command* rootCommand = nullptr; + amd::Command* endCommand = nullptr; + status = FillCommands(parallelLists_, nodeWaitLists_, topoOrder_, clonedGraph_, rootCommand, + endCommand, hip_stream); + if (status != hipSuccess) { + return status; + } + if (rootCommand != nullptr) { + rootCommand->enqueue(); + rootCommand->release(); + } + for (int i = 0; i < topoOrder_.size(); i++) { + topoOrder_[i]->EnqueueCommands(stream); + } + if (endCommand != nullptr) { + endCommand->enqueue(); + endCommand->release(); } - topoOrder_[i]->EnqueueCommands(stream); - } - if (endCommand != nullptr) { - endCommand->enqueue(); - endCommand->release(); } ResetQueueIndex(); return status;