From dabe311bd8ab4e3c3016e07416db9175e3ee5ac8 Mon Sep 17 00:00:00 2001 From: Shane Xiao Date: Thu, 17 Oct 2024 15:54:23 +0800 Subject: [PATCH] SWDEV-492049 - Remove the handle of Phy Mem from Memobj The hipGraph will use VMM by default when allocating memory. However, the handle of Phy mem has been added to Memobj by default. Since the Memobj will track the whole address range from handle to handle + size, this needs the system to reserve the whole address range. If the system range have not reserved by the system, then it will have the potential issue that clr finds the Memobj incorrectly. This patch removes the handle from the Memobj to fix this potential issue. Change-Id: I2da38e6b2d11d0d48e1afe66c46899500c290624 [ROCm/clr commit: 231b2410a0a84366a7eaa0695405b80dde5a2663] --- projects/clr/hipamd/src/hip_graph_internal.hpp | 4 ++++ projects/clr/hipamd/src/hip_mempool_impl.cpp | 2 ++ 2 files changed, 6 insertions(+) diff --git a/projects/clr/hipamd/src/hip_graph_internal.hpp b/projects/clr/hipamd/src/hip_graph_internal.hpp index 21659471a1..6ec1840aac 100644 --- a/projects/clr/hipamd/src/hip_graph_internal.hpp +++ b/projects/clr/hipamd/src/hip_graph_internal.hpp @@ -2335,6 +2335,10 @@ class GraphMemAllocNode final : public GraphNode { memory_ = getMemoryObject(dptr, offset); // Retain memory object because command release will release it memory_->retain(); + + // Remove because the entry is not needed in MemObjMap after the memory_ has been saved. + // The Phy mem obj will be saved in virtual memory object during VirtualMapCommand::submit. + amd::MemObjMap::RemoveMemObj(dptr); size_ = aligned_size; // Execute the original mapping command VirtualMapCommand::submit(device); diff --git a/projects/clr/hipamd/src/hip_mempool_impl.cpp b/projects/clr/hipamd/src/hip_mempool_impl.cpp index 98acefc710..a1c0ef9b54 100644 --- a/projects/clr/hipamd/src/hip_mempool_impl.cpp +++ b/projects/clr/hipamd/src/hip_mempool_impl.cpp @@ -216,6 +216,8 @@ void* MemoryPool::AllocateMemory(size_t size, Stream* stream, void* dptr) { } } else { dev_ptr = memory->getSvmPtr(); + if (!amd::MemObjMap::FindMemObj(dev_ptr)) + amd::MemObjMap::AddMemObj(dev_ptr, memory); } // Place the allocated memory into the busy heap ts.AddSafeStream(stream);