From 7c35d797d9b5f4e3ac33f12db32bc01947272182 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Wed, 10 Jan 2024 00:39:19 +0000 Subject: [PATCH] VMM: Fix flags when allocating memory handle When allocating a memory handle, the NoAddress thunk flag should be set so that this allocation does not have a virtual address range. Also, skip mapping the memory when allocating a memory handle Change-Id: I1c168bc00ddbc158d447197c4dc25f96bad02b19 [ROCm/ROCR-Runtime commit: 29efd8eccd03c8720bf6fd7b87e8c556a221ac34] --- .../hsa-runtime/core/runtime/amd_memory_region.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp index 5108310143..b564773eed 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp @@ -200,11 +200,15 @@ hsa_status_t MemoryRegion::AllocateImpl(size_t& size, AllocateFlags alloc_flags, if (IsSystem() && (alloc_flags & AllocateNonPaged)) kmt_alloc_flags.ui32.NonPaged = 1; + // Allocating a memory handle for virtual memory + kmt_alloc_flags.ui32.NoAddress = !!(alloc_flags & AllocateMemoryOnly); + // Allocate pseudo fine grain memory kmt_alloc_flags.ui32.CoarseGrain = (alloc_flags & AllocatePCIeRW ? 0 : kmt_alloc_flags.ui32.CoarseGrain); + kmt_alloc_flags.ui32.NoSubstitute = (alloc_flags & AllocatePinned ? 1 : kmt_alloc_flags.ui32.NoSubstitute); // Only allow using the suballocator for ordinary VRAM. - if (IsLocalMemory()) { + if (IsLocalMemory() && !kmt_alloc_flags.ui32.NoAddress) { bool subAllocEnabled = !core::Runtime::runtime_singleton_->flag().disable_fragment_alloc(); // Avoid modifying executable or queue allocations. bool useSubAlloc = subAllocEnabled; @@ -230,6 +234,8 @@ hsa_status_t MemoryRegion::AllocateImpl(size_t& size, AllocateFlags alloc_flags, *address = AllocateKfdMemory(kmt_alloc_flags, owner()->node_id(), size); } + if (kmt_alloc_flags.ui32.NoAddress) return HSA_STATUS_SUCCESS; + if (*address != nullptr) { // Commit the memory. // For system memory, on non-restricted allocation, map it to all GPUs. On