SWDEV-546311 - implement hipKernelGetLibrary & hipLibraryEnumerateKer… (#1143)

* SWDEV-546311 - implement hipKernelGetLibrary & hipLibraryEnumerateKernels API

* Fix for LibraryEnumerateKernel and KernelGetName

* Update Enumerate Kernels to handle 0 numKernels

* Minor fixes to function names

* fix error checking in internal function

* Update changelog for new apis

---------

Co-authored-by: Rahul Manocha <rmanocha@amd.com>
This commit is contained in:
Rahul Manocha
2025-10-27 14:13:17 -07:00
committed by GitHub
parent 3e59eebf17
commit f5d901f016
13 changed files with 340 additions and 26 deletions
@@ -63,7 +63,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 16
#define HIP_RUNTIME_API_TABLE_STEP_VERSION 17
// HIP API interface
// HIP compiler dispatch functions
@@ -1105,6 +1105,10 @@ typedef hipError_t (*t_hipLibraryGetKernel)(hipKernel_t* pKernel, hipLibrary_t l
const char* name);
typedef hipError_t (*t_hipLibraryGetKernelCount)(unsigned int *count,
hipLibrary_t library);
typedef hipError_t (*t_hipLibraryEnumerateKernels)(hipKernel_t* kernels, unsigned int numKernels,
hipLibrary_t library);
typedef hipError_t (*t_hipKernelGetLibrary)(hipLibrary_t* library, hipKernel_t kernel);
typedef hipError_t (*t_hipKernelGetName)(const char** name, hipKernel_t kernel);
// HIP Compiler dispatch table
struct HipCompilerDispatchTable {
@@ -1683,8 +1687,13 @@ struct HipDispatchTable {
// HIP_RUNTIME_API_TABLE_STEP_VERSION = 16
t_hipStreamCopyAttributes hipStreamCopyAttributes_fn;
// HIP_RUNTIME_API_TABLE_STEP_VERSION = 17
t_hipLibraryEnumerateKernels hipLibraryEnumerateKernels_fn;
t_hipKernelGetLibrary hipKernelGetLibrary_fn;
t_hipKernelGetName hipKernelGetName_fn;
// DO NOT EDIT ABOVE!
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 17
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 18
// ******************************************************************************************* //
//
@@ -463,7 +463,10 @@ enum hip_api_id_t {
HIP_API_ID_hipLibraryGetKernelCount = 443,
HIP_API_ID_hipMemGetHandleForAddressRange = 444,
HIP_API_ID_hipStreamCopyAttributes = 445,
HIP_API_ID_LAST = 445,
HIP_API_ID_hipKernelGetLibrary = 446,
HIP_API_ID_hipLibraryEnumerateKernels = 447,
HIP_API_ID_hipKernelGetName = 448,
HIP_API_ID_LAST = 448,
HIP_API_ID_hipChooseDevice = HIP_API_ID_CONCAT(HIP_API_ID_,hipChooseDevice),
HIP_API_ID_hipGetDeviceProperties = HIP_API_ID_CONCAT(HIP_API_ID_,hipGetDeviceProperties),
@@ -727,12 +730,15 @@ static inline const char* hip_api_name(const uint32_t id) {
case HIP_API_ID_hipIpcGetMemHandle: return "hipIpcGetMemHandle";
case HIP_API_ID_hipIpcOpenEventHandle: return "hipIpcOpenEventHandle";
case HIP_API_ID_hipIpcOpenMemHandle: return "hipIpcOpenMemHandle";
case HIP_API_ID_hipKernelGetLibrary: return "hipKernelGetLibrary";
case HIP_API_ID_hipKernelGetName: return "hipKernelGetName";
case HIP_API_ID_hipLaunchByPtr: return "hipLaunchByPtr";
case HIP_API_ID_hipLaunchCooperativeKernel: return "hipLaunchCooperativeKernel";
case HIP_API_ID_hipLaunchCooperativeKernelMultiDevice: return "hipLaunchCooperativeKernelMultiDevice";
case HIP_API_ID_hipLaunchHostFunc: return "hipLaunchHostFunc";
case HIP_API_ID_hipLaunchKernel: return "hipLaunchKernel";
case HIP_API_ID_hipLaunchKernelExC: return "hipLaunchKernelExC";
case HIP_API_ID_hipLibraryEnumerateKernels: return "hipLibraryEnumerateKernels";
case HIP_API_ID_hipLibraryGetKernel: return "hipLibraryGetKernel";
case HIP_API_ID_hipLibraryGetKernelCount: return "hipLibraryGetKernelCount";
case HIP_API_ID_hipLibraryLoadData: return "hipLibraryLoadData";
@@ -1166,12 +1172,15 @@ static inline uint32_t hipApiIdByName(const char* name) {
if (strcmp("hipIpcGetMemHandle", name) == 0) return HIP_API_ID_hipIpcGetMemHandle;
if (strcmp("hipIpcOpenEventHandle", name) == 0) return HIP_API_ID_hipIpcOpenEventHandle;
if (strcmp("hipIpcOpenMemHandle", name) == 0) return HIP_API_ID_hipIpcOpenMemHandle;
if (strcmp("hipKernelGetLibrary", name) == 0) return HIP_API_ID_hipKernelGetLibrary;
if (strcmp("hipKernelGetName", name) == 0) return HIP_API_ID_hipKernelGetName;
if (strcmp("hipLaunchByPtr", name) == 0) return HIP_API_ID_hipLaunchByPtr;
if (strcmp("hipLaunchCooperativeKernel", name) == 0) return HIP_API_ID_hipLaunchCooperativeKernel;
if (strcmp("hipLaunchCooperativeKernelMultiDevice", name) == 0) return HIP_API_ID_hipLaunchCooperativeKernelMultiDevice;
if (strcmp("hipLaunchHostFunc", name) == 0) return HIP_API_ID_hipLaunchHostFunc;
if (strcmp("hipLaunchKernel", name) == 0) return HIP_API_ID_hipLaunchKernel;
if (strcmp("hipLaunchKernelExC", name) == 0) return HIP_API_ID_hipLaunchKernelExC;
if (strcmp("hipLibraryEnumerateKernels", name) == 0) return HIP_API_ID_hipLibraryEnumerateKernels;
if (strcmp("hipLibraryGetKernel", name) == 0) return HIP_API_ID_hipLibraryGetKernel;
if (strcmp("hipLibraryGetKernelCount", name) == 0) return HIP_API_ID_hipLibraryGetKernelCount;
if (strcmp("hipLibraryLoadData", name) == 0) return HIP_API_ID_hipLibraryLoadData;
@@ -2672,6 +2681,16 @@ typedef struct hip_api_data_s {
hipIpcMemHandle_t handle;
unsigned int flags;
} hipIpcOpenMemHandle;
struct {
hipLibrary_t* library;
hipLibrary_t library__val;
hipKernel_t kernel;
} hipKernelGetLibrary;
struct {
const char** name;
const char* name__val;
hipKernel_t kernel;
} hipKernelGetName;
struct {
const void* hostFunction;
} hipLaunchByPtr;
@@ -2711,6 +2730,12 @@ typedef struct hip_api_data_s {
void** args;
void* args__val;
} hipLaunchKernelExC;
struct {
hipKernel_t* kernels;
hipKernel_t kernels__val;
unsigned int numKernels;
hipLibrary_t library;
} hipLibraryEnumerateKernels;
struct {
hipKernel_t* pKernel;
hipKernel_t pKernel__val;
@@ -5307,6 +5332,16 @@ typedef struct hip_api_data_s {
cb_data.args.hipIpcOpenMemHandle.handle = (hipIpcMemHandle_t)handle; \
cb_data.args.hipIpcOpenMemHandle.flags = (unsigned int)flags; \
};
// hipKernelGetLibrary[('hipLibrary_t*', 'library'), ('hipKernel_t', 'kernel')]
#define INIT_hipKernelGetLibrary_CB_ARGS_DATA(cb_data) { \
cb_data.args.hipKernelGetLibrary.library = (hipLibrary_t*)library; \
cb_data.args.hipKernelGetLibrary.kernel = (hipKernel_t)kernel; \
};
// hipKernelGetName[('const char**', 'name'), ('hipKernel_t', 'kernel')]
#define INIT_hipKernelGetName_CB_ARGS_DATA(cb_data) { \
cb_data.args.hipKernelGetName.name = (const char**)name; \
cb_data.args.hipKernelGetName.kernel = (hipKernel_t)kernel; \
};
// hipLaunchByPtr[('const void*', 'hostFunction')]
#define INIT_hipLaunchByPtr_CB_ARGS_DATA(cb_data) { \
cb_data.args.hipLaunchByPtr.hostFunction = (const void*)hostFunction; \
@@ -5347,6 +5382,12 @@ typedef struct hip_api_data_s {
cb_data.args.hipLaunchKernelExC.fPtr = (const void*)fPtr; \
cb_data.args.hipLaunchKernelExC.args = (void**)args; \
};
// hipLibraryEnumerateKernels[('hipKernel_t*', 'kernels'), ('unsigned int', 'numKernels'), ('hipLibrary_t', 'library')]
#define INIT_hipLibraryEnumerateKernels_CB_ARGS_DATA(cb_data) { \
cb_data.args.hipLibraryEnumerateKernels.kernels = (hipKernel_t*)kernels; \
cb_data.args.hipLibraryEnumerateKernels.numKernels = (unsigned int)numKernels; \
cb_data.args.hipLibraryEnumerateKernels.library = (hipLibrary_t)library; \
};
// hipLibraryGetKernel[('hipKernel_t*', 'pKernel'), ('hipLibrary_t', 'library'), ('const char*', 'name')]
#define INIT_hipLibraryGetKernel_CB_ARGS_DATA(cb_data) { \
cb_data.args.hipLibraryGetKernel.pKernel = (hipKernel_t*)kernel; \
@@ -7632,6 +7673,14 @@ static inline void hipApiArgsInit(hip_api_id_t id, hip_api_data_t* data) {
case HIP_API_ID_hipIpcOpenMemHandle:
if (data->args.hipIpcOpenMemHandle.devPtr) data->args.hipIpcOpenMemHandle.devPtr__val = *(data->args.hipIpcOpenMemHandle.devPtr);
break;
// hipKernelGetLibrary[('hipLibrary_t*', 'library'), ('hipKernel_t', 'kernel')]
case HIP_API_ID_hipKernelGetLibrary:
if (data->args.hipKernelGetLibrary.library) data->args.hipKernelGetLibrary.library__val = *(data->args.hipKernelGetLibrary.library);
break;
// hipKernelGetName[('const char**', 'name'), ('hipKernel_t', 'kernel')]
case HIP_API_ID_hipKernelGetName:
if (data->args.hipKernelGetName.name) data->args.hipKernelGetName.name__val = *(data->args.hipKernelGetName.name);
break;
// hipLaunchByPtr[('const void*', 'hostFunction')]
case HIP_API_ID_hipLaunchByPtr:
break;
@@ -7655,6 +7704,10 @@ static inline void hipApiArgsInit(hip_api_id_t id, hip_api_data_t* data) {
if (data->args.hipLaunchKernelExC.config) data->args.hipLaunchKernelExC.config__val = *(data->args.hipLaunchKernelExC.config);
if (data->args.hipLaunchKernelExC.args) data->args.hipLaunchKernelExC.args__val = *(data->args.hipLaunchKernelExC.args);
break;
// hipLibraryEnumerateKernels[('hipKernel_t*', 'kernels'), ('unsigned int', 'numKernels'), ('hipLibrary_t', 'library')]
case HIP_API_ID_hipLibraryEnumerateKernels:
if (data->args.hipLibraryEnumerateKernels.kernels) data->args.hipLibraryEnumerateKernels.kernels__val = *(data->args.hipLibraryEnumerateKernels.kernels);
break;
// hipLibraryGetKernel[('hipKernel_t*', 'pKernel'), ('hipLibrary_t', 'library'), ('const char*', 'name')]
case HIP_API_ID_hipLibraryGetKernel:
if (data->args.hipLibraryGetKernel.pKernel) data->args.hipLibraryGetKernel.pKernel__val = *(data->args.hipLibraryGetKernel.pKernel);
@@ -10201,6 +10254,20 @@ 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.hipIpcOpenMemHandle.flags);
oss << ")";
break;
case HIP_API_ID_hipKernelGetLibrary:
oss << "hipKernelGetLibrary(";
if (data->args.hipKernelGetLibrary.library == NULL) oss << "library=NULL";
else { oss << "library="; roctracer::hip_support::detail::operator<<(oss, data->args.hipKernelGetLibrary.library__val); }
oss << ", kernel="; roctracer::hip_support::detail::operator<<(oss, data->args.hipKernelGetLibrary.kernel);
oss << ")";
break;
case HIP_API_ID_hipKernelGetName:
oss << "hipKernelGetName(";
if (data->args.hipKernelGetName.name == NULL) oss << "name=NULL";
else { oss << "name="; roctracer::hip_support::detail::operator<<(oss, (void*)data->args.hipKernelGetName.name__val); }
oss << ", kernel="; roctracer::hip_support::detail::operator<<(oss, data->args.hipKernelGetName.kernel);
oss << ")";
break;
case HIP_API_ID_hipLaunchByPtr:
oss << "hipLaunchByPtr(";
oss << "hostFunction="; roctracer::hip_support::detail::operator<<(oss, data->args.hipLaunchByPtr.hostFunction);
@@ -10252,6 +10319,14 @@ static inline const char* hipApiString(hip_api_id_t id, const hip_api_data_t* da
else { oss << ", args="; roctracer::hip_support::detail::operator<<(oss, data->args.hipLaunchKernelExC.args__val); }
oss << ")";
break;
case HIP_API_ID_hipLibraryEnumerateKernels:
oss << "hipLibraryEnumerateKernels(";
if (data->args.hipLibraryEnumerateKernels.kernels == NULL) oss << "kernels=NULL";
else { oss << "kernels="; roctracer::hip_support::detail::operator<<(oss, data->args.hipLibraryEnumerateKernels.kernels__val); }
oss << ", numKernels="; roctracer::hip_support::detail::operator<<(oss, data->args.hipLibraryEnumerateKernels.numKernels);
oss << ", library="; roctracer::hip_support::detail::operator<<(oss, data->args.hipLibraryEnumerateKernels.library);
oss << ")";
break;
case HIP_API_ID_hipLibraryGetKernel:
oss << "hipLibraryGetKernel(";
if (data->args.hipLibraryGetKernel.pKernel == NULL) oss << "pKernel=NULL";