Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

// ******************************************************************************************* //
//
Expand Down
32 changes: 31 additions & 1 deletion projects/clr/hipamd/include/hip/amd_detail/hip_prof_str.h
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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; \
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions projects/clr/hipamd/src/amdhip.def
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,4 @@ hipMipmappedArrayGetMemoryRequirements
hipKernelGetAttribute
hipKernelSetAttribute
hipKernelGetFunction
hipMemGetDefaultMemPool
9 changes: 7 additions & 2 deletions projects/clr/hipamd/src/hip_api_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(<table>, <functor>, 8)
//
// HIP_ENFORCE_ABI_VERSIONING(<table>, 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
1 change: 1 addition & 0 deletions projects/clr/hipamd/src/hip_hcc.map.in
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ global:
hipKernelGetAttribute;
hipKernelSetAttribute;
hipKernelGetFunction;
hipMemGetDefaultMemPool;
local:
*;
} hip_7.1;
32 changes: 32 additions & 0 deletions projects/clr/hipamd/src/hip_mempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<hipMemPool_t>(
g_devices[static_cast<std::size_t>(location->id)]->GetDefaultMemoryPool());
break;
case hipMemAllocationTypeManaged:
*memPool = reinterpret_cast<hipMemPool_t>(
g_devices[static_cast<std::size_t>(location->id)]->GetDefaultManagedMemoryPool());
break;
default:
HIP_RETURN(hipErrorInvalidValue);
}

HIP_RETURN(hipSuccess);
}
} // namespace hip
8 changes: 7 additions & 1 deletion projects/clr/hipamd/src/hip_table_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3188,4 +3188,10 @@ hipError_t hipKernelGetFunction(hipFunction_t* pFunc, hipKernel_t kernel) {
TRY;
return hip::GetHipDispatchTable()->hipKernelGetFunction_fn(pFunc, kernel) ;
CATCH;
}
}
hipError_t hipMemGetDefaultMemPool(hipMemPool_t* memPool, hipMemLocation* location,
hipMemAllocationType type) {
TRY;
return hip::GetHipDispatchTable()->hipMemGetDefaultMemPool_fn(memPool, location, type);
CATCH;
}
2 changes: 2 additions & 0 deletions projects/hip-tests/catch/config/configs/unit/memory.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2446,6 +2446,8 @@ 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
Unit_hipFreeHost_Capture_negative:
<<: *level_2
# Huge memory usage, no point enabling them with ASAN
Expand Down
3 changes: 2 additions & 1 deletion projects/hip-tests/catch/unit/memory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
97 changes: 97 additions & 0 deletions projects/hip-tests/catch/unit/memory/hipMemGetDefaultMemPool.cc
Original file line number Diff line number Diff line change
@@ -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 <hip_test_common.hh>
#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);
}
}
11 changes: 11 additions & 0 deletions projects/hip/include/hip/hip_runtime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
/**
* @}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3442,6 +3442,14 @@ 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
Loading
Loading