From eb825325d27a079b06d70cd906fca7150c23d82a Mon Sep 17 00:00:00 2001 From: Ioannis Assiouras Date: Tue, 25 Feb 2025 12:56:21 +0000 Subject: [PATCH] SWDEV-516994 - Fix race condition in the implementation of graph AutoFreeOnLaunch on Windows Change-Id: I3c98d0d4bffe2a9e0aa5cfa24b6c8e9a8087da29 [ROCm/clr commit: a8f309049de644c23e14687c26a58be4eb277b04] --- projects/clr/hipamd/src/hip_graph_internal.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/projects/clr/hipamd/src/hip_graph_internal.cpp b/projects/clr/hipamd/src/hip_graph_internal.cpp index b709298947..589430fc46 100644 --- a/projects/clr/hipamd/src/hip_graph_internal.cpp +++ b/projects/clr/hipamd/src/hip_graph_internal.cpp @@ -691,6 +691,12 @@ hipError_t GraphExec::Run(hipStream_t graph_launch_stream) { if (!topoOrder_.empty()) { topoOrder_[0]->GetParentGraph()->FreeAllMemory(launch_stream); topoOrder_[0]->GetParentGraph()->memalloc_nodes_ = 0; + if (!AMD_DIRECT_DISPATCH) { + // The MemoryPool::FreeAllMemory queues a memory unmap command that for !AMD_DIRECT_DISPATCH + // runs asynchonously. Make sure that freeAllMemory is complete before creating new commands + // to prevent races to the MemObjMap. + launch_stream->finish(); + } } }