diff --git a/source/include/rocprofiler/callback_tracing.h b/source/include/rocprofiler/callback_tracing.h index d526c68c29..20d80c35af 100644 --- a/source/include/rocprofiler/callback_tracing.h +++ b/source/include/rocprofiler/callback_tracing.h @@ -24,7 +24,11 @@ #include #include +#include #include +#include + +#include ROCPROFILER_EXTERN_C_INIT @@ -35,69 +39,90 @@ ROCPROFILER_EXTERN_C_INIT * @{ */ +/** + * @brief ROCProfiler Enumeration for code object storage types (identical values to + * `hsa_ven_amd_loader_code_object_storage_type_t` enumeration) + */ +typedef enum +{ + ROCPROFILER_CODE_OBJECT_STORAGE_TYPE_NONE = HSA_VEN_AMD_LOADER_CODE_OBJECT_STORAGE_TYPE_NONE, + ROCPROFILER_CODE_OBJECT_STORAGE_TYPE_FILE = HSA_VEN_AMD_LOADER_CODE_OBJECT_STORAGE_TYPE_FILE, + ROCPROFILER_CODE_OBJECT_STORAGE_TYPE_MEMORY = + HSA_VEN_AMD_LOADER_CODE_OBJECT_STORAGE_TYPE_MEMORY, +} rocprofiler_code_object_storage_type_t; + /** * @brief ROCProfiler HSA API Callback Data. */ typedef struct { - size_t size; ///< provides the size of this struct + uint64_t size; ///< size of this struct rocprofiler_hsa_api_args_t args; rocprofiler_hsa_api_retval_t retval; -} rocprofiler_hsa_api_callback_tracer_data_t; - -/** - * @brief ROCProfiler HIP API Callback Data. - * - * Depending on the operation kind, the data can be casted to the corresponding - * structure. - * - */ -typedef void* rocprofiler_hip_api_callback_api_data_t; +} rocprofiler_callback_tracing_hsa_api_data_t; /** * @brief ROCProfiler HIP API Tracer Callback Data. */ typedef struct { - size_t size; - rocprofiler_correlation_id_t correlation_id; - rocprofiler_address_t host_kernel_address; - rocprofiler_hip_api_callback_api_data_t data; // Arguments or api_data? -} rocprofiler_hip_api_callback_tracer_data_t; - -/** - * @brief ROCProfiler Marker Callback Data. - * - * Depending on the operation kind, the data can be casted to the corresponding - * structure. - * - */ -typedef void* rocprofiler_marker_callback_api_data_t; + uint64_t size; ///< size of this struct + rocprofiler_hip_api_args_t args; + rocprofiler_hip_api_retval_t retval; +} rocprofiler_callback_tracing_hip_api_data_t; /** * @brief ROCProfiler Marker Tracer Callback Data. */ typedef struct { - size_t size; - rocprofiler_correlation_id_t correlation_id; - rocprofiler_marker_callback_api_data_t data; // Arguments or api_data? -} rocprofiler_marker_callback_tracer_data_t; + uint64_t size; ///< size of this struct + rocprofiler_marker_api_args_t args; + rocprofiler_marker_api_retval_t retval; +} rocprofiler_callback_tracing_marker_api_data_t; /** * @brief ROCProfiler Code Object Load Tracer Callback Record. */ typedef struct { - uint64_t load_base; // code object load base - uint64_t load_size; // code object load size - const char* uri; // URI string (NULL terminated) - // uint32_t storage_type; // code object storage type (Need Review?) - // int storage_file; // origin file descriptor (Need Review?) - // uint64_t memory_base; // origin memory base (Need Review?) - // uint64_t memory_size; // origin memory size (Need Review?) - // uint64_t load_delta; // code object load delta (Need Review?) -} rocprofiler_callback_tracer_code_object_load_data_t; + uint64_t size; ///< size of this struct + uint64_t code_object_id; ///< unique code object identifier + rocprofiler_agent_id_t rocp_agent; ///< The agent on which this loaded code object is loaded + hsa_agent_t hsa_agent; ///< The agent on which this loaded code object is loaded + const char* uri; ///< The URI name from which the code object was loaded + uint64_t load_base; ///< The base memory address at which the code object is loaded. This is + ///< the base address of the allocation for the lowest addressed segment of + ///< the code object that is loaded. Note that any non-loaded segments + ///< before the first loaded segment are ignored. + uint64_t load_size; ///< The byte size of the loaded code objects contiguous memory allocation. + uint64_t load_delta; ///< The signed byte address difference of the memory address at which the + ///< code object is loaded minus the virtual address specified in the code + ///< object that is loaded. + rocprofiler_code_object_storage_type_t + storage_type; ///< storage type of the code object reader used to load the loaded code + ///< object + union + { + struct + { + int storage_file; ///< file descriptor of the code object that was loaded. Access this + ///< field if @ref rocprofiler_code_object_storage_type_t is + ///< @ref ROCPROFILER_CODE_OBJECT_STORAGE_TYPE_FILE + }; + struct + { + uint64_t memory_base; ///< The memory address of the first byte of the code object that + ///< was loaded. Access this + ///< field if @ref rocprofiler_code_object_storage_type_t is + ///< @ref ROCPROFILER_CODE_OBJECT_STORAGE_TYPE_MEMORY + uint64_t memory_size; ///< The memory size in bytes of the code object that was loaded. + ///< Access this field if @ref + ///< rocprofiler_code_object_storage_type_t is + ///< @ref ROCPROFILER_CODE_OBJECT_STORAGE_TYPE_MEMORY + }; + }; +} rocprofiler_callback_tracing_code_object_load_data_t; /** * @brief ROCProfiler Code Object UnLoad Tracer Callback Record. @@ -105,18 +130,31 @@ typedef struct */ typedef struct { - uint64_t load_base; // code object load base -} rocprofiler_callback_tracer_code_object_unload_data_t; + uint64_t size; ///< size of this struct + uint64_t code_object_id; ///< unique code object identifier +} rocprofiler_callback_tracing_code_object_unload_data_t; /** - * @brief ROCProfiler Code Object Device Kernel Symbol Tracer Callback Record. + * @brief ROCProfiler Code Object Kernel Symbol Tracer Callback Record. * */ typedef struct { - const char* kernel_name; // kernel name string (NULL terminated) - rocprofiler_address_t kernel_descriptor; // kernel descriptor -} rocprofiler_callback_tracer_code_object_device_kernel_symbol_data_t; + uint64_t size; ///< size of this struct + uint64_t kernel_id; ///< unique symbol identifier value + uint64_t code_object_id; ///< parent unique code object identifier + rocprofiler_agent_id_t rocp_agent; ///< Agent associated with this symbol + const char* kernel_name; ///< name of the kernel + uint64_t kernel_object; ///< kernel object handle, used in the kernel dispatch packet + uint32_t kernarg_segment_size; ///< size of memory (in bytes) allocated for kernel arguments. + ///< Will be multiple of 16 + uint32_t kernarg_segment_alignment; ///< Alignment (in bytes) of the buffer used to pass + ///< arguments to the kernel + uint32_t group_segment_size; ///< Size of static group segment memory required by the kernel + ///< (per work-group), in bytes + uint32_t private_segment_size; ///< Size of static private, spill, and arg segment memory + ///< required by this kernel (per work-item), in bytes. +} rocprofiler_callback_tracing_code_object_kernel_symbol_data_t; /** * @brief ROCProfiler Code Object Register Host Kernel Symbol Tracer Callback @@ -125,11 +163,12 @@ typedef struct */ typedef struct { + uint64_t size; ///< size of this struct rocprofiler_address_t host_address; // host address // Should this be nullptr if it is unregister? const char* kernel_name; // kernel name string (NULL terminated) rocprofiler_address_t kernel_descriptor; // kernel descriptor -} rocprofiler_callback_tracer_code_object_register_host_kernel_symbol_data_t; +} rocprofiler_callback_tracing_code_object_register_host_kernel_symbol_data_t; /** * @brief API Tracing callback function. This function is invoked twice per API function: once diff --git a/source/include/rocprofiler/fwd.h b/source/include/rocprofiler/fwd.h index b8a87b0973..8bc6c45fd6 100644 --- a/source/include/rocprofiler/fwd.h +++ b/source/include/rocprofiler/fwd.h @@ -106,7 +106,13 @@ typedef enum // NOLINT(performance-enum-size) { ROCPROFILER_SERVICE_CALLBACK_PHASE_NONE = 0, ///< Callback has no phase ROCPROFILER_SERVICE_CALLBACK_PHASE_ENTER, ///< Callback invoked prior to function execution - ROCPROFILER_SERVICE_CALLBACK_PHASE_EXIT, ///< Callback invoked after to function execution + ROCPROFILER_SERVICE_CALLBACK_PHASE_LOAD = + ROCPROFILER_SERVICE_CALLBACK_PHASE_ENTER, ///< Callback invoked prior to code object + ///< loading + ROCPROFILER_SERVICE_CALLBACK_PHASE_EXIT, ///< Callback invoked after to function execution + ROCPROFILER_SERVICE_CALLBACK_PHASE_UNLOAD = + ROCPROFILER_SERVICE_CALLBACK_PHASE_EXIT, ///< Callback invoked prior to code object + ///< unloading ROCPROFILER_SERVICE_CALLBACK_PHASE_LAST, } rocprofiler_service_callback_phase_t; diff --git a/source/include/rocprofiler/hip.h b/source/include/rocprofiler/hip.h index 3a6eff20f4..3b5bc85f96 100644 --- a/source/include/rocprofiler/hip.h +++ b/source/include/rocprofiler/hip.h @@ -24,27 +24,3 @@ #include #include - -#include - -typedef struct rocprofiler_hip_trace_data_s rocprofiler_hip_trace_data_t; -typedef struct rocprofiler_hip_api_data_s rocprofiler_hip_api_data_t; - -struct rocprofiler_hip_api_data_s -{ - uint64_t correlation_id; - uint32_t phase; - rocprofiler_hip_api_args_t args; - uint64_t* phase_data; -}; - -struct rocprofiler_hip_trace_data_s -{ - rocprofiler_hip_api_data_t api_data; - uint64_t phase_enter_timestamp; - uint64_t phase_exit_timestamp; - uint64_t phase_data; - - void (*phase_enter)(rocprofiler_hip_api_id_t operation_id, rocprofiler_hip_trace_data_t* data); - void (*phase_exit)(rocprofiler_hip_api_id_t operation_id, rocprofiler_hip_trace_data_t* data); -}; diff --git a/source/include/rocprofiler/hip/api_args.h b/source/include/rocprofiler/hip/api_args.h index 79e62d5aa5..3f60030842 100644 --- a/source/include/rocprofiler/hip/api_args.h +++ b/source/include/rocprofiler/hip/api_args.h @@ -22,6 +22,13 @@ #include +typedef union rocprofiler_hip_api_retval_u +{ + int int_retval; + const char* const_charp_retval; + hipError_t hipError_t_retval; +} rocprofiler_hip_api_retval_t; + typedef union rocprofiler_hip_api_args_u { struct diff --git a/source/include/rocprofiler/hip/api_id.h b/source/include/rocprofiler/hip/api_id.h index e0b572135a..bc1ca47b6d 100644 --- a/source/include/rocprofiler/hip/api_id.h +++ b/source/include/rocprofiler/hip/api_id.h @@ -20,8 +20,10 @@ #pragma once -// NOLINTNEXTLINE(performance-enum-size) -typedef enum +/** + * @brief ROCProfiler enumeration of HIP API tracing operations + */ +typedef enum // NOLINT(performance-enum-size) { ROCPROFILER_HIP_API_ID_NONE = -1, ROCPROFILER_HIP_API_ID___hipPopCallConfiguration = 0, diff --git a/source/include/rocprofiler/hsa.h b/source/include/rocprofiler/hsa.h index 51fe506648..1565fc6afb 100644 --- a/source/include/rocprofiler/hsa.h +++ b/source/include/rocprofiler/hsa.h @@ -41,17 +41,3 @@ #if defined(ROCPROFILER_DEFINED_AMD_INTERNAL_BUILD) && ROCPROFILER_DEFINED_AMD_INTERNAL_BUILD > 0 # undef AMD_INTERNAL_BUILD #endif - -#include - -typedef struct hsa_kernel_dispatch_packet_s hsa_kernel_dispatch_packet_t; -typedef struct rocprofiler_hsa_api_data_s rocprofiler_hsa_api_data_t; - -struct rocprofiler_hsa_api_data_s -{ - uint64_t correlation_id; - uint32_t phase; - rocprofiler_hsa_api_args_t args; - rocprofiler_hsa_api_retval_t retval; - uint64_t* phase_data; -}; diff --git a/source/include/rocprofiler/hsa/api_id.h b/source/include/rocprofiler/hsa/api_id.h index 1a2007a431..ffa1bc8b7d 100644 --- a/source/include/rocprofiler/hsa/api_id.h +++ b/source/include/rocprofiler/hsa/api_id.h @@ -22,8 +22,10 @@ #include -// NOLINTNEXTLINE(performance-enum-size) -typedef enum +/** + * @brief ROCProfiler enumeration of HSA API tracing operations + */ +typedef enum // NOLINT(performance-enum-size) { ROCPROFILER_HSA_API_ID_NONE = -1, // block: CoreApi API diff --git a/source/include/rocprofiler/marker.h b/source/include/rocprofiler/marker.h index 9bb3afe123..286ab6615d 100644 --- a/source/include/rocprofiler/marker.h +++ b/source/include/rocprofiler/marker.h @@ -23,10 +23,4 @@ #pragma once #include - -typedef struct rocprofiler_roctx_api_data_s rocprofiler_roctx_api_data_t; - -struct rocprofiler_roctx_api_data_s -{ - rocprofiler_roctx_api_args_t args; -}; +#include diff --git a/source/include/rocprofiler/marker/api_args.h b/source/include/rocprofiler/marker/api_args.h index e3db2ed01e..472465e8da 100644 --- a/source/include/rocprofiler/marker/api_args.h +++ b/source/include/rocprofiler/marker/api_args.h @@ -24,7 +24,13 @@ typedef uint64_t roctx_range_id_t; -typedef union rocprofiler_roctx_api_args_u +typedef union rocprofiler_marker_api_retval_u +{ + uint32_t uint32_t_retval; + uint64_t uint64_t_retval; +} rocprofiler_marker_api_retval_t; + +typedef union rocprofiler_marker_api_args_u { struct { @@ -36,16 +42,13 @@ typedef union rocprofiler_roctx_api_args_u } roctxRangePushA; struct { - const char* message; } roctxRangePop; struct { - const char* message; - roctx_range_id_t id; + const char* message; } roctxRangeStartA; struct { - const char* message; roctx_range_id_t id; } roctxRangeStop; -} rocprofiler_roctx_api_args_t; +} rocprofiler_marker_api_args_t; diff --git a/source/include/rocprofiler/marker/api_id.h b/source/include/rocprofiler/marker/api_id.h index 95cc8c00ba..2f898c07cc 100644 --- a/source/include/rocprofiler/marker/api_id.h +++ b/source/include/rocprofiler/marker/api_id.h @@ -20,14 +20,16 @@ #pragma once -// NOLINTNEXTLINE(performance-enum-size) -typedef enum +/** + * @brief ROCProfiler enumeration of Marker (ROCTx) API tracing operations + */ +typedef enum // NOLINT(performance-enum-size) { - ROCPROFILER_ROCTX_API_ID_NONE = -1, - ROCPROFILER_ROCTX_API_ID_roctxMarkA = 0, - ROCPROFILER_ROCTX_API_ID_roctxRangePushA, - ROCPROFILER_ROCTX_API_ID_roctxRangePop, - ROCPROFILER_ROCTX_API_ID_roctxRangeStartA, - ROCPROFILER_ROCTX_API_ID_roctxRangeStop, - ROCPROFILER_ROCTX_API_ID_LAST, -} rocprofiler_roctx_api_id_t; + ROCPROFILER_MARKER_API_ID_NONE = -1, + ROCPROFILER_MARKER_API_ID_roctxMarkA = 0, + ROCPROFILER_MARKER_API_ID_roctxRangePushA, + ROCPROFILER_MARKER_API_ID_roctxRangePop, + ROCPROFILER_MARKER_API_ID_roctxRangeStartA, + ROCPROFILER_MARKER_API_ID_roctxRangeStop, + ROCPROFILER_MARKER_API_ID_LAST, +} rocprofiler_marker_api_id_t; diff --git a/source/lib/rocprofiler/callback_tracing.cpp b/source/lib/rocprofiler/callback_tracing.cpp index e2590fe650..440e104079 100644 --- a/source/lib/rocprofiler/callback_tracing.cpp +++ b/source/lib/rocprofiler/callback_tracing.cpp @@ -205,7 +205,7 @@ rocprofiler_iterate_callback_tracing_kind_operation_args( { rocprofiler::hsa::iterate_args( record.operation, - *static_cast(record.payload), + *static_cast(record.payload), callback, user_data); return ROCPROFILER_STATUS_SUCCESS; diff --git a/source/lib/rocprofiler/hsa/defines.hpp b/source/lib/rocprofiler/hsa/defines.hpp index b6b7117aa6..2f6a4df6bc 100644 --- a/source/lib/rocprofiler/hsa/defines.hpp +++ b/source/lib/rocprofiler/hsa/defines.hpp @@ -138,13 +138,13 @@ \ static auto get_functor() { return get_functor(get_table_func()); } \ \ - static std::vector as_arg_addr(rocprofiler_hsa_api_callback_tracer_data_t) \ + static std::vector as_arg_addr(rocprofiler_callback_tracing_hsa_api_data_t) \ { \ return std::vector{}; \ } \ \ static std::vector> as_arg_list( \ - rocprofiler_hsa_api_callback_tracer_data_t) \ + rocprofiler_callback_tracing_hsa_api_data_t) \ { \ return {}; \ } \ @@ -211,13 +211,13 @@ static auto get_functor() { return get_functor(get_table_func()); } \ \ static std::vector as_arg_addr( \ - rocprofiler_hsa_api_callback_tracer_data_t trace_data) \ + rocprofiler_callback_tracing_hsa_api_data_t trace_data) \ { \ return std::vector{ \ GET_ADDR_MEMBER_FIELDS(get_api_data_args(trace_data.args), __VA_ARGS__)}; \ } \ \ - static auto as_arg_list(rocprofiler_hsa_api_callback_tracer_data_t trace_data) \ + static auto as_arg_list(rocprofiler_callback_tracing_hsa_api_data_t trace_data) \ { \ return utils::stringize( \ GET_NAMED_MEMBER_FIELDS(get_api_data_args(trace_data.args), __VA_ARGS__)); \ diff --git a/source/lib/rocprofiler/hsa/hsa.cpp b/source/lib/rocprofiler/hsa/hsa.cpp index 4bb3d4c7d6..3811f518b7 100644 --- a/source/lib/rocprofiler/hsa/hsa.cpp +++ b/source/lib/rocprofiler/hsa/hsa.cpp @@ -228,7 +228,7 @@ hsa_api_impl::functor(Args&&... args) constexpr auto empty_user_data = rocprofiler_user_data_t{.value = 0}; auto buffer_record = rocprofiler_buffer_tracing_hsa_api_record_t{}; - auto tracer_data = rocprofiler_hsa_api_callback_tracer_data_t{}; + auto tracer_data = rocprofiler_callback_tracing_hsa_api_data_t{}; auto internal_corr_id = context::correlation_tracing_service::get_unique_internal_id(); // construct the buffered info before the callback so the callbacks are as closely wrapped @@ -246,7 +246,7 @@ hsa_api_impl::functor(Args&&... args) // invoke the callbacks if(!callback_contexts.empty()) { - tracer_data.size = sizeof(rocprofiler_hsa_api_callback_tracer_data_t); + tracer_data.size = sizeof(rocprofiler_callback_tracing_hsa_api_data_t); set_data_args(info_type::get_api_data_args(tracer_data.args), std::forward(args)...); for(auto& itr : callback_contexts) @@ -382,10 +382,10 @@ id_by_name(const char* name, std::index_sequence) template void -iterate_args(const uint32_t id, - const rocprofiler_hsa_api_callback_tracer_data_t& data, - rocprofiler_callback_tracing_operation_args_cb_t func, - void* user_data, +iterate_args(const uint32_t id, + const rocprofiler_callback_tracing_hsa_api_data_t& data, + rocprofiler_callback_tracing_operation_args_cb_t func, + void* user_data, std::index_sequence) { if(Idx == id) @@ -495,10 +495,10 @@ id_by_name(const char* name) } void -iterate_args(uint32_t id, - const rocprofiler_hsa_api_callback_tracer_data_t& data, - rocprofiler_callback_tracing_operation_args_cb_t callback, - void* user_data) +iterate_args(uint32_t id, + const rocprofiler_callback_tracing_hsa_api_data_t& data, + rocprofiler_callback_tracing_operation_args_cb_t callback, + void* user_data) { if(callback) iterate_args( diff --git a/source/lib/rocprofiler/hsa/hsa.hpp b/source/lib/rocprofiler/hsa/hsa.hpp index 78eb3991ea..757e27217c 100644 --- a/source/lib/rocprofiler/hsa/hsa.hpp +++ b/source/lib/rocprofiler/hsa/hsa.hpp @@ -64,10 +64,10 @@ uint32_t id_by_name(const char* name); void -iterate_args(uint32_t id, - const rocprofiler_hsa_api_callback_tracer_data_t& data, - rocprofiler_callback_tracing_operation_args_cb_t callback, - void* user_data); +iterate_args(uint32_t id, + const rocprofiler_callback_tracing_hsa_api_data_t& data, + rocprofiler_callback_tracing_operation_args_cb_t callback, + void* user_data); std::vector get_names();