Skip to content

Commit ff370e7

Browse files
committed
[hip][AIRUNTIME-748] Implement hipMemGetDefaultMemPool api
This change adds new api hipMemGetDefaultMemPool to the runtime Signed-off-by: Sebastian Luzynski <sebastian.luzynski@amd.com>
1 parent c3796ce commit ff370e7

File tree

14 files changed

+131
-6
lines changed

14 files changed

+131
-6
lines changed

projects/clr/hipamd/include/hip/amd_detail/hip_api_trace.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#define HIP_API_TABLE_STEP_VERSION 0
4848
#define HIP_COMPILER_API_TABLE_STEP_VERSION 0
4949
#define HIP_TOOLS_API_TABLE_STEP_VERSION 0
50-
#define HIP_RUNTIME_API_TABLE_STEP_VERSION 25
50+
#define HIP_RUNTIME_API_TABLE_STEP_VERSION 26
5151

5252
// HIP API interface
5353
// HIP compiler dispatch functions
@@ -1116,6 +1116,8 @@ typedef hipError_t (*t_hipMemGetMemPool)(hipMemPool_t* pool, hipMemLocation* loc
11161116
hipMemAllocationType type);
11171117
typedef hipError_t (*t_hipMipmappedArrayGetMemoryRequirements)(
11181118
hipArrayMemoryRequirements* memoryRequirements, hipMipmappedArray_t mipmap, hipDevice_t device);
1119+
typedef hipError_t (*t_hipMemGetDefaultMemPool)(hipMemPool_t* memPool, hipMemLocation* location,
1120+
hipMemAllocationType type);
11191121
// HIP Compiler dispatch table
11201122
struct HipCompilerDispatchTable {
11211123
// HIP_COMPILER_API_TABLE_STEP_VERSION == 0
@@ -1727,8 +1729,11 @@ struct HipDispatchTable {
17271729
t_hipKernelSetAttribute hipKernelSetAttribute_fn;
17281730
t_hipKernelGetFunction hipKernelGetFunction_fn;
17291731

1732+
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 26
1733+
t_hipMemGetDefaultMemPool hipMemGetDefaultMemPool_fn;
1734+
17301735
// DO NOT EDIT ABOVE!
1731-
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 25
1736+
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 27
17321737

17331738
// ******************************************************************************************* //
17341739
//

projects/clr/hipamd/include/hip/amd_detail/hip_prof_str.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,8 @@ enum hip_api_id_t {
482482
HIP_API_ID_hipKernelGetAttribute = 457,
483483
HIP_API_ID_hipKernelSetAttribute = 458,
484484
HIP_API_ID_hipKernelGetFunction = 459,
485-
HIP_API_ID_LAST = 459,
485+
HIP_API_ID_hipMemGetDefaultMemPool = 460,
486+
HIP_API_ID_LAST = 460,
486487

487488
HIP_API_ID_hipChooseDevice = HIP_API_ID_CONCAT(HIP_API_ID_,hipChooseDevice),
488489
HIP_API_ID_hipGetDeviceProperties = HIP_API_ID_CONCAT(HIP_API_ID_,hipGetDeviceProperties),
@@ -794,6 +795,7 @@ static inline const char* hip_api_name(const uint32_t id) {
794795
case HIP_API_ID_hipMemGetAddressRange: return "hipMemGetAddressRange";
795796
case HIP_API_ID_hipMemGetAllocationGranularity: return "hipMemGetAllocationGranularity";
796797
case HIP_API_ID_hipMemGetAllocationPropertiesFromHandle: return "hipMemGetAllocationPropertiesFromHandle";
798+
case HIP_API_ID_hipMemGetDefaultMemPool: return "hipMemGetDefaultMemPool";
797799
case HIP_API_ID_hipMemGetHandleForAddressRange: return "hipMemGetHandleForAddressRange";
798800
case HIP_API_ID_hipMemGetInfo: return "hipMemGetInfo";
799801
case HIP_API_ID_hipMemGetMemPool: return "hipMemGetMemPool";
@@ -1247,6 +1249,7 @@ static inline uint32_t hipApiIdByName(const char* name) {
12471249
if (strcmp("hipMemGetAddressRange", name) == 0) return HIP_API_ID_hipMemGetAddressRange;
12481250
if (strcmp("hipMemGetAllocationGranularity", name) == 0) return HIP_API_ID_hipMemGetAllocationGranularity;
12491251
if (strcmp("hipMemGetAllocationPropertiesFromHandle", name) == 0) return HIP_API_ID_hipMemGetAllocationPropertiesFromHandle;
1252+
if (strcmp("hipMemGetDefaultMemPool", name) == 0) return HIP_API_ID_hipMemGetDefaultMemPool;
12501253
if (strcmp("hipMemGetHandleForAddressRange", name) == 0) return HIP_API_ID_hipMemGetHandleForAddressRange;
12511254
if (strcmp("hipMemGetInfo", name) == 0) return HIP_API_ID_hipMemGetInfo;
12521255
if (strcmp("hipMemGetMemPool", name) == 0) return HIP_API_ID_hipMemGetMemPool;
@@ -3040,6 +3043,13 @@ typedef struct hip_api_data_s {
30403043
hipMemAllocationProp prop__val;
30413044
hipMemGenericAllocationHandle_t handle;
30423045
} hipMemGetAllocationPropertiesFromHandle;
3046+
struct {
3047+
hipMemPool_t* memPool;
3048+
hipMemPool_t memPool__val;
3049+
hipMemLocation* location;
3050+
hipMemLocation location__val;
3051+
hipMemAllocationType type;
3052+
} hipMemGetDefaultMemPool;
30433053
struct {
30443054
void* handle;
30453055
hipDeviceptr_t dptr;
@@ -5736,6 +5746,12 @@ typedef struct hip_api_data_s {
57365746
cb_data.args.hipMemGetAllocationPropertiesFromHandle.prop = (hipMemAllocationProp*)prop; \
57375747
cb_data.args.hipMemGetAllocationPropertiesFromHandle.handle = (hipMemGenericAllocationHandle_t)handle; \
57385748
};
5749+
// hipMemGetDefaultMemPool[('hipMemPool_t*', 'memPool'), ('hipMemLocation*', 'location'), ('hipMemAllocationType', 'type')]
5750+
#define INIT_hipMemGetDefaultMemPool_CB_ARGS_DATA(cb_data) { \
5751+
cb_data.args.hipMemGetDefaultMemPool.memPool = (hipMemPool_t*)memPool; \
5752+
cb_data.args.hipMemGetDefaultMemPool.location = (hipMemLocation*)location; \
5753+
cb_data.args.hipMemGetDefaultMemPool.type = (hipMemAllocationType)type; \
5754+
};
57395755
// hipMemGetHandleForAddressRange[('void*', 'handle'), ('hipDeviceptr_t', 'dptr'), ('size_t', 'size'), ('hipMemRangeHandleType', 'handleType'), ('unsigned long long', 'flags')]
57405756
#define INIT_hipMemGetHandleForAddressRange_CB_ARGS_DATA(cb_data) { \
57415757
cb_data.args.hipMemGetHandleForAddressRange.handle = (void*)handle; \
@@ -8039,6 +8055,11 @@ static inline void hipApiArgsInit(hip_api_id_t id, hip_api_data_t* data) {
80398055
case HIP_API_ID_hipMemGetAllocationPropertiesFromHandle:
80408056
if (data->args.hipMemGetAllocationPropertiesFromHandle.prop) data->args.hipMemGetAllocationPropertiesFromHandle.prop__val = *(data->args.hipMemGetAllocationPropertiesFromHandle.prop);
80418057
break;
8058+
// hipMemGetDefaultMemPool[('hipMemPool_t*', 'memPool'), ('hipMemLocation*', 'location'), ('hipMemAllocationType', 'type')]
8059+
case HIP_API_ID_hipMemGetDefaultMemPool:
8060+
if (data->args.hipMemGetDefaultMemPool.memPool) data->args.hipMemGetDefaultMemPool.memPool__val = *(data->args.hipMemGetDefaultMemPool.memPool);
8061+
if (data->args.hipMemGetDefaultMemPool.location) data->args.hipMemGetDefaultMemPool.location__val = *(data->args.hipMemGetDefaultMemPool.location);
8062+
break;
80428063
// hipMemGetHandleForAddressRange[('void*', 'handle'), ('hipDeviceptr_t', 'dptr'), ('size_t', 'size'), ('hipMemRangeHandleType', 'handleType'), ('unsigned long long', 'flags')]
80438064
case HIP_API_ID_hipMemGetHandleForAddressRange:
80448065
break;
@@ -10875,6 +10896,15 @@ static inline const char* hipApiString(hip_api_id_t id, const hip_api_data_t* da
1087510896
oss << ", handle="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMemGetAllocationPropertiesFromHandle.handle);
1087610897
oss << ")";
1087710898
break;
10899+
case HIP_API_ID_hipMemGetDefaultMemPool:
10900+
oss << "hipMemGetDefaultMemPool(";
10901+
if (data->args.hipMemGetDefaultMemPool.memPool == NULL) oss << "memPool=NULL";
10902+
else { oss << "memPool="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMemGetDefaultMemPool.memPool__val); }
10903+
if (data->args.hipMemGetDefaultMemPool.location == NULL) oss << ", location=NULL";
10904+
else { oss << ", location="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMemGetDefaultMemPool.location__val); }
10905+
oss << ", type="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMemGetDefaultMemPool.type);
10906+
oss << ")";
10907+
break;
1087810908
case HIP_API_ID_hipMemGetHandleForAddressRange:
1087910909
oss << "hipMemGetHandleForAddressRange(";
1088010910
oss << "handle="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMemGetHandleForAddressRange.handle);

projects/clr/hipamd/src/amdhip.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,3 +532,4 @@ hipMipmappedArrayGetMemoryRequirements
532532
hipKernelGetAttribute
533533
hipKernelSetAttribute
534534
hipKernelGetFunction
535+
hipMemGetDefaultMemPool

projects/clr/hipamd/src/hip_api_trace.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,8 @@ hipError_t hipKernelGetAttribute(int* pi, hipFunction_attribute attrib, hipKerne
897897
hipDevice_t dev);
898898
hipError_t hipKernelSetAttribute(hipFunction_attribute attrib, int value, hipKernel_t kernel, hipDevice_t dev);
899899
hipError_t hipKernelGetFunction(hipFunction_t* pFunc, hipKernel_t kernel);
900+
hipError_t hipMemGetDefaultMemPool(hipMemPool_t* memPool, hipMemLocation* location,
901+
hipMemAllocationType type);
900902
} // namespace hip
901903

902904
namespace hip {
@@ -1454,6 +1456,7 @@ void UpdateDispatchTable(HipDispatchTable* ptrDispatchTable) {
14541456
ptrDispatchTable->hipKernelGetAttribute_fn = hip::hipKernelGetAttribute;
14551457
ptrDispatchTable->hipKernelSetAttribute_fn = hip::hipKernelSetAttribute;
14561458
ptrDispatchTable->hipKernelGetFunction_fn = hip::hipKernelGetFunction;
1459+
ptrDispatchTable->hipMemGetDefaultMemPool_fn = hip::hipMemGetDefaultMemPool;
14571460
}
14581461

14591462
#if HIP_ROCPROFILER_REGISTER > 0
@@ -2150,15 +2153,17 @@ HIP_ENFORCE_ABI(HipDispatchTable, hipKernelGetAttribute_fn, 514);
21502153
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 25
21512154
HIP_ENFORCE_ABI(HipDispatchTable, hipKernelSetAttribute_fn, 515);
21522155
HIP_ENFORCE_ABI(HipDispatchTable, hipKernelGetFunction_fn, 516);
2156+
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 26
2157+
HIP_ENFORCE_ABI(HipDispatchTable, hipMemGetDefaultMemPool_fn, 517);
21532158
// if HIP_ENFORCE_ABI entries are added for each new function pointer in the table, the number below
21542159
// will be +1 of the number in the last HIP_ENFORCE_ABI line. E.g.:
21552160
//
21562161
// HIP_ENFORCE_ABI(<table>, <functor>, 8)
21572162
//
21582163
// HIP_ENFORCE_ABI_VERSIONING(<table>, 9) <- 8 + 1 = 9
2159-
HIP_ENFORCE_ABI_VERSIONING(HipDispatchTable, 517)
2164+
HIP_ENFORCE_ABI_VERSIONING(HipDispatchTable, 518)
21602165

2161-
static_assert(HIP_RUNTIME_API_TABLE_MAJOR_VERSION == 0 && HIP_RUNTIME_API_TABLE_STEP_VERSION == 25,
2166+
static_assert(HIP_RUNTIME_API_TABLE_MAJOR_VERSION == 0 && HIP_RUNTIME_API_TABLE_STEP_VERSION == 26,
21622167
"If you get this error, add new HIP_ENFORCE_ABI(...) code for the new function "
21632168
"pointers and then update this check so it is true");
21642169
#endif

projects/clr/hipamd/src/hip_hcc.map.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ global:
654654
hipKernelGetAttribute;
655655
hipKernelSetAttribute;
656656
hipKernelGetFunction;
657+
hipMemGetDefaultMemPool;
657658
local:
658659
*;
659660
} hip_7.1;

projects/clr/hipamd/src/hip_mempool.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,4 +560,36 @@ hipError_t hipMemGetMemPool(hipMemPool_t* pool, hipMemLocation* location,
560560

561561
HIP_RETURN(hipSuccess);
562562
}
563+
564+
// ================================================================================================
565+
hipError_t hipMemGetDefaultMemPool(hipMemPool_t* memPool, hipMemLocation* location,
566+
hipMemAllocationType type) {
567+
HIP_INIT_API(hipMemGetDefaultMemPool, memPool, location, type);
568+
if (memPool == nullptr || location == nullptr) {
569+
HIP_RETURN(hipErrorInvalidValue);
570+
}
571+
572+
if (location->type != hipMemLocationTypeDevice) {
573+
HIP_RETURN(hipErrorInvalidValue);
574+
}
575+
576+
if (location->id < 0 || location->id >= g_devices.size()) {
577+
HIP_RETURN(hipErrorInvalidValue);
578+
}
579+
580+
switch (type) {
581+
case hipMemAllocationTypePinned:
582+
*memPool = reinterpret_cast<hipMemPool_t>(
583+
g_devices[static_cast<std::size_t>(location->id)]->GetDefaultMemoryPool());
584+
break;
585+
case hipMemAllocationTypeManaged:
586+
*memPool = reinterpret_cast<hipMemPool_t>(
587+
g_devices[static_cast<std::size_t>(location->id)]->GetDefaultManagedMemoryPool());
588+
break;
589+
default:
590+
HIP_RETURN(hipErrorInvalidValue);
591+
}
592+
593+
HIP_RETURN(hipSuccess);
594+
}
563595
} // namespace hip

projects/clr/hipamd/src/hip_table_interface.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3203,4 +3203,10 @@ hipError_t hipKernelGetFunction(hipFunction_t* pFunc, hipKernel_t kernel) {
32033203
TRY;
32043204
return hip::GetHipDispatchTable()->hipKernelGetFunction_fn(pFunc, kernel) ;
32053205
CATCH;
3206-
}
3206+
}
3207+
hipError_t hipMemGetDefaultMemPool(hipMemPool_t* memPool, hipMemLocation* location,
3208+
hipMemAllocationType type) {
3209+
TRY;
3210+
return hip::GetHipDispatchTable()->hipMemGetDefaultMemPool_fn(memPool, location, type);
3211+
CATCH;
3212+
}

