Skip to content

Commit e79eaaa

Browse files
authored
SWDEV-546287 - Implement hipLibrary load/unload (#975)
1 parent 775ac73 commit e79eaaa

File tree

26 files changed

+1175
-16
lines changed

26 files changed

+1175
-16
lines changed

projects/clr/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ Full documentation for HIP is available at [rocm.docs.amd.com](https://rocm.docs
2828
- `hipGetDriverEntryPoint ` gets function pointer of a HIP API.
2929
- `hipSetValidDevices` sets a default list of devices that can be used by HIP
3030
- `hipStreamGetId` queries the id of a stream
31+
- `hipLibraryLoadData` Create library object from code
32+
- `hipLibraryLoadFromFile` Create library object from file
33+
- `hipLibraryUnload` Unload library
34+
- `hipLibraryGetKernel` Get a kernel from library
35+
- `hipLibraryGetKernelCount` Get kernel count in library
3136
* Changed HIP APIs
3237
- `hipMemAllocationType` now has hip exclusive enum hipMemAllocationTypeUncached
3338
- `hipMemCreate` now checks for hipMemAllocationTypeUncached enum from

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
#define HIP_API_TABLE_STEP_VERSION 0
6464
#define HIP_COMPILER_API_TABLE_STEP_VERSION 0
6565
#define HIP_TOOLS_API_TABLE_STEP_VERSION 0
66-
#define HIP_RUNTIME_API_TABLE_STEP_VERSION 14
66+
#define HIP_RUNTIME_API_TABLE_STEP_VERSION 15
6767

6868
// HIP API interface
6969
// HIP compiler dispatch functions
@@ -1087,6 +1087,23 @@ typedef hipError_t (*t_hipGetDriverEntryPoint)(const char* symbol, void** funcPt
10871087
typedef hipError_t (*t_hipGetDriverEntryPoint_spt)(const char* symbol, void** funcPtr,
10881088
unsigned long long flags,
10891089
hipDriverEntryPointQueryResult* status);
1090+
typedef hipError_t (*t_hipLibraryLoadData)(hipLibrary_t* library, const void* code,
1091+
hipJitOption** jitOptions, void** jitOptionsValues,
1092+
unsigned int numJitOptions,
1093+
hipLibraryOption** libraryOptions,
1094+
void** libraryOptionValues,
1095+
unsigned int numLibraryOptions);
1096+
typedef hipError_t (*t_hipLibraryLoadFromFile)(hipLibrary_t* library, const char* fileName,
1097+
hipJitOption** jitOptions, void** jitOptionsValues,
1098+
unsigned int numJitOptions,
1099+
hipLibraryOption** libraryOptions,
1100+
void** libraryOptionValues,
1101+
unsigned int numLibraryOptions);
1102+
typedef hipError_t (*t_hipLibraryUnload)(hipLibrary_t library);
1103+
typedef hipError_t (*t_hipLibraryGetKernel)(hipKernel_t* pKernel, hipLibrary_t library,
1104+
const char* name);
1105+
typedef hipError_t (*t_hipLibraryGetKernelCount)(unsigned int *count,
1106+
hipLibrary_t library);
10901107

10911108
// HIP Compiler dispatch table
10921109
struct HipCompilerDispatchTable {
@@ -1655,6 +1672,13 @@ struct HipDispatchTable {
16551672
t_hipMemAdvise_v2 hipMemAdvise_v2_fn;
16561673
t_hipStreamGetId hipStreamGetId_fn;
16571674

1675+
// HIP_RUNTIME_API_TABLE_STEP_VERSION = 15
1676+
t_hipLibraryLoadData hipLibraryLoadData_fn;
1677+
t_hipLibraryLoadFromFile hipLibraryLoadFromFile_fn;
1678+
t_hipLibraryUnload hipLibraryUnload_fn;
1679+
t_hipLibraryGetKernel hipLibraryGetKernel_fn;
1680+
t_hipLibraryGetKernelCount hipLibraryGetKernelCount_fn;
1681+
16581682
// DO NOT EDIT ABOVE!
16591683
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 15
16601684

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

Lines changed: 218 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,12 @@ enum hip_api_id_t {
456456
HIP_API_ID_hipMemPrefetchAsync_v2 = 436,
457457
HIP_API_ID_hipMemAdvise_v2 = 437,
458458
HIP_API_ID_hipStreamGetId = 438,
459-
HIP_API_ID_LAST = 438,
459+
HIP_API_ID_hipLibraryLoadData = 439,
460+
HIP_API_ID_hipLibraryLoadFromFile = 440,
461+
HIP_API_ID_hipLibraryUnload = 441,
462+
HIP_API_ID_hipLibraryGetKernel = 442,
463+
HIP_API_ID_hipLibraryGetKernelCount = 443,
464+
HIP_API_ID_LAST = 443,
460465

461466
HIP_API_ID_hipChooseDevice = HIP_API_ID_CONCAT(HIP_API_ID_,hipChooseDevice),
462467
HIP_API_ID_hipGetDeviceProperties = HIP_API_ID_CONCAT(HIP_API_ID_,hipGetDeviceProperties),
@@ -922,6 +927,11 @@ static inline const char* hip_api_name(const uint32_t id) {
922927
case HIP_API_ID_hipUserObjectRetain: return "hipUserObjectRetain";
923928
case HIP_API_ID_hipWaitExternalSemaphoresAsync: return "hipWaitExternalSemaphoresAsync";
924929
case HIP_API_ID_hipModuleGetFunctionCount: return "hipModuleGetFunctionCount";
930+
case HIP_API_ID_hipLibraryLoadData: return "hipLibraryLoadData";
931+
case HIP_API_ID_hipLibraryLoadFromFile: return "hipLibraryLoadFromFile";
932+
case HIP_API_ID_hipLibraryUnload: return "hipLibraryUnload";
933+
case HIP_API_ID_hipLibraryGetKernel: return "hipLibraryGetKernel";
934+
case HIP_API_ID_hipLibraryGetKernelCount: return "hipLibraryGetKernelCount";
925935
};
926936
return "unknown";
927937
};
@@ -1355,6 +1365,11 @@ static inline uint32_t hipApiIdByName(const char* name) {
13551365
if (strcmp("hipUserObjectRetain", name) == 0) return HIP_API_ID_hipUserObjectRetain;
13561366
if (strcmp("hipWaitExternalSemaphoresAsync", name) == 0) return HIP_API_ID_hipWaitExternalSemaphoresAsync;
13571367
if (strcmp("hipModuleGetFunctionCount", name) == 0) return HIP_API_ID_hipModuleGetFunctionCount;
1368+
if (strcmp("hipLibraryLoadData", name) == 0) return HIP_API_ID_hipLibraryLoadData;
1369+
if (strcmp("hipLibraryLoadFromFile", name) == 0) return HIP_API_ID_hipLibraryLoadFromFile;
1370+
if (strcmp("hipLibraryUnload", name) == 0) return HIP_API_ID_hipLibraryUnload;
1371+
if (strcmp("hipLibraryGetKernel", name) == 0) return HIP_API_ID_hipLibraryGetKernel;
1372+
if (strcmp("hipLibraryGetKernelCount", name) == 0) return HIP_API_ID_hipLibraryGetKernelCount;
13581373
return HIP_API_ID_NONE;
13591374
}
13601375

@@ -3936,6 +3951,44 @@ typedef struct hip_api_data_s {
39363951
unsigned int numExtSems;
39373952
hipStream_t stream;
39383953
} hipWaitExternalSemaphoresAsync;
3954+
struct {
3955+
hipLibrary_t* library;
3956+
hipLibrary_t library__val;
3957+
const void* image;
3958+
hipJitOption** jitOptions;
3959+
void** jitOptionsValues;
3960+
unsigned int numJitOptions;
3961+
hipLibraryOption** libraryOptions;
3962+
void** libraryOptionValues;
3963+
unsigned int numLibraryOptions;
3964+
} hipLibraryLoadData;
3965+
struct {
3966+
hipLibrary_t* library;
3967+
hipLibrary_t library__val;
3968+
const char* fname;
3969+
char fname__val;
3970+
hipJitOption** jitOptions;
3971+
void** jitOptionsValues;
3972+
unsigned int numJitOptions;
3973+
hipLibraryOption** libraryOptions;
3974+
void** libraryOptionValues;
3975+
unsigned int numLibraryOptions;
3976+
} hipLibraryLoadFromFile;
3977+
struct {
3978+
hipLibrary_t library;
3979+
} hipLibraryUnload;
3980+
struct {
3981+
hipKernel_t* kernel;
3982+
hipKernel_t kernel__val;
3983+
hipLibrary_t library;
3984+
const char* kname;
3985+
char kname__val;
3986+
} hipLibraryGetKernel;
3987+
struct {
3988+
unsigned int *count;
3989+
unsigned int count__val;
3990+
hipLibrary_t library;
3991+
} hipLibraryGetKernelCount;
39393992
} args;
39403993
uint64_t *phase_data;
39413994
} hip_api_data_t;
@@ -6601,6 +6654,46 @@ typedef struct hip_api_data_s {
66016654
#define INIT_hipTexRefSetMipmapFilterMode_CB_ARGS_DATA(cb_data) {};
66026655
// hipUnbindTexture()
66036656
#define INIT_hipUnbindTexture_CB_ARGS_DATA(cb_data) {};
6657+
// hipLibraryLoadData()
6658+
#define INIT_hipLibraryLoadData_CB_ARGS_DATA(cb_data) \
6659+
{ \
6660+
cb_data.args.hipLibraryLoadData.library = (hipLibrary_t*)library; \
6661+
cb_data.args.hipLibraryLoadData.image = (const void*)image; \
6662+
cb_data.args.hipLibraryLoadData.jitOptions = (hipJitOption**)jitOptions; \
6663+
cb_data.args.hipLibraryLoadData.jitOptionsValues = (void**)jitOptionsValues; \
6664+
cb_data.args.hipLibraryLoadData.numJitOptions = (unsigned int)numJitOptions; \
6665+
cb_data.args.hipLibraryLoadData.libraryOptions = (hipLibraryOption**)libraryOptions; \
6666+
cb_data.args.hipLibraryLoadData.libraryOptionValues = (void**)libraryOptionValues; \
6667+
cb_data.args.hipLibraryLoadData.numLibraryOptions = (unsigned int)numLibraryOptions; \
6668+
};
6669+
// hipLibraryLoadFromFile()
6670+
#define INIT_hipLibraryLoadFromFile_CB_ARGS_DATA(cb_data) \
6671+
{ \
6672+
cb_data.args.hipLibraryLoadFromFile.library = (hipLibrary_t*)library; \
6673+
cb_data.args.hipLibraryLoadFromFile.fname = (const char*)fname; \
6674+
cb_data.args.hipLibraryLoadFromFile.jitOptions = (hipJitOption**)jitOptions; \
6675+
cb_data.args.hipLibraryLoadFromFile.jitOptionsValues = (void**)jitOptionsValues; \
6676+
cb_data.args.hipLibraryLoadFromFile.numJitOptions = (unsigned int)numJitOptions; \
6677+
cb_data.args.hipLibraryLoadFromFile.libraryOptions = (hipLibraryOption**)libraryOptions; \
6678+
cb_data.args.hipLibraryLoadFromFile.libraryOptionValues = (void**)libraryOptionValues; \
6679+
cb_data.args.hipLibraryLoadFromFile.numLibraryOptions = (unsigned int)numLibraryOptions; \
6680+
};
6681+
// hipLibraryUnload()
6682+
#define INIT_hipLibraryUnload_CB_ARGS_DATA(cb_data) \
6683+
{ cb_data.args.hipLibraryUnload.library = (hipLibrary_t)library; };
6684+
// hipLibraryGetKernel()
6685+
#define INIT_hipLibraryGetKernel_CB_ARGS_DATA(cb_data) \
6686+
{ \
6687+
cb_data.args.hipLibraryGetKernel.kernel = (hipKernel_t *)kernel; \
6688+
cb_data.args.hipLibraryGetKernel.library = (hipLibrary_t)library; \
6689+
cb_data.args.hipLibraryGetKernel.kname = (const char *)kname; \
6690+
};
6691+
// hipLibraryGetKernelCount()
6692+
#define INIT_hipLibraryGetKernelCount_CB_ARGS_DATA(cb_data) \
6693+
{ \
6694+
cb_data.args.hipLibraryGetKernelCount.count = (unsigned int *)count; \
6695+
cb_data.args.hipLibraryGetKernelCount.library = (hipLibrary_t)library; \
6696+
};
66046697

66056698
#define INIT_NONE_CB_ARGS_DATA(cb_data) {};
66066699

@@ -8287,9 +8380,27 @@ static inline void hipApiArgsInit(hip_api_id_t id, hip_api_data_t* data) {
82878380
break;
82888381
// hipModuleGetFunctionCount[('unsigned int*', 'count'), ('hipModule_t', 'mod')]
82898382
case HIP_API_ID_hipModuleGetFunctionCount:
8290-
if (data->args.hipModuleGetFunctionCount.count) data->args.hipModuleGetFunctionCount.count__val = *(data->args.hipModuleGetFunctionCount.count);
8383+
if (data->args.hipModuleGetFunctionCount.count)
8384+
data->args.hipModuleGetFunctionCount.count__val =
8385+
*(data->args.hipModuleGetFunctionCount.count);
8386+
break;
8387+
case HIP_API_ID_hipLibraryLoadData:
8388+
if (data->args.hipLibraryLoadData.library)
8389+
data->args.hipLibraryLoadData.library__val = *(data->args.hipLibraryLoadData.library);
8390+
break;
8391+
case HIP_API_ID_hipLibraryLoadFromFile:
8392+
if (data->args.hipLibraryLoadFromFile.library)
8393+
data->args.hipLibraryLoadFromFile.library__val =
8394+
*(data->args.hipLibraryLoadFromFile.library);
8395+
if (data->args.hipLibraryLoadFromFile.fname)
8396+
data->args.hipLibraryLoadFromFile.fname__val = *(data->args.hipLibraryLoadFromFile.fname);
8397+
break;
8398+
case HIP_API_ID_hipLibraryGetKernel:
8399+
if (data->args.hipLibraryGetKernel.kernel)
8400+
data->args.hipLibraryGetKernel.kernel__val = *(data->args.hipLibraryGetKernel.kernel);
8401+
break;
8402+
default:
82918403
break;
8292-
default: break;
82938404
};
82948405
}
82958406

@@ -11741,8 +11852,110 @@ static inline const char* hipApiString(hip_api_id_t id, const hip_api_data_t* da
1174111852
else { oss << "count="; roctracer::hip_support::detail::operator<<(oss, data->args.hipModuleGetFunctionCount.count__val); }
1174211853
oss << ", mod="; roctracer::hip_support::detail::operator<<(oss, data->args.hipModuleGetFunctionCount.mod);
1174311854
oss << ")";
11744-
break;
11745-
default: oss << "unknown";
11855+
break;
11856+
case HIP_API_ID_hipLibraryLoadData:
11857+
oss << "hipLibraryLoadData(";
11858+
if (data->args.hipLibraryLoadData.library == NULL)
11859+
oss << "library=NULL";
11860+
else {
11861+
oss << "library=";
11862+
roctracer::hip_support::detail::operator<<(oss, data->args.hipLibraryLoadData.library__val);
11863+
}
11864+
oss << ", image=";
11865+
roctracer::hip_support::detail::operator<<(oss, data->args.hipLibraryLoadData.image);
11866+
oss << ", jitOptions=";
11867+
roctracer::hip_support::detail::operator<<(oss, data->args.hipLibraryLoadData.jitOptions);
11868+
oss << ", jitOptionsValues=";
11869+
roctracer::hip_support::detail::operator<<(oss,
11870+
data->args.hipLibraryLoadData.jitOptionsValues);
11871+
oss << ", numJitOptions=";
11872+
roctracer::hip_support::detail::operator<<(oss,
11873+
data->args.hipLibraryLoadData.numJitOptions);
11874+
oss << ", libraryOptions=";
11875+
roctracer::hip_support::detail::operator<<(oss, data->args.hipLibraryLoadData.libraryOptions);
11876+
oss << ", libraryOptionsValues=";
11877+
roctracer::hip_support::detail::operator<<(
11878+
oss, data->args.hipLibraryLoadData.libraryOptionValues);
11879+
oss << ", numLibraryOptions=";
11880+
roctracer::hip_support::detail::operator<<(oss,
11881+
data->args.hipLibraryLoadData.numLibraryOptions);
11882+
oss << ")";
11883+
break;
11884+
case HIP_API_ID_hipLibraryLoadFromFile:
11885+
oss << "hipLibraryLoadFromFile(";
11886+
if (data->args.hipLibraryLoadFromFile.library == NULL)
11887+
oss << "library=NULL";
11888+
else {
11889+
oss << "library=";
11890+
roctracer::hip_support::detail::operator<<(oss, data->args.hipLibraryLoadFromFile.library__val);
11891+
}
11892+
if (data->args.hipLibraryLoadFromFile.fname == NULL)
11893+
oss << "fname=NULL";
11894+
else {
11895+
oss << "fname=";
11896+
roctracer::hip_support::detail::operator<<(oss,
11897+
data->args.hipLibraryLoadFromFile.fname__val);
11898+
}
11899+
oss << ", jitOptions=";
11900+
roctracer::hip_support::detail::operator<<(oss, data->args.hipLibraryLoadFromFile.jitOptions);
11901+
oss << ")";
11902+
oss << ", jitOptionsValues=";
11903+
roctracer::hip_support::detail::operator<<(
11904+
oss, data->args.hipLibraryLoadFromFile.jitOptionsValues);
11905+
oss << ")";
11906+
oss << ", numJitOptions=";
11907+
roctracer::hip_support::detail::operator<<(oss,
11908+
data->args.hipLibraryLoadFromFile.numJitOptions);
11909+
oss << ")";
11910+
oss << ", libraryOptions=";
11911+
roctracer::hip_support::detail::operator<<(oss, data->args.hipLibraryLoadFromFile.libraryOptions);
11912+
oss << ")";
11913+
oss << ", libraryOptionsValues=";
11914+
roctracer::hip_support::detail::operator<<(
11915+
oss, data->args.hipLibraryLoadFromFile.libraryOptionValues);
11916+
oss << ")";
11917+
oss << ", numLibraryOptions=";
11918+
roctracer::hip_support::detail::operator<<(oss,
11919+
data->args.hipLibraryLoadFromFile.numLibraryOptions);
11920+
oss << ")";
11921+
break;
11922+
case HIP_API_ID_hipLibraryUnload:
11923+
oss << "hipLibraryUnload(";
11924+
oss << ", library=";
11925+
roctracer::hip_support::detail::operator<<(oss, data->args.hipLibraryUnload.library);
11926+
break;
11927+
case HIP_API_ID_hipLibraryGetKernel:
11928+
oss << "hipLibraryGetKernel(";
11929+
if (data->args.hipLibraryGetKernel.kernel == NULL)
11930+
oss << "kernel=NULL";
11931+
else {
11932+
oss << "kernel=";
11933+
roctracer::hip_support::detail::operator<<(oss, data->args.hipLibraryGetKernel.kernel__val);
11934+
}
11935+
oss << ", library=";
11936+
roctracer::hip_support::detail::operator<<(oss, data->args.hipLibraryGetKernel.library);
11937+
if (data->args.hipLibraryGetKernel.kname == NULL)
11938+
oss << "kname=NULL";
11939+
else {
11940+
oss << "kname=";
11941+
roctracer::hip_support::detail::operator<<(oss, data->args.hipLibraryGetKernel.kname__val);
11942+
}
11943+
break;
11944+
case HIP_API_ID_hipLibraryGetKernelCount:
11945+
oss << "hipLibraryGetKernelCount(";
11946+
if (data->args.hipLibraryGetKernelCount.count == NULL)
11947+
oss << "count=NULL";
11948+
else {
11949+
oss << "count=";
11950+
roctracer::hip_support::detail::operator<<(
11951+
oss, data->args.hipLibraryGetKernelCount.count__val);
11952+
}
11953+
oss << ", library=";
11954+
roctracer::hip_support::detail::operator<<(
11955+
oss, data->args.hipLibraryGetKernelCount.library);
11956+
break;
11957+
default:
11958+
oss << "unknown";
1174611959
};
1174711960
return strdup(oss.str().c_str());
1174811961
}

projects/clr/hipamd/src/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ target_sources(amdhip64 PRIVATE
127127
hip_api_trace.cpp
128128
hip_table_interface.cpp
129129
hip_table_interface_c.cpp
130-
hip_comgr_helper.cpp)
130+
hip_comgr_helper.cpp
131+
hip_library.cpp)
131132

132133
if(WIN32)
133134
target_sources(amdhip64 PRIVATE hip_runtime.cpp)

projects/clr/hipamd/src/amdhip.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,3 +511,8 @@ hipGetDriverEntryPoint_spt
511511
hipMemPrefetchAsync_v2
512512
hipMemAdvise_v2
513513
hipStreamGetId
514+
hipLibraryLoadData
515+
hipLibraryLoadFromFile
516+
hipLibraryUnload
517+
hipLibraryGetKernel
518+
hipLibraryGetKernelCount

0 commit comments

Comments
 (0)