From f6736d57a5307bb2d335f3bb0fca261356d33dfb Mon Sep 17 00:00:00 2001 From: "GunaShekar, Ajay" Date: Fri, 15 Aug 2025 13:06:24 -0700 Subject: [PATCH] SWDEV-546178 - hipModuleLoadFatBinary implementation (#785) * SWDEV-546178 - hipModuleLoadFatBinary implementation * SWDEV-546178 - hipModuleLoadFatBinary CHANGELOG update * SWDEV-546178 - fix roctracer build issue due to hip_prof_str.h --- CHANGELOG.md | 1 + .../include/hip/amd_detail/hip_api_trace.hpp | 2 ++ hipamd/include/hip/amd_detail/hip_prof_str.h | 26 ++++++++++++++++++- hipamd/src/amdhip.def | 1 + hipamd/src/hip_api_trace.cpp | 5 +++- hipamd/src/hip_hcc.map.in | 1 + hipamd/src/hip_module.cpp | 5 ++++ hipamd/src/hip_table_interface.cpp | 3 +++ 8 files changed, 42 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63ef0c856b..088571ad0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Full documentation for HIP is available at [rocm.docs.amd.com](https://rocm.docs - `hipMemsetD2D32Async` Used for setting 2D memory range with specified 32-bit values asynchronously - `hipStreamSetAttribute` sets attributes such as synchronization policy for a given stream - `hipStreamGetAttribute` returns attributes such as priority for a given stream + - `hipModuleLoadFatBinary` loads fatbin binary to a module ## HIP 7.0 for ROCm 7.0 diff --git a/hipamd/include/hip/amd_detail/hip_api_trace.hpp b/hipamd/include/hip/amd_detail/hip_api_trace.hpp index 59f27677c5..2df94bf9f0 100644 --- a/hipamd/include/hip/amd_detail/hip_api_trace.hpp +++ b/hipamd/include/hip/amd_detail/hip_api_trace.hpp @@ -1063,6 +1063,7 @@ typedef hipError_t (*t_hipStreamSetAttribute)(hipStream_t stream, hipStreamAttrI const hipStreamAttrValue *value); typedef hipError_t (*t_hipStreamGetAttribute)(hipStream_t stream, hipStreamAttrID attr, hipStreamAttrValue *value_out); +typedef hipError_t (*t_hipModuleLoadFatBinary)(hipModule_t* module, const void* fatbin); // HIP Compiler dispatch table struct HipCompilerDispatchTable { @@ -1615,6 +1616,7 @@ struct HipDispatchTable { t_hipMemsetD2D32Async hipMemsetD2D32Async_fn; t_hipStreamGetAttribute hipStreamGetAttribute_fn; t_hipStreamSetAttribute hipStreamSetAttribute_fn; + t_hipModuleLoadFatBinary hipModuleLoadFatBinary_fn; // HIP_RUNTIME_API_TABLE_STEP_VERSION = 14 // removed HIP_MEMSET_NODE_PARAMS replaced by hipMemsetParams diff --git a/hipamd/include/hip/amd_detail/hip_prof_str.h b/hipamd/include/hip/amd_detail/hip_prof_str.h index 6a10b8342f..38cd9657e4 100644 --- a/hipamd/include/hip/amd_detail/hip_prof_str.h +++ b/hipamd/include/hip/amd_detail/hip_prof_str.h @@ -447,7 +447,8 @@ enum hip_api_id_t { HIP_API_ID_hipMemsetD2D8Async = 427, HIP_API_ID_hipStreamGetAttribute = 428, HIP_API_ID_hipStreamSetAttribute = 429, - HIP_API_ID_LAST = 429, + HIP_API_ID_hipModuleLoadFatBinary = 430, + HIP_API_ID_LAST = 430, HIP_API_ID_hipChooseDevice = HIP_API_ID_CONCAT(HIP_API_ID_,hipChooseDevice), HIP_API_ID_hipGetDeviceProperties = HIP_API_ID_CONCAT(HIP_API_ID_,hipGetDeviceProperties), @@ -829,6 +830,7 @@ static inline const char* hip_api_name(const uint32_t id) { case HIP_API_ID_hipModuleLaunchCooperativeKernel: return "hipModuleLaunchCooperativeKernel"; case HIP_API_ID_hipModuleLaunchCooperativeKernelMultiDevice: return "hipModuleLaunchCooperativeKernelMultiDevice"; case HIP_API_ID_hipModuleLaunchKernel: return "hipModuleLaunchKernel"; + case HIP_API_ID_hipModuleLoadFatBinary: return "hipModuleLoadFatBinary"; case HIP_API_ID_hipModuleLoad: return "hipModuleLoad"; case HIP_API_ID_hipModuleLoadData: return "hipModuleLoadData"; case HIP_API_ID_hipModuleLoadDataEx: return "hipModuleLoadDataEx"; @@ -1253,6 +1255,7 @@ static inline uint32_t hipApiIdByName(const char* name) { if (strcmp("hipModuleLaunchCooperativeKernel", name) == 0) return HIP_API_ID_hipModuleLaunchCooperativeKernel; if (strcmp("hipModuleLaunchCooperativeKernelMultiDevice", name) == 0) return HIP_API_ID_hipModuleLaunchCooperativeKernelMultiDevice; if (strcmp("hipModuleLaunchKernel", name) == 0) return HIP_API_ID_hipModuleLaunchKernel; + if (strcmp("hipModuleLoadFatBinary", name) == 0) return HIP_API_ID_hipModuleLoadFatBinary; if (strcmp("hipModuleLoad", name) == 0) return HIP_API_ID_hipModuleLoad; if (strcmp("hipModuleLoadData", name) == 0) return HIP_API_ID_hipModuleLoadData; if (strcmp("hipModuleLoadDataEx", name) == 0) return HIP_API_ID_hipModuleLoadDataEx; @@ -3416,6 +3419,11 @@ typedef struct hip_api_data_s { void** extra; void* extra__val; } hipModuleLaunchKernel; + struct { + hipModule_t* module; + hipModule_t module__val; + const void* fatbin; + } hipModuleLoadFatBinary; struct { hipModule_t* module; hipModule_t module__val; @@ -5964,6 +5972,11 @@ typedef struct hip_api_data_s { cb_data.args.hipModuleLaunchKernel.kernelParams = (void**)kernelParams; \ cb_data.args.hipModuleLaunchKernel.extra = (void**)extra; \ }; +// hipModuleLoadFatBinary[('hipModule_t*', 'module'), ('const void*', 'fatbin')] +#define INIT_hipModuleLoadFatBinary_CB_ARGS_DATA(cb_data) { \ + cb_data.args.hipModuleLoadFatBinary.module = (hipModule_t*)module; \ + cb_data.args.hipModuleLoadFatBinary.fatbin = (const void*)fatbin; \ +}; // hipModuleLoad[('hipModule_t*', 'module'), ('const char*', 'fname')] #define INIT_hipModuleLoad_CB_ARGS_DATA(cb_data) { \ cb_data.args.hipModuleLoad.module = (hipModule_t*)module; \ @@ -7786,6 +7799,10 @@ static inline void hipApiArgsInit(hip_api_id_t id, hip_api_data_t* data) { if (data->args.hipModuleLaunchKernel.kernelParams) data->args.hipModuleLaunchKernel.kernelParams__val = *(data->args.hipModuleLaunchKernel.kernelParams); if (data->args.hipModuleLaunchKernel.extra) data->args.hipModuleLaunchKernel.extra__val = *(data->args.hipModuleLaunchKernel.extra); break; +// hipModuleLoadFatBinary[('hipModule_t*', 'module'), ('const void*', 'fatbin')] + case HIP_API_ID_hipModuleLoadFatBinary: + if (data->args.hipModuleLoadFatBinary.module) data->args.hipModuleLoadFatBinary.module__val = *(data->args.hipModuleLoadFatBinary.module); + break; // hipModuleLoad[('hipModule_t*', 'module'), ('const char*', 'fname')] case HIP_API_ID_hipModuleLoad: if (data->args.hipModuleLoad.module) data->args.hipModuleLoad.module__val = *(data->args.hipModuleLoad.module); @@ -10873,6 +10890,13 @@ static inline const char* hipApiString(hip_api_id_t id, const hip_api_data_t* da else { oss << ", extra="; roctracer::hip_support::detail::operator<<(oss, data->args.hipModuleLaunchKernel.extra__val); } oss << ")"; break; + case HIP_API_ID_hipModuleLoadFatBinary: + oss << "hipModuleLoadFatBinary("; + if (data->args.hipModuleLoadFatBinary.module == NULL) oss << "module=NULL"; + else { oss << "module="; roctracer::hip_support::detail::operator<<(oss, data->args.hipModuleLoadFatBinary.module__val); } + oss << ", fatbin="; roctracer::hip_support::detail::operator<<(oss, data->args.hipModuleLoadFatBinary.fatbin); + oss << ")"; + break; case HIP_API_ID_hipModuleLoad: oss << "hipModuleLoad("; if (data->args.hipModuleLoad.module == NULL) oss << "module=NULL"; diff --git a/hipamd/src/amdhip.def b/hipamd/src/amdhip.def index 1f0372e078..20bf383857 100644 --- a/hipamd/src/amdhip.def +++ b/hipamd/src/amdhip.def @@ -501,3 +501,4 @@ hipMemsetD2D32 hipMemsetD2D32Async hipStreamGetAttribute hipStreamSetAttribute +hipModuleLoadFatBinary diff --git a/hipamd/src/hip_api_trace.cpp b/hipamd/src/hip_api_trace.cpp index 72cbaba390..910d5b5dd9 100644 --- a/hipamd/src/hip_api_trace.cpp +++ b/hipamd/src/hip_api_trace.cpp @@ -535,6 +535,7 @@ hipError_t hipModuleLaunchKernel(hipFunction_t f, unsigned int gridDimX, unsigne unsigned int blockDimY, unsigned int blockDimZ, unsigned int sharedMemBytes, hipStream_t stream, void** kernelParams, void** extra); +hipError_t hipModuleLoadFatBinary(hipModule_t* module, const void* fatbin); hipError_t hipModuleLoad(hipModule_t* module, const char* fname); hipError_t hipModuleLoadData(hipModule_t* module, const void* image); hipError_t hipModuleLoadDataEx(hipModule_t* module, const void* image, unsigned int numOptions, @@ -1197,6 +1198,7 @@ void UpdateDispatchTable(HipDispatchTable* ptrDispatchTable) { ptrDispatchTable->hipModuleLaunchCooperativeKernelMultiDevice_fn = hip::hipModuleLaunchCooperativeKernelMultiDevice; ptrDispatchTable->hipModuleLaunchKernel_fn = hip::hipModuleLaunchKernel; + ptrDispatchTable->hipModuleLoadFatBinary_fn = hip::hipModuleLoadFatBinary; ptrDispatchTable->hipModuleLoad_fn = hip::hipModuleLoad; ptrDispatchTable->hipModuleLoadData_fn = hip::hipModuleLoadData; ptrDispatchTable->hipModuleLoadDataEx_fn = hip::hipModuleLoadDataEx; @@ -2024,13 +2026,14 @@ HIP_ENFORCE_ABI(HipDispatchTable, hipMemsetD2D32_fn, 482); HIP_ENFORCE_ABI(HipDispatchTable, hipMemsetD2D32Async_fn, 483); HIP_ENFORCE_ABI(HipDispatchTable, hipStreamGetAttribute_fn, 484); HIP_ENFORCE_ABI(HipDispatchTable, hipStreamSetAttribute_fn, 485); +HIP_ENFORCE_ABI(HipDispatchTable, hipModuleLoadFatBinary_fn, 486); // if HIP_ENFORCE_ABI entries are added for each new function pointer in the table, the number below // will be +1 of the number in the last HIP_ENFORCE_ABI line. E.g.: // // HIP_ENFORCE_ABI(, , 8) // // HIP_ENFORCE_ABI_VERSIONING(
, 9) <- 8 + 1 = 9 -HIP_ENFORCE_ABI_VERSIONING(HipDispatchTable, 486) +HIP_ENFORCE_ABI_VERSIONING(HipDispatchTable, 487) static_assert(HIP_RUNTIME_API_TABLE_MAJOR_VERSION == 0 && HIP_RUNTIME_API_TABLE_STEP_VERSION == 14, "If you get this error, add new HIP_ENFORCE_ABI(...) code for the new function " diff --git a/hipamd/src/hip_hcc.map.in b/hipamd/src/hip_hcc.map.in index d5f1ab6610..1bc44391c4 100644 --- a/hipamd/src/hip_hcc.map.in +++ b/hipamd/src/hip_hcc.map.in @@ -617,6 +617,7 @@ global: hipMemsetD2D32Async; hipStreamGetAttribute; hipStreamSetAttribute; + hipModuleLoadFatBinary; local: *; } hip_6.5; \ No newline at end of file diff --git a/hipamd/src/hip_module.cpp b/hipamd/src/hip_module.cpp index 8cef77d990..edbda15331 100644 --- a/hipamd/src/hip_module.cpp +++ b/hipamd/src/hip_module.cpp @@ -48,6 +48,11 @@ hipError_t hipModuleUnload(hipModule_t hmod) { CHECK_STREAM_CAPTURE_SUPPORTED(); HIP_RETURN(PlatformState::instance().unloadModule(hmod)); } +hipError_t hipModuleLoadFatBinary(hipModule_t* module, const void* fatbin) { + HIP_INIT_API(hipModuleLoadFatBinary, module, fatbin); + HIP_RETURN(PlatformState::instance().loadModule(module, 0, fatbin)); + HIP_RETURN(hipSuccess); +} hipError_t hipModuleLoad(hipModule_t* module, const char* fname) { HIP_INIT_API(hipModuleLoad, module, fname); diff --git a/hipamd/src/hip_table_interface.cpp b/hipamd/src/hip_table_interface.cpp index 614f0a6eed..8ec4e2a382 100644 --- a/hipamd/src/hip_table_interface.cpp +++ b/hipamd/src/hip_table_interface.cpp @@ -1254,6 +1254,9 @@ hipError_t hipModuleLaunchKernel(hipFunction_t f, unsigned int gridDimX, unsigne f, gridDimX, gridDimY, gridDimZ, blockDimX, blockDimY, blockDimZ, sharedMemBytes, stream, kernelParams, extra); } +hipError_t hipModuleLoadFatBinary(hipModule_t* module, const void* fatbin) { + return hip::GetHipDispatchTable()->hipModuleLoadFatBinary_fn(module, fatbin); +} hipError_t hipModuleLoad(hipModule_t* module, const char* fname) { return hip::GetHipDispatchTable()->hipModuleLoad_fn(module, fname); }