From 8da9c601a9c86553eaa677717b7950390490aa28 Mon Sep 17 00:00:00 2001 From: Sebastian Luzynski Date: Thu, 12 Mar 2026 20:23:00 +0000 Subject: [PATCH 1/2] [hip][AIRUNTIME-748] Implement hipMemGetDefaultMemPool api This change adds new api hipMemGetDefaultMemPool to the runtime Signed-off-by: Sebastian Luzynski --- .../include/hip/amd_detail/hip_api_trace.hpp | 9 ++++-- .../include/hip/amd_detail/hip_prof_str.h | 32 ++++++++++++++++++- projects/clr/hipamd/src/amdhip.def | 1 + projects/clr/hipamd/src/hip_api_trace.cpp | 9 ++++-- projects/clr/hipamd/src/hip_hcc.map.in | 1 + projects/clr/hipamd/src/hip_mempool.cpp | 32 +++++++++++++++++++ .../clr/hipamd/src/hip_table_interface.cpp | 8 ++++- projects/hip/include/hip/hip_runtime_api.h | 11 +++++++ .../nvidia_detail/nvidia_hip_runtime_api.h | 7 ++++ .../rocprofiler-sdk/cxx/enum_string.hpp | 5 +++ .../include/rocprofiler-sdk/hip/api_args.h | 9 ++++++ .../rocprofiler-sdk/hip/runtime_api_id.h | 3 ++ .../source/lib/rocprofiler-sdk/hip/abi.cpp | 6 ++++ .../lib/rocprofiler-sdk/hip/hip.def.cpp | 4 +++ 14 files changed, 131 insertions(+), 6 deletions(-) diff --git a/projects/clr/hipamd/include/hip/amd_detail/hip_api_trace.hpp b/projects/clr/hipamd/include/hip/amd_detail/hip_api_trace.hpp index 2eaedbe1ec0..6f877e703fb 100644 --- a/projects/clr/hipamd/include/hip/amd_detail/hip_api_trace.hpp +++ b/projects/clr/hipamd/include/hip/amd_detail/hip_api_trace.hpp @@ -48,7 +48,7 @@ #define HIP_API_TABLE_STEP_VERSION 0 #define HIP_COMPILER_API_TABLE_STEP_VERSION 0 #define HIP_TOOLS_API_TABLE_STEP_VERSION 0 -#define HIP_RUNTIME_API_TABLE_STEP_VERSION 25 +#define HIP_RUNTIME_API_TABLE_STEP_VERSION 26 // HIP API interface // HIP compiler dispatch functions @@ -1117,6 +1117,8 @@ typedef hipError_t (*t_hipMemGetMemPool)(hipMemPool_t* pool, hipMemLocation* loc hipMemAllocationType type); typedef hipError_t (*t_hipMipmappedArrayGetMemoryRequirements)( hipArrayMemoryRequirements* memoryRequirements, hipMipmappedArray_t mipmap, hipDevice_t device); +typedef hipError_t (*t_hipMemGetDefaultMemPool)(hipMemPool_t* memPool, hipMemLocation* location, + hipMemAllocationType type); // HIP Compiler dispatch table struct HipCompilerDispatchTable { // HIP_COMPILER_API_TABLE_STEP_VERSION == 0 @@ -1728,8 +1730,11 @@ struct HipDispatchTable { t_hipKernelSetAttribute hipKernelSetAttribute_fn; t_hipKernelGetFunction hipKernelGetFunction_fn; + // HIP_RUNTIME_API_TABLE_STEP_VERSION == 26 + t_hipMemGetDefaultMemPool hipMemGetDefaultMemPool_fn; + // DO NOT EDIT ABOVE! - // HIP_RUNTIME_API_TABLE_STEP_VERSION == 25 + // HIP_RUNTIME_API_TABLE_STEP_VERSION == 27 // ******************************************************************************************* // // diff --git a/projects/clr/hipamd/include/hip/amd_detail/hip_prof_str.h b/projects/clr/hipamd/include/hip/amd_detail/hip_prof_str.h index e3190b96a67..89b52476927 100644 --- a/projects/clr/hipamd/include/hip/amd_detail/hip_prof_str.h +++ b/projects/clr/hipamd/include/hip/amd_detail/hip_prof_str.h @@ -483,7 +483,8 @@ enum hip_api_id_t { HIP_API_ID_hipKernelGetAttribute = 457, HIP_API_ID_hipKernelSetAttribute = 458, HIP_API_ID_hipKernelGetFunction = 459, - HIP_API_ID_LAST = 459, + HIP_API_ID_hipMemGetDefaultMemPool = 460, + HIP_API_ID_LAST = 460, HIP_API_ID_hipChooseDevice = HIP_API_ID_CONCAT(HIP_API_ID_,hipChooseDevice), HIP_API_ID_hipGetDeviceProperties = HIP_API_ID_CONCAT(HIP_API_ID_,hipGetDeviceProperties), @@ -795,6 +796,7 @@ static inline const char* hip_api_name(const uint32_t id) { case HIP_API_ID_hipMemGetAddressRange: return "hipMemGetAddressRange"; case HIP_API_ID_hipMemGetAllocationGranularity: return "hipMemGetAllocationGranularity"; case HIP_API_ID_hipMemGetAllocationPropertiesFromHandle: return "hipMemGetAllocationPropertiesFromHandle"; + case HIP_API_ID_hipMemGetDefaultMemPool: return "hipMemGetDefaultMemPool"; case HIP_API_ID_hipMemGetHandleForAddressRange: return "hipMemGetHandleForAddressRange"; case HIP_API_ID_hipMemGetInfo: return "hipMemGetInfo"; case HIP_API_ID_hipMemGetMemPool: return "hipMemGetMemPool"; @@ -1248,6 +1250,7 @@ static inline uint32_t hipApiIdByName(const char* name) { if (strcmp("hipMemGetAddressRange", name) == 0) return HIP_API_ID_hipMemGetAddressRange; if (strcmp("hipMemGetAllocationGranularity", name) == 0) return HIP_API_ID_hipMemGetAllocationGranularity; if (strcmp("hipMemGetAllocationPropertiesFromHandle", name) == 0) return HIP_API_ID_hipMemGetAllocationPropertiesFromHandle; + if (strcmp("hipMemGetDefaultMemPool", name) == 0) return HIP_API_ID_hipMemGetDefaultMemPool; if (strcmp("hipMemGetHandleForAddressRange", name) == 0) return HIP_API_ID_hipMemGetHandleForAddressRange; if (strcmp("hipMemGetInfo", name) == 0) return HIP_API_ID_hipMemGetInfo; if (strcmp("hipMemGetMemPool", name) == 0) return HIP_API_ID_hipMemGetMemPool; @@ -3041,6 +3044,13 @@ typedef struct hip_api_data_s { hipMemAllocationProp prop__val; hipMemGenericAllocationHandle_t handle; } hipMemGetAllocationPropertiesFromHandle; + struct { + hipMemPool_t* memPool; + hipMemPool_t memPool__val; + hipMemLocation* location; + hipMemLocation location__val; + hipMemAllocationType type; + } hipMemGetDefaultMemPool; struct { void* handle; hipDeviceptr_t dptr; @@ -5737,6 +5747,12 @@ typedef struct hip_api_data_s { cb_data.args.hipMemGetAllocationPropertiesFromHandle.prop = (hipMemAllocationProp*)prop; \ cb_data.args.hipMemGetAllocationPropertiesFromHandle.handle = (hipMemGenericAllocationHandle_t)handle; \ }; +// hipMemGetDefaultMemPool[('hipMemPool_t*', 'memPool'), ('hipMemLocation*', 'location'), ('hipMemAllocationType', 'type')] +#define INIT_hipMemGetDefaultMemPool_CB_ARGS_DATA(cb_data) { \ + cb_data.args.hipMemGetDefaultMemPool.memPool = (hipMemPool_t*)memPool; \ + cb_data.args.hipMemGetDefaultMemPool.location = (hipMemLocation*)location; \ + cb_data.args.hipMemGetDefaultMemPool.type = (hipMemAllocationType)type; \ +}; // hipMemGetHandleForAddressRange[('void*', 'handle'), ('hipDeviceptr_t', 'dptr'), ('size_t', 'size'), ('hipMemRangeHandleType', 'handleType'), ('unsigned long long', 'flags')] #define INIT_hipMemGetHandleForAddressRange_CB_ARGS_DATA(cb_data) { \ cb_data.args.hipMemGetHandleForAddressRange.handle = (void*)handle; \ @@ -8040,6 +8056,11 @@ static inline void hipApiArgsInit(hip_api_id_t id, hip_api_data_t* data) { case HIP_API_ID_hipMemGetAllocationPropertiesFromHandle: if (data->args.hipMemGetAllocationPropertiesFromHandle.prop) data->args.hipMemGetAllocationPropertiesFromHandle.prop__val = *(data->args.hipMemGetAllocationPropertiesFromHandle.prop); break; +// hipMemGetDefaultMemPool[('hipMemPool_t*', 'memPool'), ('hipMemLocation*', 'location'), ('hipMemAllocationType', 'type')] + case HIP_API_ID_hipMemGetDefaultMemPool: + if (data->args.hipMemGetDefaultMemPool.memPool) data->args.hipMemGetDefaultMemPool.memPool__val = *(data->args.hipMemGetDefaultMemPool.memPool); + if (data->args.hipMemGetDefaultMemPool.location) data->args.hipMemGetDefaultMemPool.location__val = *(data->args.hipMemGetDefaultMemPool.location); + break; // hipMemGetHandleForAddressRange[('void*', 'handle'), ('hipDeviceptr_t', 'dptr'), ('size_t', 'size'), ('hipMemRangeHandleType', 'handleType'), ('unsigned long long', 'flags')] case HIP_API_ID_hipMemGetHandleForAddressRange: break; @@ -10876,6 +10897,15 @@ static inline const char* hipApiString(hip_api_id_t id, const hip_api_data_t* da oss << ", handle="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMemGetAllocationPropertiesFromHandle.handle); oss << ")"; break; + case HIP_API_ID_hipMemGetDefaultMemPool: + oss << "hipMemGetDefaultMemPool("; + if (data->args.hipMemGetDefaultMemPool.memPool == NULL) oss << "memPool=NULL"; + else { oss << "memPool="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMemGetDefaultMemPool.memPool__val); } + if (data->args.hipMemGetDefaultMemPool.location == NULL) oss << ", location=NULL"; + else { oss << ", location="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMemGetDefaultMemPool.location__val); } + oss << ", type="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMemGetDefaultMemPool.type); + oss << ")"; + break; case HIP_API_ID_hipMemGetHandleForAddressRange: oss << "hipMemGetHandleForAddressRange("; oss << "handle="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMemGetHandleForAddressRange.handle); diff --git a/projects/clr/hipamd/src/amdhip.def b/projects/clr/hipamd/src/amdhip.def index 4d65a48a6a4..f3dc53f09d1 100644 --- a/projects/clr/hipamd/src/amdhip.def +++ b/projects/clr/hipamd/src/amdhip.def @@ -532,3 +532,4 @@ hipMipmappedArrayGetMemoryRequirements hipKernelGetAttribute hipKernelSetAttribute hipKernelGetFunction +hipMemGetDefaultMemPool diff --git a/projects/clr/hipamd/src/hip_api_trace.cpp b/projects/clr/hipamd/src/hip_api_trace.cpp index 80a8e2b9c36..d45373405ff 100644 --- a/projects/clr/hipamd/src/hip_api_trace.cpp +++ b/projects/clr/hipamd/src/hip_api_trace.cpp @@ -881,6 +881,8 @@ hipError_t hipKernelGetAttribute(int* pi, hipFunction_attribute attrib, hipKerne hipDevice_t dev); hipError_t hipKernelSetAttribute(hipFunction_attribute attrib, int value, hipKernel_t kernel, hipDevice_t dev); hipError_t hipKernelGetFunction(hipFunction_t* pFunc, hipKernel_t kernel); +hipError_t hipMemGetDefaultMemPool(hipMemPool_t* memPool, hipMemLocation* location, + hipMemAllocationType type); } // namespace hip namespace hip { @@ -1438,6 +1440,7 @@ void UpdateDispatchTable(HipDispatchTable* ptrDispatchTable) { ptrDispatchTable->hipKernelGetAttribute_fn = hip::hipKernelGetAttribute; ptrDispatchTable->hipKernelSetAttribute_fn = hip::hipKernelSetAttribute; ptrDispatchTable->hipKernelGetFunction_fn = hip::hipKernelGetFunction; + ptrDispatchTable->hipMemGetDefaultMemPool_fn = hip::hipMemGetDefaultMemPool; } #if HIP_ROCPROFILER_REGISTER > 0 @@ -2134,15 +2137,17 @@ HIP_ENFORCE_ABI(HipDispatchTable, hipKernelGetAttribute_fn, 514); // HIP_RUNTIME_API_TABLE_STEP_VERSION == 25 HIP_ENFORCE_ABI(HipDispatchTable, hipKernelSetAttribute_fn, 515); HIP_ENFORCE_ABI(HipDispatchTable, hipKernelGetFunction_fn, 516); +// HIP_RUNTIME_API_TABLE_STEP_VERSION == 26 +HIP_ENFORCE_ABI(HipDispatchTable, hipMemGetDefaultMemPool_fn, 517); // if HIP_ENFORCE_ABI entries are added for each new function pointer in the table, the number below // will be +1 of the number in the last HIP_ENFORCE_ABI line. E.g.: // // HIP_ENFORCE_ABI(, , 8) // // HIP_ENFORCE_ABI_VERSIONING(
, 9) <- 8 + 1 = 9 -HIP_ENFORCE_ABI_VERSIONING(HipDispatchTable, 517) +HIP_ENFORCE_ABI_VERSIONING(HipDispatchTable, 518) -static_assert(HIP_RUNTIME_API_TABLE_MAJOR_VERSION == 0 && HIP_RUNTIME_API_TABLE_STEP_VERSION == 25, +static_assert(HIP_RUNTIME_API_TABLE_MAJOR_VERSION == 0 && HIP_RUNTIME_API_TABLE_STEP_VERSION == 26, "If you get this error, add new HIP_ENFORCE_ABI(...) code for the new function " "pointers and then update this check so it is true"); #endif diff --git a/projects/clr/hipamd/src/hip_hcc.map.in b/projects/clr/hipamd/src/hip_hcc.map.in index 38c19856d1f..8f89ba4dfff 100644 --- a/projects/clr/hipamd/src/hip_hcc.map.in +++ b/projects/clr/hipamd/src/hip_hcc.map.in @@ -654,6 +654,7 @@ global: hipKernelGetAttribute; hipKernelSetAttribute; hipKernelGetFunction; + hipMemGetDefaultMemPool; local: *; } hip_7.1; diff --git a/projects/clr/hipamd/src/hip_mempool.cpp b/projects/clr/hipamd/src/hip_mempool.cpp index 5970cfa76bb..267773034c0 100644 --- a/projects/clr/hipamd/src/hip_mempool.cpp +++ b/projects/clr/hipamd/src/hip_mempool.cpp @@ -546,4 +546,36 @@ hipError_t hipMemGetMemPool(hipMemPool_t* pool, hipMemLocation* location, HIP_RETURN(hipSuccess); } + +// ================================================================================================ +hipError_t hipMemGetDefaultMemPool(hipMemPool_t* memPool, hipMemLocation* location, + hipMemAllocationType type) { + HIP_INIT_API(hipMemGetDefaultMemPool, memPool, location, type); + if (memPool == nullptr || location == nullptr) { + HIP_RETURN(hipErrorInvalidValue); + } + + if (location->type != hipMemLocationTypeDevice) { + HIP_RETURN(hipErrorInvalidValue); + } + + if (location->id < 0 || location->id >= g_devices.size()) { + HIP_RETURN(hipErrorInvalidValue); + } + + switch (type) { + case hipMemAllocationTypePinned: + *memPool = reinterpret_cast( + g_devices[static_cast(location->id)]->GetDefaultMemoryPool()); + break; + case hipMemAllocationTypeManaged: + *memPool = reinterpret_cast( + g_devices[static_cast(location->id)]->GetDefaultManagedMemoryPool()); + break; + default: + HIP_RETURN(hipErrorInvalidValue); + } + + HIP_RETURN(hipSuccess); +} } // namespace hip diff --git a/projects/clr/hipamd/src/hip_table_interface.cpp b/projects/clr/hipamd/src/hip_table_interface.cpp index 7d20d7173a4..1b03cc5156b 100644 --- a/projects/clr/hipamd/src/hip_table_interface.cpp +++ b/projects/clr/hipamd/src/hip_table_interface.cpp @@ -3188,4 +3188,10 @@ hipError_t hipKernelGetFunction(hipFunction_t* pFunc, hipKernel_t kernel) { TRY; return hip::GetHipDispatchTable()->hipKernelGetFunction_fn(pFunc, kernel) ; CATCH; -} \ No newline at end of file +} +hipError_t hipMemGetDefaultMemPool(hipMemPool_t* memPool, hipMemLocation* location, + hipMemAllocationType type) { + TRY; + return hip::GetHipDispatchTable()->hipMemGetDefaultMemPool_fn(memPool, location, type); + CATCH; +} diff --git a/projects/hip/include/hip/hip_runtime_api.h b/projects/hip/include/hip/hip_runtime_api.h index 4ea04816745..720710e0184 100644 --- a/projects/hip/include/hip/hip_runtime_api.h +++ b/projects/hip/include/hip/hip_runtime_api.h @@ -4477,6 +4477,17 @@ hipError_t hipMemSetMemPool(hipMemLocation* location, hipMemAllocationType type, */ hipError_t hipMemGetMemPool(hipMemPool_t* pool, hipMemLocation* location, hipMemAllocationType type); + +/** + * @brief Returns the default memory pool for a given location and allocation type + * + * @param [out] memPool + * @param [in] location + * @param [in] type + */ +hipError_t hipMemGetDefaultMemPool(hipMemPool_t* memPool, hipMemLocation* location, + hipMemAllocationType type); + // Doxygen end of ordered memory allocator /** * @} diff --git a/projects/hipother/hipnv/include/hip/nvidia_detail/nvidia_hip_runtime_api.h b/projects/hipother/hipnv/include/hip/nvidia_detail/nvidia_hip_runtime_api.h index b5174481442..6cc4ed877ea 100644 --- a/projects/hipother/hipnv/include/hip/nvidia_detail/nvidia_hip_runtime_api.h +++ b/projects/hipother/hipnv/include/hip/nvidia_detail/nvidia_hip_runtime_api.h @@ -4161,6 +4161,13 @@ inline static hipError_t hipMemGetMemPool(hipMemPool_t* pool, hipMemLocation* lo CUmemAllocationType cu_allocation_type = cudaMemAllocationTypeToCUmemAllocationType(type); return hipCUResultTohipError(cuMemGetMemPool(pool, &cu_location, cu_allocation_type)); } + +inline static hipError_t hipMemGetDefaultMemPool(hipMemPool_t* memPool, hipMemLocation* location, + hipMemAllocationType type) { + CUmemLocation cu_location = cudaMemLocationToCUmemLocation(location); + CUmemAllocationType cu_allocation_type = cudaMemAllocationTypeToCUmemAllocationType(type); + return hipCUResultTohipError(cuMemGetDefaultMemPool(memPool, &cu_location, cu_allocation_type)); +} #endif // CUDA_VERSION >= CUDA_13000 #ifdef __cplusplus diff --git a/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/cxx/enum_string.hpp b/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/cxx/enum_string.hpp index 3a3aa72f26a..822bd7e3fb7 100644 --- a/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/cxx/enum_string.hpp +++ b/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/cxx/enum_string.hpp @@ -1075,6 +1075,9 @@ ROCPROFILER_ENUM_LABEL(ROCPROFILER_HIP_RUNTIME_API_ID_hipKernelGetAttribute) ROCPROFILER_ENUM_LABEL(ROCPROFILER_HIP_RUNTIME_API_ID_hipKernelSetAttribute) ROCPROFILER_ENUM_LABEL(ROCPROFILER_HIP_RUNTIME_API_ID_hipKernelGetFunction) #endif +#if HIP_RUNTIME_API_TABLE_STEP_VERSION >= 26 +ROCPROFILER_ENUM_LABEL(ROCPROFILER_HIP_RUNTIME_API_ID_hipMemGetDefaultMemPool) +#endif #if HIP_RUNTIME_API_TABLE_STEP_VERSION == 0 static_assert(ROCPROFILER_HIP_RUNTIME_API_ID_LAST == 442); #elif HIP_RUNTIME_API_TABLE_STEP_VERSION == 1 @@ -1127,6 +1130,8 @@ static_assert(ROCPROFILER_HIP_RUNTIME_API_ID_LAST == 514); static_assert(ROCPROFILER_HIP_RUNTIME_API_ID_LAST == 515); #elif HIP_RUNTIME_API_TABLE_STEP_VERSION == 25 static_assert(ROCPROFILER_HIP_RUNTIME_API_ID_LAST == 517); +#elif HIP_RUNTIME_API_TABLE_STEP_VERSION == 26 +static_assert(ROCPROFILER_HIP_RUNTIME_API_ID_LAST == 518); #else # if !defined(ROCPROFILER_UNSAFE_NO_VERSION_CHECK) && \ (defined(ROCPROFILER_CI) && ROCPROFILER_CI > 0) diff --git a/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/hip/api_args.h b/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/hip/api_args.h index 43b3eaa022e..8ddaae7fd6d 100644 --- a/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/hip/api_args.h +++ b/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/hip/api_args.h @@ -3442,6 +3442,15 @@ typedef union rocprofiler_hip_api_args_t hipKernel_t kernel; } hipKernelGetFunction; #endif +#if HIP_RUNTIME_API_TABLE_STEP_VERSION >= 26 + struct + { + hipMemPool_t* memPool; + hipMemLocation* location; + hipMemAllocationType type; + } hipMemGetDefaultMemPool; + +#endif } rocprofiler_hip_api_args_t; ROCPROFILER_EXTERN_C_FINI diff --git a/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/hip/runtime_api_id.h b/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/hip/runtime_api_id.h index c81dad861b0..7c8877a5a52 100644 --- a/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/hip/runtime_api_id.h +++ b/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/hip/runtime_api_id.h @@ -594,6 +594,9 @@ typedef enum rocprofiler_hip_runtime_api_id_t // NOLINT(performance-enum-size) #if HIP_RUNTIME_API_TABLE_STEP_VERSION >= 25 ROCPROFILER_HIP_RUNTIME_API_ID_hipKernelSetAttribute, ROCPROFILER_HIP_RUNTIME_API_ID_hipKernelGetFunction, +#endif +#if HIP_RUNTIME_API_TABLE_STEP_VERSION >= 26 + ROCPROFILER_HIP_RUNTIME_API_ID_hipMemGetDefaultMemPool, #endif ROCPROFILER_HIP_RUNTIME_API_ID_LAST, } rocprofiler_hip_runtime_api_id_t; diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/hip/abi.cpp b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/hip/abi.cpp index 4e790fe5d6c..9e7f8b99410 100644 --- a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/hip/abi.cpp +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/hip/abi.cpp @@ -645,6 +645,10 @@ ROCP_SDK_ENFORCE_ABI(::HipDispatchTable, hipKernelSetAttribute_fn, 515); ROCP_SDK_ENFORCE_ABI(::HipDispatchTable, hipKernelGetFunction_fn, 516); #endif +#if HIP_RUNTIME_API_TABLE_STEP_VERSION >= 26 +ROCP_SDK_ENFORCE_ABI(::HipDispatchTable, hipMemGetDefaultMemPool_fn, 517); +#endif + #if HIP_RUNTIME_API_TABLE_STEP_VERSION == 0 ROCP_SDK_ENFORCE_ABI_VERSIONING(::HipDispatchTable, 442) #elif HIP_RUNTIME_API_TABLE_STEP_VERSION == 1 @@ -697,6 +701,8 @@ ROCP_SDK_ENFORCE_ABI_VERSIONING(::HipDispatchTable, 514) ROCP_SDK_ENFORCE_ABI_VERSIONING(::HipDispatchTable, 515) #elif HIP_RUNTIME_API_TABLE_STEP_VERSION == 25 ROCP_SDK_ENFORCE_ABI_VERSIONING(::HipDispatchTable, 517) +#elif HIP_RUNTIME_API_TABLE_STEP_VERSION == 26 +ROCP_SDK_ENFORCE_ABI_VERSIONING(::HipDispatchTable, 518) #else INTERNAL_CI_ROCP_SDK_ENFORCE_ABI_VERSIONING(::HipDispatchTable, 0) #endif diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/hip/hip.def.cpp b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/hip/hip.def.cpp index edabb2ed073..8651bd62ff1 100644 --- a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/hip/hip.def.cpp +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/hip/hip.def.cpp @@ -673,6 +673,10 @@ HIP_API_INFO_DEFINITION_V(ROCPROFILER_HIP_TABLE_ID_Runtime, ROCPROFILER_HIP_RUNT HIP_API_INFO_DEFINITION_V(ROCPROFILER_HIP_TABLE_ID_Runtime, ROCPROFILER_HIP_RUNTIME_API_ID_hipKernelSetAttribute, hipKernelSetAttribute, hipKernelSetAttribute_fn, attrib, value, kernel, dev); HIP_API_INFO_DEFINITION_V(ROCPROFILER_HIP_TABLE_ID_Runtime, ROCPROFILER_HIP_RUNTIME_API_ID_hipKernelGetFunction, hipKernelGetFunction, hipKernelGetFunction_fn, pFunc, kernel); #endif + +#if HIP_RUNTIME_API_TABLE_STEP_VERSION >= 26 +HIP_API_INFO_DEFINITION_V(ROCPROFILER_HIP_TABLE_ID_Runtime, ROCPROFILER_HIP_RUNTIME_API_ID_hipMemGetDefaultMemPool, hipMemGetDefaultMemPool, hipMemGetDefaultMemPool_fn, memPool, location, type); +#endif // clang-format on #else From b65a1f79187844801011cae686d6e36b885cc4aa Mon Sep 17 00:00:00 2001 From: Sebastian Luzynski Date: Fri, 13 Mar 2026 08:14:20 +0000 Subject: [PATCH 2/2] Add unit tests for hipMemGetDefaultMemPool API This change adds 2 new tests: - Unit_hipMemGetDefaultMemPool_Negative - Unit_hipMemGetDefaultMemPool_Basic Signed-off-by: Sebastian Luzynski --- .../catch/config/configs/unit/memory.yaml | 2 + .../catch/unit/memory/CMakeLists.txt | 3 +- .../unit/memory/hipMemGetDefaultMemPool.cc | 97 +++++++++++++++++++ .../include/rocprofiler-sdk/hip/api_args.h | 1 - 4 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 projects/hip-tests/catch/unit/memory/hipMemGetDefaultMemPool.cc diff --git a/projects/hip-tests/catch/config/configs/unit/memory.yaml b/projects/hip-tests/catch/config/configs/unit/memory.yaml index 56fa12df939..f645372b41c 100644 --- a/projects/hip-tests/catch/config/configs/unit/memory.yaml +++ b/projects/hip-tests/catch/config/configs/unit/memory.yaml @@ -1242,3 +1242,5 @@ memory: Unit_hipMemGetMemPool_Basic: *level_2 Unit_hipMemSetMemPool_Negative: *level_2 Unit_hipMemSetMemPool_Basic: *level_2 + Unit_hipMemGetDefaultMemPool_Negative: *level_2 + Unit_hipMemGetDefaultMemPool_Basic: *level_2 diff --git a/projects/hip-tests/catch/unit/memory/CMakeLists.txt b/projects/hip-tests/catch/unit/memory/CMakeLists.txt index b2a8fb2523f..bfc92e83259 100644 --- a/projects/hip-tests/catch/unit/memory/CMakeLists.txt +++ b/projects/hip-tests/catch/unit/memory/CMakeLists.txt @@ -195,7 +195,8 @@ set(TEST_SRC hipFreeMipmappedArray.cc hipHostAlloc.cc hipMemSetMemPool.cc - hipMemGetMemPool.cc) + hipMemGetMemPool.cc + hipMemGetDefaultMemPool.cc) if(HIP_PLATFORM MATCHES "amd") set(TEST_SRC diff --git a/projects/hip-tests/catch/unit/memory/hipMemGetDefaultMemPool.cc b/projects/hip-tests/catch/unit/memory/hipMemGetDefaultMemPool.cc new file mode 100644 index 00000000000..01b57f33436 --- /dev/null +++ b/projects/hip-tests/catch/unit/memory/hipMemGetDefaultMemPool.cc @@ -0,0 +1,97 @@ +/* +Copyright (c) 2026 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of intge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include +#include "mempool_common.hh" + +/** + * @addtogroup hipMemGetDefaultMemPool hipMemGetDefaultMemPool + * @{ + * @ingroup MemoryTest + * `hipError_t hipMemGetDefaultMemPool(hipMemPool_t* memPool, hipMemLocation* location, + hipMemAllocationType type)` - + * Gets the default memory pool for the location and allocation type. + */ + +TEST_CASE("Unit_hipMemGetDefaultMemPool_Negative") { + int dev; + HIP_CHECK(hipGetDevice(&dev)); + + hipMemPool_t memPool; + hipMemLocation location{}; + location.id = dev; + location.type = hipMemLocationTypeDevice; + hipMemAllocationType allocationType = hipMemAllocationTypePinned; + + SECTION("Invalid memPool") { + HIP_CHECK_ERROR(hipMemGetDefaultMemPool(nullptr, &location, allocationType), + hipErrorInvalidValue); + } + + SECTION("Invalid location") { + HIP_CHECK_ERROR(hipMemGetDefaultMemPool(&memPool, nullptr, allocationType), + hipErrorInvalidValue); + + location.id = -1; + HIP_CHECK_ERROR(hipMemGetDefaultMemPool(&memPool, &location, allocationType), + hipErrorInvalidValue); + + location.id = dev; + location.type = hipMemLocationTypeNone; + HIP_CHECK_ERROR(hipMemGetDefaultMemPool(&memPool, &location, allocationType), + hipErrorInvalidValue); + } + + SECTION("Invalid allocation type") { + HIP_CHECK_ERROR(hipMemGetDefaultMemPool(&memPool, &location, hipMemAllocationTypeInvalid), + hipErrorInvalidValue); + } +} + +TEST_CASE("Unit_hipMemGetDefaultMemPool_Basic") { + int dev; + HIP_CHECK(hipGetDevice(&dev)); + + hipMemLocation location{}; + location.id = dev; + location.type = hipMemLocationTypeDevice; + + SECTION("Pinned") { + auto alloc_type = hipMemAllocationTypePinned; + hipMemPool_t memPool; + hipMemPool_t deviceMemPool; + + + HIP_CHECK(hipMemGetDefaultMemPool(&memPool, &location, alloc_type)); + REQUIRE(memPool != nullptr); + HIP_CHECK(hipDeviceGetDefaultMemPool(&deviceMemPool, dev)); + REQUIRE(deviceMemPool != nullptr); + REQUIRE(memPool == deviceMemPool); + } + + SECTION("Managed") { + auto alloc_type = hipMemAllocationTypeManaged; + hipMemPool_t memPool; + HIP_CHECK(hipMemGetDefaultMemPool(&memPool, &location, alloc_type)); + REQUIRE(memPool != nullptr); + } +} diff --git a/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/hip/api_args.h b/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/hip/api_args.h index 8ddaae7fd6d..509ab524129 100644 --- a/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/hip/api_args.h +++ b/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/hip/api_args.h @@ -3449,7 +3449,6 @@ typedef union rocprofiler_hip_api_args_t hipMemLocation* location; hipMemAllocationType type; } hipMemGetDefaultMemPool; - #endif } rocprofiler_hip_api_args_t;