projects/hip/include/hip/hip_runtime_api.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4477,6 +4477,17 @@ hipError_t hipMemSetMemPool(hipMemLocation* location, hipMemAllocationType type,
44774477
*/
44784478
hipError_t hipMemGetMemPool(hipMemPool_t* pool, hipMemLocation* location,
44794479
hipMemAllocationType type);
4480+
4481+
/**
4482+
* @brief Returns the default memory pool for a given location and allocation type
4483+
*
4484+
* @param [out] memPool
4485+
* @param [in] location
4486+
* @param [in] type
4487+
*/
4488+
hipError_t hipMemGetDefaultMemPool(hipMemPool_t* memPool, hipMemLocation* location,
4489+
hipMemAllocationType type);
4490+
44804491
// Doxygen end of ordered memory allocator
44814492
/**
44824493
* @}

projects/hipother/hipnv/include/hip/nvidia_detail/nvidia_hip_runtime_api.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4177,6 +4177,13 @@ inline static hipError_t hipMemGetMemPool(hipMemPool_t* pool, hipMemLocation* lo
41774177
CUmemAllocationType cu_allocation_type = cudaMemAllocationTypeToCUmemAllocationType(type);
41784178
return hipCUResultTohipError(cuMemGetMemPool(pool, &cu_location, cu_allocation_type));
41794179
}
4180+
4181+
inline static hipError_t hipMemGetDefaultMemPool(hipMemPool_t* memPool, hipMemLocation* location,
4182+
hipMemAllocationType type) {
4183+
CUmemLocation cu_location = cudaMemLocationToCUmemLocation(location);
4184+
CUmemAllocationType cu_allocation_type = cudaMemAllocationTypeToCUmemAllocationType(type);
4185+
return hipCUResultTohipError(cuMemGetDefaultMemPool(memPool, &cu_location, cu_allocation_type));
4186+
}
41804187
#endif // CUDA_VERSION >= CUDA_13000
41814188

41824189
#ifdef __cplusplus

projects/rocprofiler-sdk/source/include/rocprofiler-sdk/cxx/enum_string.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,9 @@ ROCPROFILER_ENUM_LABEL(ROCPROFILER_HIP_RUNTIME_API_ID_hipKernelGetAttribute)
10751075
ROCPROFILER_ENUM_LABEL(ROCPROFILER_HIP_RUNTIME_API_ID_hipKernelSetAttribute)
10761076
ROCPROFILER_ENUM_LABEL(ROCPROFILER_HIP_RUNTIME_API_ID_hipKernelGetFunction)
10771077
#endif
1078+
#if HIP_RUNTIME_API_TABLE_STEP_VERSION >= 26
1079+
ROCPROFILER_ENUM_LABEL(ROCPROFILER_HIP_RUNTIME_API_ID_hipMemGetDefaultMemPool)
1080+
#endif
10781081
#if HIP_RUNTIME_API_TABLE_STEP_VERSION == 0
10791082
static_assert(ROCPROFILER_HIP_RUNTIME_API_ID_LAST == 442);
10801083
#elif HIP_RUNTIME_API_TABLE_STEP_VERSION == 1
@@ -1127,6 +1130,8 @@ static_assert(ROCPROFILER_HIP_RUNTIME_API_ID_LAST == 514);
11271130
static_assert(ROCPROFILER_HIP_RUNTIME_API_ID_LAST == 515);
11281131
#elif HIP_RUNTIME_API_TABLE_STEP_VERSION == 25
11291132
static_assert(ROCPROFILER_HIP_RUNTIME_API_ID_LAST == 517);
1133+
#elif HIP_RUNTIME_API_TABLE_STEP_VERSION == 26
1134+
static_assert(ROCPROFILER_HIP_RUNTIME_API_ID_LAST == 518);
11301135
#else
11311136
# if !defined(ROCPROFILER_UNSAFE_NO_VERSION_CHECK) && \
11321137
(defined(ROCPROFILER_CI) && ROCPROFILER_CI > 0)

0 commit comments

Comments
 (0)