diff --git a/hipamd/src/hip_device.cpp b/hipamd/src/hip_device.cpp index 5ea357f2f4..c4c704b1b3 100644 --- a/hipamd/src/hip_device.cpp +++ b/hipamd/src/hip_device.cpp @@ -57,7 +57,7 @@ bool Device::Create() { } // Create graph memory pool - graph_mem_pool_ = new MemoryPool(this); + graph_mem_pool_ = new MemoryPool(this, nullptr, true); if (graph_mem_pool_ == nullptr) { return false; } diff --git a/hipamd/src/hip_graph_internal.hpp b/hipamd/src/hip_graph_internal.hpp index a80bb71c7c..7b13bfbfe3 100644 --- a/hipamd/src/hip_graph_internal.hpp +++ b/hipamd/src/hip_graph_internal.hpp @@ -1071,7 +1071,7 @@ class GraphKernelNode : public GraphNode { hipError_t SetAttrParams(hipKernelNodeAttrID attr, const hipKernelNodeAttrValue* params) { hipDeviceProp_t prop = {0}; - hipError_t status = ihipGetDeviceProperties(&prop, ihipGetDevice()); + hipError_t status = ihipGetDeviceProperties(&prop, ihipGetDevice()); if (hipSuccess != status){ return status; } @@ -2106,9 +2106,10 @@ class GraphMemAllocNode final : public GraphNode { size_ = aligned_size; // Execute the original mapping command VirtualMapCommand::submit(device); + queue()->device().SetMemAccess(va_->getSvmPtr(), aligned_size, amd::Device::VmmAccess::kReadWrite); va_->retain(); - ClPrint(amd::LOG_INFO, amd::LOG_MEM_POOL, "Graph MemAlloc execute: %p, %p", - va_->getSvmPtr(), memory()); + ClPrint(amd::LOG_INFO, amd::LOG_MEM_POOL, "Graph MemAlloc execute [%p-%p], %p", + va_->getSvmPtr(), reinterpret_cast(va_->getSvmPtr()) + aligned_size, memory()); } private: diff --git a/hipamd/src/hip_mempool_impl.cpp b/hipamd/src/hip_mempool_impl.cpp index 8b30e89857..6c6b98ae56 100644 --- a/hipamd/src/hip_mempool_impl.cpp +++ b/hipamd/src/hip_mempool_impl.cpp @@ -180,6 +180,7 @@ void* MemoryPool::AllocateMemory(size_t size, Stream* stream, void* dptr) { return nullptr; } cl_svm_mem_flags flags = (state_.interprocess_) ? ROCCLR_MEM_INTERPROCESS : 0; + flags |= (state_.phys_mem_) ? ROCCLR_MEM_PHYMEM : 0; dev_ptr = amd::SvmBuffer::malloc(*context, flags, size, dev_info.memBaseAddrAlign_, nullptr); if (dev_ptr == nullptr) { size_t free = 0, total =0; @@ -291,7 +292,7 @@ bool MemoryPool::FreeMemory(amd::Memory* memory, Stream* stream, Event* event) { // Decrement the reference counter on the pool. // Note: It may delete memory pool for the last allocation. Thus, the scope lock can't include - // this call. + // this call. release(); return true; diff --git a/hipamd/src/hip_mempool_impl.hpp b/hipamd/src/hip_mempool_impl.hpp index 536e24f025..0662d1dc96 100644 --- a/hipamd/src/hip_mempool_impl.hpp +++ b/hipamd/src/hip_mempool_impl.hpp @@ -196,7 +196,7 @@ class MemoryPool : public amd::ReferenceCountedObject { SharedAccess access_[kMaxMgpuAccess]; //!< The list of devices for access }; - MemoryPool(hip::Device* device, const hipMemPoolProps* props = nullptr) + MemoryPool(hip::Device* device, const hipMemPoolProps* props = nullptr, bool phys_mem = false) : busy_heap_(device), free_heap_(device), lock_pool_ops_("Pool operations", true), @@ -208,6 +208,7 @@ class MemoryPool : public amd::ReferenceCountedObject { state_.event_dependencies_ = 1; state_.opportunistic_ = 1; state_.internal_dependencies_ = 1; + state_.phys_mem_ = HIP_MEM_POOL_USE_VM && phys_mem; if (props != nullptr) { properties_ = *props; } else { @@ -317,6 +318,7 @@ class MemoryPool : public amd::ReferenceCountedObject { //!< dependencies uint32_t interprocess_ : 1; //!< Memory pool can be used in interprocess communications uint32_t graph_in_use_ : 1; //!< Memory pool was used in a graph execution + uint32_t phys_mem_ : 1; //!< Mempool is used for graphs and will have physical allocations }; uint32_t value_; } state_; diff --git a/rocclr/device/rocm/rocvirtual.cpp b/rocclr/device/rocm/rocvirtual.cpp index fd9bb7faaf..51080013b7 100644 --- a/rocclr/device/rocm/rocvirtual.cpp +++ b/rocclr/device/rocm/rocvirtual.cpp @@ -2615,6 +2615,9 @@ void VirtualGPU::submitVirtualMap(amd::VirtualMapCommand& vcmd) { LogError("HSA Command: hsa_amd_vmem_map failed!"); } } else { + dispatchBarrierPacket(kBarrierPacketHeader, false); + Barriers().WaitCurrent(); + // Unmap the object, since the physical addr is set. if ((hsa_status = hsa_amd_vmem_unmap(vaddr_mem_obj->getSvmPtr(), vcmd.size())) == HSA_STATUS_SUCCESS) {