Skip to content

Commit 8da9c60

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 24d77fe commit 8da9c60

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
@@ -48,7 +48,7 @@
4848
#define HIP_API_TABLE_STEP_VERSION 0
4949
#define HIP_COMPILER_API_TABLE_STEP_VERSION 0
5050
#define HIP_TOOLS_API_TABLE_STEP_VERSION 0
51-
#define HIP_RUNTIME_API_TABLE_STEP_VERSION 25
51+
#define HIP_RUNTIME_API_TABLE_STEP_VERSION 26
5252

5353
// HIP API interface
5454
// HIP compiler dispatch functions
@@ -1117,6 +1117,8 @@ typedef hipError_t (*t_hipMemGetMemPool)(hipMemPool_t* pool, hipMemLocation* loc
11171117
hipMemAllocationType type);
11181118
typedef hipError_t (*t_hipMipmappedArrayGetMemoryRequirements)(
11191119
hipArrayMemoryRequirements* memoryRequirements, hipMipmappedArray_t mipmap, hipDevice_t device);
1120+
typedef hipError_t (*t_hipMemGetDefaultMemPool)(hipMemPool_t* memPool, hipMemLocation* location,
1121+
hipMemAllocationType type);
11201122
// HIP Compiler dispatch table
11211123
struct HipCompilerDispatchTable {
11221124
// HIP_COMPILER_API_TABLE_STEP_VERSION == 0
@@ -1728,8 +1730,11 @@ struct HipDispatchTable {
17281730
t_hipKernelSetAttribute hipKernelSetAttribute_fn;
17291731
t_hipKernelGetFunction hipKernelGetFunction_fn;
17301732

1733+
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 26
1734+
t_hipMemGetDefaultMemPool hipMemGetDefaultMemPool_fn;
1735+
17311736
// DO NOT EDIT ABOVE!
1732-
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 25
1737+
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 27
17331738

17341739
// ******************************************************************************************* //
17351740
//

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
@@ -483,7 +483,8 @@ enum hip_api_id_t {
483483
HIP_API_ID_hipKernelGetAttribute = 457,
484484
HIP_API_ID_hipKernelSetAttribute = 458,
485485
HIP_API_ID_hipKernelGetFunction = 459,
486-
HIP_API_ID_LAST = 459,
486+
HIP_API_ID_hipMemGetDefaultMemPool = 460,
487+
HIP_API_ID_LAST = 460,
487488

488489
HIP_API_ID_hipChooseDevice = HIP_API_ID_CONCAT(HIP_API_ID_,hipChooseDevice),
489490
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) {
795796
case HIP_API_ID_hipMemGetAddressRange: return "hipMemGetAddressRange";
796797
case HIP_API_ID_hipMemGetAllocationGranularity: return "hipMemGetAllocationGranularity";
797798
case HIP_API_ID_hipMemGetAllocationPropertiesFromHandle: return "hipMemGetAllocationPropertiesFromHandle";
799+
case HIP_API_ID_hipMemGetDefaultMemPool: return "hipMemGetDefaultMemPool";
798800
case HIP_API_ID_hipMemGetHandleForAddressRange: return "hipMemGetHandleForAddressRange";
799801
case HIP_API_ID_hipMemGetInfo: return "hipMemGetInfo";
800802
case HIP_API_ID_hipMemGetMemPool: return "hipMemGetMemPool";
@@ -1248,6 +1250,7 @@ static inline uint32_t hipApiIdByName(const char* name) {
12481250
if (strcmp("hipMemGetAddressRange", name) == 0) return HIP_API_ID_hipMemGetAddressRange;
12491251
if (strcmp("hipMemGetAllocationGranularity", name) == 0) return HIP_API_ID_hipMemGetAllocationGranularity;
12501252
if (strcmp("hipMemGetAllocationPropertiesFromHandle", name) == 0) return HIP_API_ID_hipMemGetAllocationPropertiesFromHandle;
1253+
if (strcmp("hipMemGetDefaultMemPool", name) == 0) return HIP_API_ID_hipMemGetDefaultMemPool;
12511254
if (strcmp("hipMemGetHandleForAddressRange", name) == 0) return HIP_API_ID_hipMemGetHandleForAddressRange;
12521255
if (strcmp("hipMemGetInfo", name) == 0) return HIP_API_ID_hipMemGetInfo;
12531256
if (strcmp("hipMemGetMemPool", name) == 0) return HIP_API_ID_hipMemGetMemPool;
@@ -3041,6 +3044,13 @@ typedef struct hip_api_data_s {
30413044
hipMemAllocationProp prop__val;
30423045
hipMemGenericAllocationHandle_t handle;
30433046
} hipMemGetAllocationPropertiesFromHandle;
3047+
struct {
3048+
hipMemPool_t* memPool;
3049+
hipMemPool_t memPool__val;
3050+
hipMemLocation* location;
3051+
hipMemLocation location__val;
3052+
hipMemAllocationType type;
3053+
} hipMemGetDefaultMemPool;
30443054
struct {
30453055
void* handle;
30463056
hipDeviceptr_t dptr;
@@ -5737,6 +5747,12 @@ typedef struct hip_api_data_s {
57375747
cb_data.args.hipMemGetAllocationPropertiesFromHandle.prop = (hipMemAllocationProp*)prop; \
57385748
cb_data.args.hipMemGetAllocationPropertiesFromHandle.handle = (hipMemGenericAllocationHandle_t)handle; \
57395749
};
5750+
// hipMemGetDefaultMemPool[('hipMemPool_t*', 'memPool'), ('hipMemLocation*', 'location'), ('hipMemAllocationType', 'type')]
5751+
#define INIT_hipMemGetDefaultMemPool_CB_ARGS_DATA(cb_data) { \
5752+
cb_data.args.hipMemGetDefaultMemPool.memPool = (hipMemPool_t*)memPool; \
5753+
cb_data.args.hipMemGetDefaultMemPool.location = (hipMemLocation*)location; \
5754+
cb_data.args.hipMemGetDefaultMemPool.type = (hipMemAllocationType)type; \
5755+
};
57405756
// hipMemGetHandleForAddressRange[('void*', 'handle'), ('hipDeviceptr_t', 'dptr'), ('size_t', 'size'), ('hipMemRangeHandleType', 'handleType'), ('unsigned long long', 'flags')]
57415757
#define INIT_hipMemGetHandleForAddressRange_CB_ARGS_DATA(cb_data) { \
57425758
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) {
80408056
case HIP_API_ID_hipMemGetAllocationPropertiesFromHandle:
80418057
if (data->args.hipMemGetAllocationPropertiesFromHandle.prop) data->args.hipMemGetAllocationPropertiesFromHandle.prop__val = *(data->args.hipMemGetAllocationPropertiesFromHandle.prop);
80428058
break;
8059+
// hipMemGetDefaultMemPool[('hipMemPool_t*', 'memPool'), ('hipMemLocation*', 'location'), ('hipMemAllocationType', 'type')]
8060+
case HIP_API_ID_hipMemGetDefaultMemPool:
8061+
if (data->args.hipMemGetDefaultMemPool.memPool) data->args.hipMemGetDefaultMemPool.memPool__val = *(data->args.hipMemGetDefaultMemPool.memPool);
8062+
if (data->args.hipMemGetDefaultMemPool.location) data->args.hipMemGetDefaultMemPool.location__val = *(data->args.hipMemGetDefaultMemPool.location);
8063+
break;
80438064
// hipMemGetHandleForAddressRange[('void*', 'handle'), ('hipDeviceptr_t', 'dptr'), ('size_t', 'size'), ('hipMemRangeHandleType', 'handleType'), ('unsigned long long', 'flags')]
80448065
case HIP_API_ID_hipMemGetHandleForAddressRange:
80458066
break;
@@ -10876,6 +10897,15 @@ static inline const char* hipApiString(hip_api_id_t id, const hip_api_data_t* da
1087610897
oss << ", handle="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMemGetAllocationPropertiesFromHandle.handle);
1087710898
oss << ")";
1087810899
break;
10900+
case HIP_API_ID_hipMemGetDefaultMemPool:
10901+
oss << "hipMemGetDefaultMemPool(";
10902+
if (data->args.hipMemGetDefaultMemPool.memPool == NULL) oss << "memPool=NULL";
10903+
else { oss << "memPool="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMemGetDefaultMemPool.memPool__val); }
10904+
if (data->args.hipMemGetDefaultMemPool.location == NULL) oss << ", location=NULL";
10905+
else { oss << ", location="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMemGetDefaultMemPool.location__val); }
10906+
oss << ", type="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMemGetDefaultMemPool.type);
10907+
oss << ")";
10908+
break;
1087910909
case HIP_API_ID_hipMemGetHandleForAddressRange:
1088010910
oss << "hipMemGetHandleForAddressRange(";
1088110911
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
@@ -881,6 +881,8 @@ hipError_t hipKernelGetAttribute(int* pi, hipFunction_attribute attrib, hipKerne
881881
hipDevice_t dev);
882882
hipError_t hipKernelSetAttribute(hipFunction_attribute attrib, int value, hipKernel_t kernel, hipDevice_t dev);
883883
hipError_t hipKernelGetFunction(hipFunction_t* pFunc, hipKernel_t kernel);
884+
hipError_t hipMemGetDefaultMemPool(hipMemPool_t* memPool, hipMemLocation* location,
885+
hipMemAllocationType type);
884886
} // namespace hip
885887

