From 389cd3564b3d08ef0006576e279f1458ede25119 Mon Sep 17 00:00:00 2001 From: Xiaomeng Hou Date: Tue, 6 Jun 2023 22:01:31 +0800 Subject: [PATCH] Do not reserve scratch memory on asic with finite vram resource Change-Id: I0a2207cb01f464ed3e73331637cfa9bd62f03d97 --- runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp index 7ac0c0842c..f4ac5ca7cc 100644 --- a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp +++ b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp @@ -521,8 +521,11 @@ void GpuAgent::InitScratchPool() { void GpuAgent::ReserveScratch() { size_t reserved_sz = core::Runtime::runtime_singleton_->flag().scratch_single_limit(); + size_t available; + HSAKMT_STATUS err = hsaKmtAvailableMemory(node_id(), &available); + assert(err == HSAKMT_STATUS_SUCCESS && "hsaKmtAvailableMemory failed"); ScopedAcquire lock(&scratch_lock_); - if (!scratch_cache_.reserved_bytes() && reserved_sz) { + if (!scratch_cache_.reserved_bytes() && reserved_sz && available > 8 * reserved_sz) { HSAuint64 alt_va; void* reserved_base = scratch_pool_.alloc(reserved_sz); assert(reserved_base && "Could not allocate reserved memory");