diff --git a/hipamd/src/hip_graph.cpp b/hipamd/src/hip_graph.cpp index 2272f523a8..869d60c210 100644 --- a/hipamd/src/hip_graph.cpp +++ b/hipamd/src/hip_graph.cpp @@ -1381,10 +1381,10 @@ hipError_t ihipGraphInstantiate(hip::GraphExec** pGraphExec, hip::Graph* graph, return hipErrorInvalidValue; } std::vector graphNodes; + clonedGraph->ScheduleNodes(); if (false == clonedGraph->TopologicalOrder(graphNodes)) { return hipErrorInvalidValue; } - clonedGraph->ScheduleNodes(); *pGraphExec = new hip::GraphExec(graphNodes, clonedGraph, clonedNodes, flags); if (*pGraphExec != nullptr) { graph->SetGraphInstantiated(true); diff --git a/hipamd/src/hip_graph_internal.cpp b/hipamd/src/hip_graph_internal.cpp index fb3af5bb05..9735519cb0 100644 --- a/hipamd/src/hip_graph_internal.cpp +++ b/hipamd/src/hip_graph_internal.cpp @@ -179,13 +179,6 @@ void Graph::ScheduleOneNode(Node node, int stream_id) { node->stream_id_ = stream_id; max_streams_ = std::max(max_streams_, (stream_id + 1)); - // Update the dependencies if a signal is required - for (auto dep: node->GetDependencies()) { - // Check if the stream ID doesn't match and enable signal - if (dep->stream_id_ != node->stream_id_) { - dep->signal_is_required_ |= true; - } - } // Process child graph separately, since, there is no connection if (node->GetType() == hipGraphNodeTypeGraph) { auto child = reinterpret_cast(node)->childGraph_; @@ -236,6 +229,14 @@ bool Graph::TopologicalOrder(std::vector& TopoOrder) { std::queue q; std::unordered_map inDegree; for (auto entry : vertices_) { + // Update the dependencies if a signal is required + for (auto dep: entry->GetDependencies()) { + // Check if the stream ID doesn't match and enable signal + if (dep->stream_id_ != entry->stream_id_) { + dep->signal_is_required_ = true; + } + } + if (entry->GetInDegree() == 0) { q.push(entry); }