SWDEV-470372 - Added hipExtHostAlloc API

This change adds a new HIP API `hipExtHostAlloc` which preserves
the functionality of `hipHostMalloc`.

Change-Id: I13504c6fc13465ddd7aed329795bb4f2fef1baff
This commit is contained in:
Ioannis Assiouras
2024-08-01 00:54:31 +01:00
parent bb52d9ed62
commit 2c84211b58
9 changed files with 71 additions and 13 deletions
@@ -61,7 +61,7 @@
// - Reset any of the *_STEP_VERSION defines to zero if the corresponding *_MAJOR_VERSION increases
#define HIP_API_TABLE_STEP_VERSION 0
#define HIP_COMPILER_API_TABLE_STEP_VERSION 0
#define HIP_RUNTIME_API_TABLE_STEP_VERSION 4
#define HIP_RUNTIME_API_TABLE_STEP_VERSION 5
// HIP API interface
typedef hipError_t (*t___hipPopCallConfiguration)(dim3* gridDim, dim3* blockDim, size_t* sharedMem,
@@ -998,6 +998,9 @@ typedef hipError_t (*t_hipDrvGraphMemcpyNodeGetParams)(hipGraphNode_t hNode,
typedef hipError_t (*t_hipDrvGraphMemcpyNodeSetParams)(hipGraphNode_t hNode,
const HIP_MEMCPY3D* nodeParams);
typedef hipError_t (*t_hipExtHostAlloc)(void **ptr, size_t size,
unsigned int flags);
// HIP Compiler dispatch table
struct HipCompilerDispatchTable {
size_t size;
@@ -1480,4 +1483,5 @@ struct HipDispatchTable {
t_hipExternalMemoryGetMappedMipmappedArray hipExternalMemoryGetMappedMipmappedArray_fn;
t_hipDrvGraphMemcpyNodeGetParams hipDrvGraphMemcpyNodeGetParams_fn;
t_hipDrvGraphMemcpyNodeSetParams hipDrvGraphMemcpyNodeSetParams_fn;
t_hipExtHostAlloc hipExtHostAlloc_fn;
};
+28 -1
View File
@@ -424,7 +424,8 @@ enum hip_api_id_t {
HIP_API_ID_hipMemcpyDtoA = 404,
HIP_API_ID_hipMemcpyHtoAAsync = 405,
HIP_API_ID_hipSetValidDevices = 406,
HIP_API_ID_LAST = 406,
HIP_API_ID_hipExtHostAlloc = 407,
HIP_API_ID_LAST = 407,
HIP_API_ID_hipChooseDevice = HIP_API_ID_CONCAT(HIP_API_ID_,hipChooseDevice),
HIP_API_ID_hipGetDeviceProperties = HIP_API_ID_CONCAT(HIP_API_ID_,hipGetDeviceProperties),
@@ -671,6 +672,7 @@ static inline const char* hip_api_name(const uint32_t id) {
case HIP_API_ID_hipHostGetDevicePointer: return "hipHostGetDevicePointer";
case HIP_API_ID_hipHostGetFlags: return "hipHostGetFlags";
case HIP_API_ID_hipHostMalloc: return "hipHostMalloc";
case HIP_API_ID_hipExtHostAlloc: return "hipExtHostAlloc";
case HIP_API_ID_hipHostRegister: return "hipHostRegister";
case HIP_API_ID_hipHostUnregister: return "hipHostUnregister";
case HIP_API_ID_hipImportExternalMemory: return "hipImportExternalMemory";
@@ -1073,6 +1075,7 @@ static inline uint32_t hipApiIdByName(const char* name) {
if (strcmp("hipHostGetDevicePointer", name) == 0) return HIP_API_ID_hipHostGetDevicePointer;
if (strcmp("hipHostGetFlags", name) == 0) return HIP_API_ID_hipHostGetFlags;
if (strcmp("hipHostMalloc", name) == 0) return HIP_API_ID_hipHostMalloc;
if (strcmp("hipExtHostAlloc", name) == 0) return HIP_API_ID_hipExtHostAlloc;
if (strcmp("hipHostRegister", name) == 0) return HIP_API_ID_hipHostRegister;
if (strcmp("hipHostUnregister", name) == 0) return HIP_API_ID_hipHostUnregister;
if (strcmp("hipImportExternalMemory", name) == 0) return HIP_API_ID_hipImportExternalMemory;
@@ -2462,6 +2465,12 @@ typedef struct hip_api_data_s {
size_t size;
unsigned int flags;
} hipHostMalloc;
struct {
void** ptr;
void* ptr__val;
size_t size;
unsigned int flags;
} hipExtHostAlloc;
struct {
void* hostPtr;
size_t sizeBytes;
@@ -4809,6 +4818,12 @@ typedef struct hip_api_data_s {
cb_data.args.hipHostMalloc.size = (size_t)sizeBytes; \
cb_data.args.hipHostMalloc.flags = (unsigned int)flags; \
};
// hipExtHostAlloc[('void**', 'ptr'), ('size_t', 'size'), ('unsigned int', 'flags')]
#define INIT_hipExtHostAlloc_CB_ARGS_DATA(cb_data) { \
cb_data.args.hipExtHostAlloc.ptr = (void**)ptr; \
cb_data.args.hipExtHostAlloc.size = (size_t)sizeBytes; \
cb_data.args.hipExtHostAlloc.flags = (unsigned int)flags; \
};
// hipHostRegister[('void*', 'hostPtr'), ('size_t', 'sizeBytes'), ('unsigned int', 'flags')]
#define INIT_hipHostRegister_CB_ARGS_DATA(cb_data) { \
cb_data.args.hipHostRegister.hostPtr = (void*)hostPtr; \
@@ -6897,6 +6912,10 @@ static inline void hipApiArgsInit(hip_api_id_t id, hip_api_data_t* data) {
case HIP_API_ID_hipHostMalloc:
if (data->args.hipHostMalloc.ptr) data->args.hipHostMalloc.ptr__val = *(data->args.hipHostMalloc.ptr);
break;
// hipExtHostAlloc[('void**', 'ptr'), ('size_t', 'size'), ('unsigned int', 'flags')]
case HIP_API_ID_hipExtHostAlloc:
if (data->args.hipExtHostAlloc.ptr) data->args.hipExtHostAlloc.ptr__val = *(data->args.hipExtHostAlloc.ptr);
break;
// hipHostRegister[('void*', 'hostPtr'), ('size_t', 'sizeBytes'), ('unsigned int', 'flags')]
case HIP_API_ID_hipHostRegister:
break;
@@ -9242,6 +9261,14 @@ static inline const char* hipApiString(hip_api_id_t id, const hip_api_data_t* da
oss << ", flags="; roctracer::hip_support::detail::operator<<(oss, data->args.hipHostMalloc.flags);
oss << ")";
break;
case HIP_API_ID_hipExtHostAlloc:
oss << "hipExtHostAlloc(";
if (data->args.hipExtHostAlloc.ptr == NULL) oss << "ptr=NULL";
else { oss << "ptr="; roctracer::hip_support::detail::operator<<(oss, data->args.hipExtHostAlloc.ptr__val); }
oss << ", size="; roctracer::hip_support::detail::operator<<(oss, data->args.hipExtHostAlloc.size);
oss << ", flags="; roctracer::hip_support::detail::operator<<(oss, data->args.hipExtHostAlloc.flags);
oss << ")";
break;
case HIP_API_ID_hipHostRegister:
oss << "hipHostRegister(";
oss << "hostPtr="; roctracer::hip_support::detail::operator<<(oss, data->args.hipHostRegister.hostPtr);