From 97918cbd7c9af8e11f959058dea0dbf17daa9d2e Mon Sep 17 00:00:00 2001 From: Mengbing Wang Date: Thu, 4 Mar 2021 18:44:07 +0800 Subject: [PATCH] limit the memory allocation on vram to 3/4 of vram size. 1. As we cannot ganrantee that 100% apu vram are free to be allocated, limit the allocation size be no more than 3/4 of vram size. 2. Keep the old 1GB allocation limit for dGPU case. 3. Add the alignment check for alloc_size. Affected tests: rocrtstStress.Memory_Concurrent_Allocate_Test rocrtstStress.Memory_Concurrent_Free_Test Change-Id: Id0023de132024d02f80980ae4237d9d74d9e27d3 Signed-off-by: Mengbing Wang [ROCm/ROCR-Runtime commit: d5855c1658b74ccbd3c20edb0513b81a1f544aae] --- .../suites/stress/memory_concurrent_tests.cc | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/projects/rocr-runtime/rocrtst/suites/stress/memory_concurrent_tests.cc b/projects/rocr-runtime/rocrtst/suites/stress/memory_concurrent_tests.cc index d5353e95b1..50b23556cc 100755 --- a/projects/rocr-runtime/rocrtst/suites/stress/memory_concurrent_tests.cc +++ b/projects/rocr-runtime/rocrtst/suites/stress/memory_concurrent_tests.cc @@ -268,10 +268,18 @@ void MemoryConcurrentTest::MemoryConcurrentAllocate(hsa_agent_t agent, if (alloc) { size_t alloc_size; + size_t total_vram_size; + err = hsa_amd_memory_pool_get_info(pool, HSA_AMD_MEMORY_POOL_INFO_ALLOC_MAX_SIZE, - &alloc_size); - // Adjust the size to the minimum of 1024 or max alloc size - alloc_size = (alloc_size < kMaxAllocSize) ? alloc_size: kMaxAllocSize; + &total_vram_size); + ASSERT_EQ(err, HSA_STATUS_SUCCESS); + + // Make sure do not allocate more than 3/4 of the vram size + alloc_size = (total_vram_size*3/4 <= kMaxAllocSize*kNumThreads) ? total_vram_size*3/(4*kNumThreads): kMaxAllocSize; + + // Page align the alloc_size + alloc_size = alloc_size - (alloc_size & ((1 << 12) - 1)); + // Create a test group rocrtst::test_group* tg_concurrent = rocrtst::TestGroupCreate(kNumThreads); @@ -350,12 +358,16 @@ void MemoryConcurrentTest::MemoryConcurrentFree(hsa_agent_t agent, if (alloc) { // Get the maximum allocation size size_t alloc_size; + size_t total_vram_size; err = hsa_amd_memory_pool_get_info(pool, HSA_AMD_MEMORY_POOL_INFO_ALLOC_MAX_SIZE, - &alloc_size); + &total_vram_size); ASSERT_EQ(err, HSA_STATUS_SUCCESS); - // Adjust the size to the minimum of 1024 or max alloc size - alloc_size = (alloc_size < kMaxAllocSize) ? alloc_size: kMaxAllocSize; + // Make sure do not allocate more than 3/4 of the vram size + alloc_size = (total_vram_size*3/4 <= kMaxAllocSize*kNumThreads) ? total_vram_size*3/(4*kNumThreads): kMaxAllocSize; + + // Page align the alloc_size + alloc_size = alloc_size - (alloc_size & ((1 << 12) - 1)); // Create a test group rocrtst::test_group* tg_concurrent = rocrtst::TestGroupCreate(kNumThreads);