From 107b48fb15fadf20f5de6a8a7ed9c63ee9cf5d5b Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Thu, 6 Feb 2025 16:22:52 +0000 Subject: [PATCH] rocr: Add queries for async scratch reclaim Add support for these 2 new queries: - HSA_AMD_AGENT_INFO_SCRATCH_LIMIT_MAX Maximum amount of scratch memory allowed on this agent - HSA_AMD_AGENT_INFO_SCRATCH_LIMIT_CURRENT Current limit for scratch memory on this agent --- .../core/runtime/amd_cpu_agent.cpp | 4 ++++ .../core/runtime/amd_gpu_agent.cpp | 6 ++++++ runtime/hsa-runtime/inc/hsa_ext_amd.h | 21 ++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/runtime/hsa-runtime/core/runtime/amd_cpu_agent.cpp b/runtime/hsa-runtime/core/runtime/amd_cpu_agent.cpp index 8d66fdc4a0..0faba4377e 100644 --- a/runtime/hsa-runtime/core/runtime/amd_cpu_agent.cpp +++ b/runtime/hsa-runtime/core/runtime/amd_cpu_agent.cpp @@ -415,6 +415,10 @@ hsa_status_t CpuAgent::GetInfo(hsa_agent_info_t attribute, void* value) const { case HSA_AMD_AGENT_INFO_AQL_EXTENSIONS: memset(value, 0, sizeof(uint8_t) * 8); break; + case HSA_AMD_AGENT_INFO_SCRATCH_LIMIT_MAX: + case HSA_AMD_AGENT_INFO_SCRATCH_LIMIT_CURRENT: + *((uint64_t*)value) = 0; + break; default: return HSA_STATUS_ERROR_INVALID_ARGUMENT; break; diff --git a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp index f4b0fb1495..d8c5c820e8 100644 --- a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp +++ b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp @@ -1630,6 +1630,12 @@ hsa_status_t GpuAgent::GetInfo(hsa_agent_info_t attribute, void* value) const { memset(value, 0, sizeof(uint8_t) * 8); /* Not yet implemented */ break; + case HSA_AMD_AGENT_INFO_SCRATCH_LIMIT_MAX: + *((uint64_t*)value) = MaxScratchDevice(); + break; + case HSA_AMD_AGENT_INFO_SCRATCH_LIMIT_CURRENT: + *((uint64_t*)value) = scratch_limit_async_threshold_; + break; default: return HSA_STATUS_ERROR_INVALID_ARGUMENT; break; diff --git a/runtime/hsa-runtime/inc/hsa_ext_amd.h b/runtime/hsa-runtime/inc/hsa_ext_amd.h index b778132a1f..772896e80b 100644 --- a/runtime/hsa-runtime/inc/hsa_ext_amd.h +++ b/runtime/hsa-runtime/inc/hsa_ext_amd.h @@ -731,7 +731,26 @@ typedef enum hsa_amd_agent_info_s { * bit is set at that position. User may use the hsa_flag_isset64 macro to verify whether a flag * is set. The type of this attribute is uint8_t[8]. */ - HSA_AMD_AGENT_INFO_AQL_EXTENSIONS = 0xA115 /* Not implemented yet */ + HSA_AMD_AGENT_INFO_AQL_EXTENSIONS = 0xA115, /* Not implemented yet */ + /** + * Maximum allowed value in bytes for scratch limit for this agent. This amount + * is shared accross all queues created on this agent. + * The type of this attribute is uint64_t. + */ + HSA_AMD_AGENT_INFO_SCRATCH_LIMIT_MAX = 0xA116, + /** + * Current scratch limit threshold in bytes for this agent. This limit can be + * modified using the hsa_amd_agent_set_async_scratch_limit call. + * - AQL dispatches that require scratch-memory above this threshold will trigger a + * scratch use-once. + * - AQL dispatches using less scratch-memory than this threshold, ROCr will + * permanently assign the allocated scratch memory to the queue handling the dispatch. + * This memory can be reclaimed by calling hsa_amd_agent_set_async_scratch_limit + * with a lower threshold by current value. + * + * The type of this attribute is uint64_t. + */ + HSA_AMD_AGENT_INFO_SCRATCH_LIMIT_CURRENT = 0xA117 } hsa_amd_agent_info_t; /**