diff --git a/projects/clr/hipamd/src/hip_graph_internal.cpp b/projects/clr/hipamd/src/hip_graph_internal.cpp index a985218a2c..f98eca1c05 100644 --- a/projects/clr/hipamd/src/hip_graph_internal.cpp +++ b/projects/clr/hipamd/src/hip_graph_internal.cpp @@ -578,9 +578,11 @@ hipError_t hipGraphExec::Run(hipStream_t stream) { if (hip::getStream(stream) == nullptr) { return hipErrorInvalidResourceHandle; } + auto hip_stream = (stream == nullptr) ? hip::getCurrentDevice()->NullStream() + : reinterpret_cast(stream); if (flags_ & hipGraphInstantiateFlagAutoFreeOnLaunch) { if (!topoOrder_.empty()) { - topoOrder_[0]->GetParentGraph()->FreeAllMemory(); + topoOrder_[0]->GetParentGraph()->FreeAllMemory(hip_stream); } } @@ -597,8 +599,6 @@ hipError_t hipGraphExec::Run(hipStream_t stream) { repeatLaunch_ = true; } - auto hip_stream = (stream == nullptr) ? hip::getCurrentDevice()->NullStream() - : reinterpret_cast(stream); UpdateStream(parallelLists_, hip_stream, this); std::vector rootCommands; amd::Command* endCommand = nullptr; diff --git a/projects/clr/hipamd/src/hip_graph_internal.hpp b/projects/clr/hipamd/src/hip_graph_internal.hpp index 6ee9f315e1..1c2b20cac0 100644 --- a/projects/clr/hipamd/src/hip_graph_internal.hpp +++ b/projects/clr/hipamd/src/hip_graph_internal.hpp @@ -525,8 +525,8 @@ struct ihipGraph { return false; } - void FreeAllMemory() { - mem_pool_->FreeAllMemory(); + void FreeAllMemory(hip::Stream* stream) { + mem_pool_->FreeAllMemory(stream); } bool IsGraphInstantiated() const { @@ -1940,7 +1940,9 @@ class hipGraphMemAllocNode : public hipGraphNode { virtual void submit(device::VirtualDevice& device) final { // Remove VA reference from the global mapping. Runtime has to keep a dummy reference for // validation logic during the capture or creation of the nodes - amd::MemObjMap::RemoveMemObj(va_->getSvmPtr()); + if (amd::MemObjMap::FindMemObj(va_->getSvmPtr())) { + amd::MemObjMap::RemoveMemObj(va_->getSvmPtr()); + } // Allocate real memory for mapping const auto& dev_info = queue()->device().info(); auto aligned_size = amd::alignUp(size_, dev_info.virtualMemAllocGranularity_);