From a081bdd15795a2a7d2476c64673d9e625340ca32 Mon Sep 17 00:00:00 2001 From: sdashmiz Date: Fri, 14 Oct 2022 18:11:08 -0400 Subject: [PATCH] SWDEV-361623 - correct remove edge behaviour - remove node dependency before checking parents - reduce edge level acording to new value of node Signed-off-by: sdashmiz Change-Id: Id4bff1684f7e0b42beeebc4d2e009bfdb507fb5f [ROCm/clr commit: 34d087da93cc8d0fac746a957b221759da5d2ad8] --- projects/clr/hipamd/src/hip_graph.cpp | 2 +- projects/clr/hipamd/src/hip_graph_internal.hpp | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/projects/clr/hipamd/src/hip_graph.cpp b/projects/clr/hipamd/src/hip_graph.cpp index 35b14e230e..75d0f3d737 100644 --- a/projects/clr/hipamd/src/hip_graph.cpp +++ b/projects/clr/hipamd/src/hip_graph.cpp @@ -1711,7 +1711,7 @@ hipError_t hipGraphRemoveDependencies(hipGraph_t graph, const hipGraphNode_t* fr } for (size_t i = 0; i < numDependencies; i++) { if (to[i]->GetParentGraph() != graph || from[i]->GetParentGraph() != graph || - from[i]->RemoveEdge(to[i]) == false) { + from[i]->RemoveUpdateEdge(to[i]) == false) { HIP_RETURN(hipErrorInvalidValue); } } diff --git a/projects/clr/hipamd/src/hip_graph_internal.hpp b/projects/clr/hipamd/src/hip_graph_internal.hpp index 5fb557dc50..dfebf11917 100644 --- a/projects/clr/hipamd/src/hip_graph_internal.hpp +++ b/projects/clr/hipamd/src/hip_graph_internal.hpp @@ -265,6 +265,9 @@ struct hipGraphNode : public hipGraphNodeDOTAttribute { dependencies_.erase(std::remove(dependencies_.begin(), dependencies_.end(), node), dependencies_.end()); } + void RemoveEdge(const Node& childNode) { + edges_.erase(std::remove(edges_.begin(), edges_.end(), childNode), edges_.end()); + } /// Return graph node children const std::vector& GetEdges() const { return edges_; } /// Updates graph node children @@ -280,6 +283,12 @@ struct hipGraphNode : public hipGraphNodeDOTAttribute { edge->UpdateEdgeLevel(); } } + void ReduceEdgeLevel() { + for (auto edge: edges_) { + edge->SetLevel(std::min(edge->GetLevel(),GetLevel() + 1)); + edge->ReduceEdgeLevel(); + } + } /// Add edge, update parent node outdegree, child node indegree, level and dependency void AddEdge(const Node& childNode) { edges_.push_back(childNode); @@ -290,7 +299,7 @@ struct hipGraphNode : public hipGraphNodeDOTAttribute { childNode->AddDependency(this); } /// Remove edge, update parent node outdegree, child node indegree, level and dependency - bool RemoveEdge(const Node& childNode) { + bool RemoveUpdateEdge(const Node& childNode) { // std::remove changes the end() hence saving it before hand for validation auto currEdgeEnd = edges_.end(); auto it = std::remove(edges_.begin(), edges_.end(), childNode); @@ -301,15 +310,20 @@ struct hipGraphNode : public hipGraphNodeDOTAttribute { edges_.erase(it, edges_.end()); outDegree_--; childNode->SetInDegree(childNode->GetInDegree() - 1); + childNode->RemoveDependency(this); const std::vector& dependencies = childNode->GetDependencies(); int32_t level = 0; int32_t parentLevel = 0; + uint32_t origLevel = 0; for (auto parent : dependencies) { parentLevel = parent->GetLevel(); level = std::max(level, (parentLevel + 1)); } + origLevel = childNode->GetLevel(); childNode->SetLevel(level); - childNode->RemoveDependency(this); + if (level < origLevel) { + childNode->ReduceEdgeLevel(); + } return true; } /// Get Runlist of the nodes embedded as part of the graphnode(e.g. ChildGraph)