Skip to content

Commit

Permalink
Update HSA ABI checks for tracing (#1027)
Browse files Browse the repository at this point in the history
* Update HSA ABI checks for tracing

* Update lib/common/abi.hpp

- perform ABI versioning checks even when `ROCPROFILER_CI` is not defined (or ROCPROFILER_CI=0)

* Enforce versioning size for various HSA AmdExt step versions + hsa_amd_enable_logging support

* Minor HIP abi.cpp updates
  • Loading branch information
jrmadsen authored Aug 20, 2024
1 parent 5d54682 commit 7a639f3
Show file tree
Hide file tree
Showing 9 changed files with 363 additions and 226 deletions.
3 changes: 3 additions & 0 deletions source/include/rocprofiler-sdk/hsa/amd_ext_api_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ typedef enum // NOLINT(performance-enum-size)
# if HSA_AMD_EXT_API_TABLE_STEP_VERSION >= 0x03
ROCPROFILER_HSA_AMD_EXT_API_ID_hsa_amd_vmem_address_reserve_align,
# endif
# if HSA_AMD_EXT_API_TABLE_STEP_VERSION >= 0x04
ROCPROFILER_HSA_AMD_EXT_API_ID_hsa_amd_enable_logging,
# endif
#endif

ROCPROFILER_HSA_AMD_EXT_API_ID_LAST,
Expand Down
7 changes: 7 additions & 0 deletions source/include/rocprofiler-sdk/hsa/api_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,13 @@ typedef union rocprofiler_hsa_api_args_t
uint64_t flags;
} hsa_amd_vmem_address_reserve_align;
# endif
# if HSA_AMD_EXT_API_TABLE_STEP_VERSION >= 0x04
struct
{
uint8_t* flags;
void* file;
} hsa_amd_enable_logging;
# endif
#endif
} rocprofiler_hsa_api_args_t;

Expand Down
20 changes: 19 additions & 1 deletion source/lib/common/abi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ compute_table_offset(size_t num_funcs)
// sure these versioning values are appropriately updated -- so commenting out this check, only
// updating the size field in ROCP_SDK_ENFORCE_ABI_VERSIONING, etc. will result in the
// rocprofiler-sdk failing to build and you will be forced to do the work anyway.
#if !defined(ROCPROFILER_UNSAFE_NO_VERSION_CHECK) && (defined(ROCPROFILER_CI) && ROCPROFILER_CI > 0)
#if !defined(ROCPROFILER_UNSAFE_NO_VERSION_CHECK)
# define ROCP_SDK_ENFORCE_ABI_VERSIONING(TABLE, NUM) \
static_assert( \
sizeof(TABLE) == ::rocprofiler::common::abi::compute_table_offset(NUM), \
Expand All @@ -72,3 +72,21 @@ compute_table_offset(size_t num_funcs)
# define ROCP_SDK_ENFORCE_ABI_VERSIONING(TABLE, NUM)
# define ROCP_SDK_ENFORCE_ABI(TABLE, ENTRY, NUM)
#endif

// These are guarded by ROCPROFILER_CI=1
#if !defined(ROCPROFILER_UNSAFE_NO_VERSION_CHECK) && (defined(ROCPROFILER_CI) && ROCPROFILER_CI > 0)
# define INTERNAL_CI_ROCP_SDK_ENFORCE_ABI_VERSIONING(TABLE, NUM) \
static_assert( \
sizeof(TABLE) == ::rocprofiler::common::abi::compute_table_offset(NUM), \
"size of the API table struct has changed. Update the STEP_VERSION number (or " \
"in rare cases, the MAJOR_VERSION number)");

# define INTERNAL_CI_ROCP_SDK_ENFORCE_ABI(TABLE, ENTRY, NUM) \
static_assert( \
offsetof(TABLE, ENTRY) == ::rocprofiler::common::abi::compute_table_offset(NUM), \
"ABI break for " #TABLE "." #ENTRY \
". Only add new function pointers to end of struct and do not rearrange them");
#else
# define INTERNAL_CI_ROCP_SDK_ENFORCE_ABI_VERSIONING(TABLE, NUM)
# define INTERNAL_CI_ROCP_SDK_ENFORCE_ABI(TABLE, ENTRY, NUM)
#endif
11 changes: 7 additions & 4 deletions source/lib/rocprofiler-sdk/hip/abi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace hip
{
static_assert(HIP_COMPILER_API_TABLE_MAJOR_VERSION == 0,
"Major version updated for HIP compiler dispatch table");
static_assert(HIP_RUNTIME_API_TABLE_MAJOR_VERSION == 0,
"Major version updated for HIP runtime dispatch table");

// These ensure that function pointers are not re-ordered
ROCP_SDK_ENFORCE_ABI(HipCompilerDispatchTable, __hipPopCallConfiguration_fn, 0)
Expand All @@ -46,11 +48,10 @@ ROCP_SDK_ENFORCE_ABI(HipCompilerDispatchTable, __hipUnregisterFatBinary_fn, 8)

#if HIP_COMPILER_API_TABLE_STEP_VERSION == 0
ROCP_SDK_ENFORCE_ABI_VERSIONING(HipCompilerDispatchTable, 9)
#else
ROCP_SDK_ENFORCE_ABI_VERSIONING(HipCompilerDispatchTable, 0)
#endif

static_assert(HIP_RUNTIME_API_TABLE_MAJOR_VERSION == 0,
"Major version updated for HIP runtime dispatch table");

// These ensure that function pointers are not re-ordered
ROCP_SDK_ENFORCE_ABI(HipDispatchTable, hipApiName_fn, 0)
ROCP_SDK_ENFORCE_ABI(HipDispatchTable, hipArray3DCreate_fn, 1)
Expand Down Expand Up @@ -520,7 +521,9 @@ ROCP_SDK_ENFORCE_ABI_VERSIONING(HipDispatchTable, 444)
#elif HIP_RUNTIME_API_TABLE_STEP_VERSION == 3
ROCP_SDK_ENFORCE_ABI_VERSIONING(HipDispatchTable, 445)
#elif HIP_RUNTIME_API_TABLE_STEP_VERSION == 4
ROCP_SDK_ENFORCE_ABI_VERSIONING(HipDispatchTable, 459)
INTERNAL_CI_ROCP_SDK_ENFORCE_ABI_VERSIONING(HipDispatchTable, 458)
#else
INTERNAL_CI_ROCP_SDK_ENFORCE_ABI_VERSIONING(HipDispatchTable, 0)
#endif
} // namespace hip
} // namespace rocprofiler
2 changes: 1 addition & 1 deletion source/lib/rocprofiler-sdk/hsa/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
set(ROCPROFILER_LIB_HSA_SOURCES
abi.cpp
agent_cache.cpp
aql_packet.cpp
async_copy.cpp
Expand All @@ -25,7 +26,6 @@ set(ROCPROFILER_LIB_HSA_HEADERS
queue_info_session.hpp
rocprofiler_packet.hpp
scratch_memory.hpp
types.hpp
utils.hpp)

target_sources(rocprofiler-object-library PRIVATE ${ROCPROFILER_LIB_HSA_SOURCES}
Expand Down
Loading

0 comments on commit 7a639f3

Please sign in to comment.