886888
namespace hip {
@@ -1438,6 +1440,7 @@ void UpdateDispatchTable(HipDispatchTable* ptrDispatchTable) {
14381440
ptrDispatchTable->hipKernelGetAttribute_fn = hip::hipKernelGetAttribute;
14391441
ptrDispatchTable->hipKernelSetAttribute_fn = hip::hipKernelSetAttribute;
14401442
ptrDispatchTable->hipKernelGetFunction_fn = hip::hipKernelGetFunction;
1443+
ptrDispatchTable->hipMemGetDefaultMemPool_fn = hip::hipMemGetDefaultMemPool;
14411444
}
14421445

14431446
#if HIP_ROCPROFILER_REGISTER > 0
@@ -2134,15 +2137,17 @@ HIP_ENFORCE_ABI(HipDispatchTable, hipKernelGetAttribute_fn, 514);
21342137
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 25
21352138
HIP_ENFORCE_ABI(HipDispatchTable, hipKernelSetAttribute_fn, 515);
21362139
HIP_ENFORCE_ABI(HipDispatchTable, hipKernelGetFunction_fn, 516);
2140+
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 26
2141+
HIP_ENFORCE_ABI(HipDispatchTable, hipMemGetDefaultMemPool_fn, 517);
21372142
// if HIP_ENFORCE_ABI entries are added for each new function pointer in the table, the number below
21382143
// will be +1 of the number in the last HIP_ENFORCE_ABI line. E.g.:
21392144
//
21402145
// HIP_ENFORCE_ABI(<table>, <functor>, 8)
21412146
//
21422147
// HIP_ENFORCE_ABI_VERSIONING(<table>, 9) <- 8 + 1 = 9
2143-
HIP_ENFORCE_ABI_VERSIONING(HipDispatchTable, 517)
2148+
HIP_ENFORCE_ABI_VERSIONING(HipDispatchTable, 518)
21442149

2145-
static_assert(HIP_RUNTIME_API_TABLE_MAJOR_VERSION == 0 && HIP_RUNTIME_API_TABLE_STEP_VERSION == 25,
2150+
static_assert(HIP_RUNTIME_API_TABLE_MAJOR_VERSION == 0 && HIP_RUNTIME_API_TABLE_STEP_VERSION == 26,
21462151
"If you get this error, add new HIP_ENFORCE_ABI(...) code for the new function "
21472152
"pointers and then update this check so it is true");
21482153
#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
@@ -546,4 +546,36 @@ hipError_t hipMemGetMemPool(hipMemPool_t* pool, hipMemLocation* location,
546546

547547
HIP_RETURN(hipSuccess);
548548
}
549+
550+
// ================================================================================================
551+
hipError_t hipMemGetDefaultMemPool(hipMemPool_t* memPool, hipMemLocation* location,
552+
hipMemAllocationType type) {
553+
HIP_INIT_API(hipMemGetDefaultMemPool, memPool, location, type);
554+
if (memPool == nullptr || location == nullptr) {
555+
HIP_RETURN(hipErrorInvalidValue);
556+
}
557+
558+
if (location->type != hipMemLocationTypeDevice) {
559+
HIP_RETURN(hipErrorInvalidValue);
560+
}
561+
562+
if (location->id < 0 || location->id >= g_devices.size()) {
563+
HIP_RETURN(hipErrorInvalidValue);
564+
}
565+
566+
switch (type) {
567+
case hipMemAllocationTypePinned:
568+
*memPool = reinterpret_cast<hipMemPool_t>(
569+
g_devices[static_cast<std::size_t>(location->id)]->GetDefaultMemoryPool());
570+
break;
571+
case hipMemAllocationTypeManaged:
572+
*memPool = reinterpret_cast<hipMemPool_t>(
573+
g_devices[static_cast<std::size_t>(location->id)]->GetDefaultManagedMemoryPool());
574+
break;
575+
default:
576+
HIP_RETURN(hipErrorInvalidValue);
577+
}
578+
579+
HIP_RETURN(hipSuccess);
580+
}
549581
} // namespace hip

projects/clr/hipamd/src/hip_table_interface.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3188,4 +3188,10 @@ hipError_t hipKernelGetFunction(hipFunction_t* pFunc, hipKernel_t kernel) {
31883188
TRY;
31893189
return hip::GetHipDispatchTable()->hipKernelGetFunction_fn(pFunc, kernel) ;
31903190
CATCH;
3191-
}
3191+
}
3192+
hipError_t hipMemGetDefaultMemPool(hipMemPool_t* memPool, hipMemLocation* location,
3193+
hipMemAllocationType type) {
3194+
TRY;
3195+
return hip::GetHipDispatchTable()->hipMemGetDefaultMemPool_fn(memPool, location, type);
3196+
CATCH;
3197+
}

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
@@ -4161,6 +4161,13 @@ inline static hipError_t hipMemGetMemPool(hipMemPool_t* pool, hipMemLocation* lo
41614161
CUmemAllocationType cu_allocation_type = cudaMemAllocationTypeToCUmemAllocationType(type);
41624162
return hipCUResultTohipError(cuMemGetMemPool(pool, &cu_location, cu_allocation_type));
41634163
}
4164+
4165+
inline static hipError_t hipMemGetDefaultMemPool(hipMemPool_t* memPool, hipMemLocation* location,
4166+
hipMemAllocationType type) {
4167+
CUmemLocation cu_location = cudaMemLocationToCUmemLocation(location);
4168+
CUmemAllocationType cu_allocation_type = cudaMemAllocationTypeToCUmemAllocationType(type);
4169+
return hipCUResultTohipError(cuMemGetDefaultMemPool(memPool, &cu_location, cu_allocation_type));
4170+
}
41644171
#endif // CUDA_VERSION >= CUDA_13000
41654172

41664173
#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)