From e4f386ca76b7bd22a389b15f07f60f25d986cee2 Mon Sep 17 00:00:00 2001 From: prihosur-amd Date: Wed, 9 Sep 2026 13:40:29 +0530 Subject: [PATCH 1/3] rocr: fix incorrect ALLOC_MAX_SIZE reporting for HSA_HEAPTYPE_DEVICE_SVM pools MemoryRegion::GetInfo() and AllocateImpl() used max_sysmem_alloc_size_ for HSA_HEAPTYPE_DEVICE_SVM regions, so device-SVM/AIE pools advertised the system-memory allocation cap instead of their own per-pool limit. This let allocators request sizes the pool cannot actually satisfy, which fails during concurrent alloc/free on AIE pools (e.g. aie2p Pool 8) with HSA_STATUS_ERROR_OUT_OF_RESOURCES. Report max_single_alloc_size_ for HSA_HEAPTYPE_DEVICE_SVM instead, matching the same value already used in AllocateImpl()'s own local-memory size check. Verified on gfx1151 (Strix Halo APU) with rocrtst: - rocrtstStress.Memory_Concurrent_Allocate_Test: FAIL -> PASS - rocrtstStress.Memory_Concurrent_Free_Test: FAIL -> PASS --- .../hsa-runtime/core/runtime/amd_memory_region.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 2bdde7dc560a..c8279405adf5 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 @@ -152,7 +152,9 @@ hsa_status_t MemoryRegion::AllocateImpl(size_t& size, AllocateFlags alloc_flags, // Skip the per-region cap on Windows/DXG so over-commit requests can // reach WDDM; system memory still enforces the cap. const bool is_windxg = core::Runtime::runtime_singleton_->thunkLoader()->IsWinDxg(); - if (IsSystem() && (size > max_sysmem_alloc_size_)) { + const size_t max_alloc_size = + IsDeviceSVM() ? max_single_alloc_size_ : max_sysmem_alloc_size_; + if (IsSystem() && (size > max_alloc_size)) { return HSA_STATUS_ERROR_INVALID_ALLOCATION; } if (!IsSystem() && !is_windxg && (size > max_single_alloc_size_)) { @@ -231,9 +233,11 @@ hsa_status_t MemoryRegion::GetInfo(hsa_region_info_t attribute, case HSA_REGION_INFO_ALLOC_MAX_SIZE: switch (mem_props_.HeapType) { case HSA_HEAPTYPE_SYSTEM: - case HSA_HEAPTYPE_DEVICE_SVM: *((size_t*)value) = max_sysmem_alloc_size_; break; + case HSA_HEAPTYPE_DEVICE_SVM: + *((size_t*)value) = max_single_alloc_size_; + break; case HSA_HEAPTYPE_FRAME_BUFFER_PRIVATE: case HSA_HEAPTYPE_FRAME_BUFFER_PUBLIC: case HSA_HEAPTYPE_GPU_SCRATCH: From a2d4d35e3c5883d92bee063ade102ef31444b40d Mon Sep 17 00:00:00 2001 From: prihosur Date: Thu, 8 Oct 2026 18:53:39 +0530 Subject: [PATCH 2/3] fix(rocr): correct Device-SVM allocation limit comments --- .../hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp | 6 +++--- .../runtime/hsa-runtime/core/runtime/amd_aie_agent.cpp | 4 ++-- .../runtime/hsa-runtime/core/runtime/amd_memory_region.cpp | 2 -- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp index 82c5de4237fb..ace7ab497fe0 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp @@ -701,9 +701,9 @@ hsa_status_t XdnaDriver::AllocateMemory(const core::MemoryRegion& mem_region, if (use_bo_share) { create_bo_args.type = AMDXDNA_BO_SHARE; } else { - // While this is already checked in MemoryRegion::AllocateImpl, the max size is - // MemoryRegion::max_sysmem_alloc_size_ for HSA_HEAPTYPE_DEVICE_SVM which is incorrect - // for dev heap. + // MemoryRegion::AllocateImpl already caps this at MemoryRegion::max_single_alloc_size_, which + // is dev_heap_size for HSA_HEAPTYPE_DEVICE_SVM. Keep this defensive duplicate so an oversized + // CREATE_BO cannot reach the driver if that cap ever regresses. if (size > dev_heap_size) { return HSA_STATUS_ERROR_INVALID_ALLOCATION; } diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_aie_agent.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_aie_agent.cpp index f897641eb183..142bb90a59c8 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_aie_agent.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_aie_agent.cpp @@ -325,8 +325,8 @@ void AieAgent::InitRegionList() { // We use HSA_HEAPTYPE_DEVICE_SVM so that the recommended // HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_REC_GRANULE is 0. We can use that to determine if a pool // is regular pool or dev heap. - // The system will report the max allocatable size as MemoryRegion::max_sysmem_alloc_size_, but - // this is incorrect. The pool is exactly XdnaDriver::GetDevHeapByteSize() bytes. + // The pool reports its max allocatable size as MemoryRegion::max_single_alloc_size_, which is + // exactly XdnaDriver::GetDevHeapByteSize() bytes. HsaMemoryProperties dev_mem_props = {}; dev_mem_props.HeapType = HSA_HEAPTYPE_DEVICE_SVM; dev_mem_props.SizeInBytes = XdnaDriver::GetDevHeapByteSize(); 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 c8279405adf5..8997e3372d7c 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 @@ -236,8 +236,6 @@ hsa_status_t MemoryRegion::GetInfo(hsa_region_info_t attribute, *((size_t*)value) = max_sysmem_alloc_size_; break; case HSA_HEAPTYPE_DEVICE_SVM: - *((size_t*)value) = max_single_alloc_size_; - break; case HSA_HEAPTYPE_FRAME_BUFFER_PRIVATE: case HSA_HEAPTYPE_FRAME_BUFFER_PUBLIC: case HSA_HEAPTYPE_GPU_SCRATCH: From 624adb26d865aad14f6f2035ff6379316b60f391 Mon Sep 17 00:00:00 2001 From: prihosur Date: Thu, 8 Oct 2026 20:31:48 +0530 Subject: [PATCH 3/3] fix(rocr): remove redundant Device-SVM size check --- .../hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp index 31a43ea699eb..7b939a2ecc16 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp @@ -1203,13 +1203,6 @@ hsa_status_t XdnaDriver::AllocateMemory(const core::MemoryRegion& mem_region, if (use_bo_share) { create_bo_args.type = AMDXDNA_BO_SHARE; } else { - // MemoryRegion::AllocateImpl already caps this at MemoryRegion::max_single_alloc_size_, which - // is dev_heap_size for HSA_HEAPTYPE_DEVICE_SVM. Keep this defensive duplicate so an oversized - // CREATE_BO cannot reach the driver if that cap ever regresses. - if (size > dev_heap_size) { - return HSA_STATUS_ERROR_INVALID_ALLOCATION; - } - create_bo_args.type = AMDXDNA_BO_DEV; }