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(); + } } }