diff --git a/hipamd/include/hip/amd_detail/hip_api_trace.hpp b/hipamd/include/hip/amd_detail/hip_api_trace.hpp index 4473cded3c..65e9997dc1 100644 --- a/hipamd/include/hip/amd_detail/hip_api_trace.hpp +++ b/hipamd/include/hip/amd_detail/hip_api_trace.hpp @@ -51,8 +51,8 @@ // HipCompilerDispatchTable struct, such as a *change* to type/name an existing member variable. // DO NOT REMOVE IT. #define HIP_API_TABLE_MAJOR_VERSION 0 -#define HIP_RUNTIME_API_TABLE_MAJOR_VERSION 0 #define HIP_COMPILER_API_TABLE_MAJOR_VERSION 0 +#define HIP_RUNTIME_API_TABLE_MAJOR_VERSION 0 // The step version number should be changed whenever the size of the API table struct(s) change. // - Increment the HIP_API_TABLE_STEP_VERSION when/if new API table structs are added @@ -60,8 +60,8 @@ // - Increment the HIP_COMPILER_API_TABLE_STEP_VERSION when new compiler API functions are added // - Reset any of the *_STEP_VERSION defines to zero if the corresponding *_MAJOR_VERSION increases #define HIP_API_TABLE_STEP_VERSION 0 -#define HIP_RUNTIME_API_TABLE_STEP_VERSION 1 #define HIP_COMPILER_API_TABLE_STEP_VERSION 0 +#define HIP_RUNTIME_API_TABLE_STEP_VERSION 1 // HIP API interface typedef hipError_t (*t___hipPopCallConfiguration)(dim3* gridDim, dim3* blockDim, size_t* sharedMem, diff --git a/hipamd/src/CMakeLists.txt b/hipamd/src/CMakeLists.txt index 814bf33d0f..dccaa0fb88 100644 --- a/hipamd/src/CMakeLists.txt +++ b/hipamd/src/CMakeLists.txt @@ -291,23 +291,21 @@ if(WIN32) # rocprofiler-register is not support on Windows set(HIP_ENABLE_ROCPROFILER_REGISTER OFF) else() - option(HIP_ENABLE_ROCPROFILER_REGISTER "Enable rocprofiler-register support" OFF) + option(HIP_ENABLE_ROCPROFILER_REGISTER "Enable rocprofiler-register support" ON) endif() if(HIP_ENABLE_ROCPROFILER_REGISTER) - find_package(rocprofiler-register + find_package(rocprofiler-register REQUIRED HINTS $ENV{rocprofiler_register_ROOT} $ENV{ROCPROFILER_REGISTER_ROOT} ${CMAKE_INSTALL_PREFIX} PATHS /opt/rocm) - if(rocprofiler-register_FOUND) - # don't use HIP_VERSION_PATCH because it is too large (> 100) for rocprofiler register - target_compile_definitions(amdhip64 PRIVATE HIP_ROCPROFILER_REGISTER=1 - HIP_ROCP_REG_VERSION_MAJOR=${HIP_VERSION_MAJOR} - HIP_ROCP_REG_VERSION_MINOR=${HIP_VERSION_MINOR} - HIP_ROCP_REG_VERSION_PATCH=0) - target_link_libraries(amdhip64 PRIVATE rocprofiler-register::rocprofiler-register) - set_target_properties(amdhip64 PROPERTIES INSTALL_RPATH "\$ORIGIN") - endif() + # don't use HIP_VERSION_PATCH because it is too large (> 100) for rocprofiler register + target_compile_definitions(amdhip64 PRIVATE HIP_ROCPROFILER_REGISTER=1 + HIP_ROCP_REG_VERSION_MAJOR=${HIP_VERSION_MAJOR} + HIP_ROCP_REG_VERSION_MINOR=${HIP_VERSION_MINOR} + HIP_ROCP_REG_VERSION_PATCH=0) + target_link_libraries(amdhip64 PRIVATE rocprofiler-register::rocprofiler-register) + set_target_properties(amdhip64 PROPERTIES INSTALL_RPATH "\$ORIGIN") endif() add_custom_command(TARGET amdhip64 POST_BUILD COMMAND diff --git a/hipamd/src/hip_api_trace.cpp b/hipamd/src/hip_api_trace.cpp index 6110794a17..917e142016 100644 --- a/hipamd/src/hip_api_trace.cpp +++ b/hipamd/src/hip_api_trace.cpp @@ -1242,10 +1242,9 @@ void UpdateDispatchTable(HipDispatchTable* ptrDispatchTable) { #if HIP_ROCPROFILER_REGISTER > 0 template struct dispatch_table_info; -#define HIP_DEFINE_DISPATCH_TABLE_INFO(TYPE, NAME, NUM_FUNCTORS) \ +#define HIP_DEFINE_DISPATCH_TABLE_INFO(TYPE, NAME) \ template <> struct dispatch_table_info { \ static constexpr auto name = #NAME; \ - static constexpr auto size = ComputeTableSize(NUM_FUNCTORS); \ static constexpr auto version = HIP_ROCP_REG_VERSION; \ static constexpr auto import_func = &ROCPROFILER_REGISTER_IMPORT_FUNC(NAME); \ }; @@ -1254,8 +1253,8 @@ constexpr auto ComputeTableSize(size_t num_funcs) { return (num_funcs * sizeof(void*)) + sizeof(uint64_t); } -HIP_DEFINE_DISPATCH_TABLE_INFO(HipDispatchTable, hip, 440) -HIP_DEFINE_DISPATCH_TABLE_INFO(HipCompilerDispatchTable, hip_compiler, 9) +HIP_DEFINE_DISPATCH_TABLE_INFO(HipDispatchTable, hip) +HIP_DEFINE_DISPATCH_TABLE_INFO(HipCompilerDispatchTable, hip_compiler) #endif template void ToolInit(Tp* table) { @@ -1281,21 +1280,6 @@ template Tp& GetDispatchTableImpl() { // using a static inside a function prevents static initialization fiascos static auto dispatch_table = Tp{}; -#if HIP_ROCPROFILER_REGISTER > 0 - // cause a compiler error if the size of the API table changed (most likely due to addition of new - // dispatch table entry) to make sure the developer is reminded to update the table - // versioning value before changing the value in HIP_DEFINE_DISPATCH_TABLE_INFO to make this - // static assert pass. Please note: rocprofiler will do very strict compile time checks to make - // sure these versioning values are appropriately updated -- so commenting out this check, only - // updating the size field in HIP_DEFINE_DISPATCH_TABLE_INFO, etc. will result in the - // rocprofiler-sdk failing to build and your modifications will not be able to be staged. - static_assert( - sizeof(Tp) == dispatch_table_info::size, - "size of the API table struct has changed. Update the STEP_VERSION number (or in rare cases, " - "the MAJOR_VERSION number) in for the " - "failing API struct before changing the SIZE field passed to HIP_DEFINE_DISPATCH_TABLE_INFO"); -#endif - // Change all the function pointers to point to the HIP runtime implementation functions UpdateDispatchTable(&dispatch_table); @@ -1317,8 +1301,31 @@ const HipCompilerDispatchTable* GetHipCompilerDispatchTable() { } // namespace hip #if !defined(_WIN32) +constexpr auto ComputeTableOffset(size_t num_funcs) { + return (num_funcs * sizeof(void*)) + sizeof(size_t); +} + +// HIP_ENFORCE_ABI_VERSIONING will cause a compiler error if the size of the API table changed (most +// likely due to addition of new dispatch table entry) to make sure the developer is reminded to +// update the table versioning value before changing the value in HIP_ENFORCE_ABI_VERSIONING to make +// this static assert pass. +// +// HIP_ENFORCE_ABI will cause a compiler error if the order of the members in the API table change. Do not reorder member variables and change existing HIP_ENFORCE_ABI values -- always +// +// Please note: rocprofiler will do very strict compile time checks to make +// sure these versioning values are appropriately updated -- so commenting out this check, only +// updating the size field in HIP_ENFORCE_ABI_VERSIONING, etc. will result in the +// rocprofiler-sdk failing to build and you will be forced to do the work anyway. +#define HIP_ENFORCE_ABI_VERSIONING(TABLE, NUM) \ + static_assert( \ + sizeof(TABLE) == ComputeTableOffset(NUM), \ + "size of the API table struct has changed. Update the STEP_VERSION number (or in rare " \ + "cases, the MAJOR_VERSION number) in for " \ + "the failing API struct before changing the SIZE field passed to " \ + "HIP_DEFINE_DISPATCH_TABLE_INFO"); + #define HIP_ENFORCE_ABI(TABLE, ENTRY, NUM) \ - static_assert(offsetof(TABLE, ENTRY) == (sizeof(size_t) + (NUM * sizeof(void*))), \ + static_assert(offsetof(TABLE, ENTRY) == ComputeTableOffset(NUM), \ "ABI break for " #TABLE "." #ENTRY \ ". Only add new function pointers to end of struct and do not rearrange them " ); @@ -1333,6 +1340,14 @@ HIP_ENFORCE_ABI(HipCompilerDispatchTable, __hipRegisterTexture_fn, 6) HIP_ENFORCE_ABI(HipCompilerDispatchTable, __hipRegisterVar_fn, 7) HIP_ENFORCE_ABI(HipCompilerDispatchTable, __hipUnregisterFatBinary_fn, 8) +// 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(HipCompilerDispatchTable, 9) + static_assert(HIP_COMPILER_API_TABLE_MAJOR_VERSION == 0 && HIP_COMPILER_API_TABLE_STEP_VERSION == 0, "If you get this error, add new HIP_ENFORCE_ABI(...) code for the new function " "pointers and then update this check so it is true"); @@ -1768,18 +1783,29 @@ HIP_ENFORCE_ABI(HipDispatchTable, hipStreamGetCaptureInfo_v2_spt_fn, 425) HIP_ENFORCE_ABI(HipDispatchTable, hipLaunchHostFunc_spt_fn, 426) HIP_ENFORCE_ABI(HipDispatchTable, hipGetStreamDeviceId_fn, 427) HIP_ENFORCE_ABI(HipDispatchTable, hipDrvGraphAddMemsetNode_fn, 428) -HIP_ENFORCE_ABI(HipDispatchTable, hipGraphAddExternalSemaphoresWaitNode_fn, 429); -HIP_ENFORCE_ABI(HipDispatchTable, hipGraphAddExternalSemaphoresSignalNode_fn, 430); -HIP_ENFORCE_ABI(HipDispatchTable, hipGraphExternalSemaphoresSignalNodeSetParams_fn, 431); -HIP_ENFORCE_ABI(HipDispatchTable, hipGraphExternalSemaphoresWaitNodeSetParams_fn, 432); -HIP_ENFORCE_ABI(HipDispatchTable, hipGraphExternalSemaphoresSignalNodeGetParams_fn, 433); -HIP_ENFORCE_ABI(HipDispatchTable, hipGraphExternalSemaphoresWaitNodeGetParams_fn, 434); -HIP_ENFORCE_ABI(HipDispatchTable, hipGraphExecExternalSemaphoresSignalNodeSetParams_fn, 435); -HIP_ENFORCE_ABI(HipDispatchTable, hipGraphExecExternalSemaphoresWaitNodeSetParams_fn, 436); -HIP_ENFORCE_ABI(HipDispatchTable, hipGraphAddNode_fn, 437); -HIP_ENFORCE_ABI(HipDispatchTable, hipGraphInstantiateWithParams_fn, 438); +HIP_ENFORCE_ABI(HipDispatchTable, hipGraphAddExternalSemaphoresWaitNode_fn, 429) +HIP_ENFORCE_ABI(HipDispatchTable, hipGraphAddExternalSemaphoresSignalNode_fn, 430) +HIP_ENFORCE_ABI(HipDispatchTable, hipGraphExternalSemaphoresSignalNodeSetParams_fn, 431) +HIP_ENFORCE_ABI(HipDispatchTable, hipGraphExternalSemaphoresWaitNodeSetParams_fn, 432) +HIP_ENFORCE_ABI(HipDispatchTable, hipGraphExternalSemaphoresSignalNodeGetParams_fn, 433) +HIP_ENFORCE_ABI(HipDispatchTable, hipGraphExternalSemaphoresWaitNodeGetParams_fn, 434) +HIP_ENFORCE_ABI(HipDispatchTable, hipGraphExecExternalSemaphoresSignalNodeSetParams_fn, 435) +HIP_ENFORCE_ABI(HipDispatchTable, hipGraphExecExternalSemaphoresWaitNodeSetParams_fn, 436) +HIP_ENFORCE_ABI(HipDispatchTable, hipGraphAddNode_fn, 437) +HIP_ENFORCE_ABI(HipDispatchTable, hipGraphInstantiateWithParams_fn, 438) +HIP_ENFORCE_ABI(HipDispatchTable, hipExtGetLastError_fn, 439) +HIP_ENFORCE_ABI(HipDispatchTable, hipTexRefGetBorderColor_fn, 440) +HIP_ENFORCE_ABI(HipDispatchTable, hipTexRefGetArray_fn, 441) HIP_ENFORCE_ABI(HipDispatchTable, hipGetProcAddress_fn, 442) +// 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, 443) + static_assert(HIP_RUNTIME_API_TABLE_MAJOR_VERSION == 0 && HIP_RUNTIME_API_TABLE_STEP_VERSION == 1, "If you get this error, add new HIP_ENFORCE_ABI(...) code for the new function " "pointers and then update this check so it is true");