diff --git a/hipamd/src/hip_mempool_impl.hpp b/hipamd/src/hip_mempool_impl.hpp index 817285f386..aa7b8d0bbf 100644 --- a/hipamd/src/hip_mempool_impl.hpp +++ b/hipamd/src/hip_mempool_impl.hpp @@ -214,7 +214,7 @@ class MemoryPool : public amd::ReferenceCountedObject, amd::VmHeap { }; MemoryPool(hip::Device* device, const hipMemPoolProps* props = nullptr, bool phys_mem = false) - : VmHeap(device->asContext()->devices()[0], *device->NullStream()), + : VmHeap(device->devices()[0]), busy_heap_(device, *this), free_heap_(device, *this), lock_pool_ops_(true), @@ -259,6 +259,9 @@ class MemoryPool : public amd::ReferenceCountedObject, amd::VmHeap { } } + /// Returns a queue for virtual memory map/unmap operations + virtual amd::HostQueue& GetVmQueue() final { return *device_->NullStream(); } + /// The same stream can reuse memory without HIP event validation void* AllocateMemory(size_t size, Stream* stream, void* dptr = nullptr); diff --git a/rocclr/platform/vmheap.cpp b/rocclr/platform/vmheap.cpp index 69fdf3c3e7..070e3d40c1 100644 --- a/rocclr/platform/vmheap.cpp +++ b/rocclr/platform/vmheap.cpp @@ -68,7 +68,7 @@ bool VmHeap::CommitMemory(void* addr, size_t size) { // Map the physical memory to a virtual address Command* cmd = new VirtualMapCommand( - map_queue_, Command::EventWaitList{}, addr, padded_size, phys_mem_obj); + GetVmQueue(), Command::EventWaitList{}, addr, padded_size, phys_mem_obj); cmd->enqueue(); cmd->awaitCompletion(); cmd->release(); @@ -86,7 +86,8 @@ bool VmHeap::UncommitMemory(void* addr, size_t size) { Memory* phys_mem_obj = vaddr_sub_obj->getUserData().phys_mem_obj; // Unmap the physical memory from a virtual address - Command* cmd = new VirtualMapCommand(map_queue_, Command::EventWaitList{}, addr, size, nullptr); + Command* cmd = new VirtualMapCommand( + GetVmQueue(), Command::EventWaitList{}, addr, size, nullptr); cmd->enqueue(); cmd->awaitCompletion(); cmd->release(); @@ -96,12 +97,11 @@ bool VmHeap::UncommitMemory(void* addr, size_t size) { } // ================================================================================================ -VmHeap::VmHeap(Device* device, HostQueue& queue, size_t va_size, size_t chunk_size) +VmHeap::VmHeap(Device* device, size_t va_size, size_t chunk_size) : block_alignment_(kMinBlockAlignment) , chunk_size_(chunk_size) , lock_(true) - , device_(device) - , map_queue_(queue) { + , device_(device) { va_size_ = alignUp(va_size, chunk_size); } diff --git a/rocclr/platform/vmheap.hpp b/rocclr/platform/vmheap.hpp index 6dae3fe817..5042f030ec 100644 --- a/rocclr/platform/vmheap.hpp +++ b/rocclr/platform/vmheap.hpp @@ -68,15 +68,14 @@ class VmHeap { public: static const size_t kChunkSize = 32 * Mi; //!< Chunk size, must be power of 2 static const size_t kMinBlockAlignment = 256; - VmHeap(Device* device, //!< GPU device object - HostQueue& queue //!< Queue, used for map/unmap of physical memory - ) - : VmHeap(device, queue, device->info().globalMemSize_ / 8, kChunkSize) {} - VmHeap(Device* device, //!< GPU device object - HostQueue& queue, //!< Queue, usde for map/unmap of physical memory - size_t va_size, //!< The size of the allocated heap (bytes).Virtual address space - size_t chunk_size //!< The size of single chunk for physical memory growth + VmHeap(Device* device //!< GPU device object + ) + : VmHeap(device, device->info().globalMemSize_ / 8, kChunkSize) {} + + VmHeap(Device* device, //!< GPU device object + size_t va_size, //!< The size of the allocated heap (bytes).Virtual address space + size_t chunk_size //!< The size of single chunk for physical memory growth ); //! Ceates heap object. Reserves virtual address range for the heap operation @@ -85,6 +84,9 @@ public: //! Heap destructor virtual ~VmHeap(); + //! Returns a queue for VM map/unmap operations + virtual amd::HostQueue& GetVmQueue() = 0; + //! Returns a pointer to the allocated device memory from a heap address Alloc( size_t size //! The allocation size @@ -163,7 +165,6 @@ private: bool created_ = false; //!< Used for deferred VM heap allocation amd::Monitor lock_; //!< Lock to serialise heap accesses Device* device_; //!< Device that owns this heap - HostQueue& map_queue_; //!< Queue, used to map/unmap std::vector mapped_mem_; //!< A map of mapped memory, the size is total_size/chunk_size };