Callback tracing for kernel dispatches + External correlation ID request service (#682)

* Support ROCPROFILER_CALLBACK_TRACING_KERNEL_DISPATCH

* Fix doxygen

* Update callback tracing

- temporary hacks for kind operation name and iterate kind operations

* Update source/include/rocprofiler-sdk

- introduce sequence id for kernel dispatches

* Update lib/rocprofiler-sdk (seq id)

- support sequence id passing

* Update tests (seq id)

- testing for sequence ids

* Cleanup include/rocprofiler-sdk/fwd.h

* Misc cleanup

* External Correlation ID Request Service (#699)

* External correlation ID request service

- callback requesting an external correlation ID instead of fetching from top of pushed external correlation ID stack

* Update external correlation id request support

- pass internal correlation ID in callback
- async copy generates a correlation ID if none already exists
- added external correlation ID request support for scratch memory tracing
- updated scratch memory tracing to use tracing:: functions

* Update hsa/queue.hpp

- new line at EOF

* Misc tweaks

- remove unnecessary logging in agent.cpp
- correlation_id::add_ref_count check for retirement
- finalization check in HSA queue AsyncSignalHandler

* Improve assertion failure logging in misc tests

* Update include/rocprofiler-sdk/fwd.h

- remove rocprofiler_record_counter_header_t

* Move lib/rocprofiler-sdk/tracing.hpp into lib/rocprofiler-sdk/tracing/ folder

* Update lib/rocprofiler-sdk/hsa/*

- hsa::get_hsa_status_string
- queue_info_session.hpp header
- rocprofiler_packet.hpp

* Update lib/rocprofiler-sdk/{counters,hip,marker}

- execute_phase_exit_callbacks tweaks
- queue_info_session tweaks

* Move rocprofiler_kernel_dispatch_operation_t to include/rocprofiler-sdk/fwd.h

* Update rocprofiler_buffer_tracing_kernel_dispatch_record_t

- add operation field and thread_id field

* Add lib/rocprofiler-sdk/kernel_dispatch

- enum <-> string mapping for kernel dispatch
- tracing implementations

* Update lib/rocprofiler-sdk/CMakeLists.txt

- tracing and kernel dispatch sub-directories

* Update lib/rocprofiler-sdk/{buffer,callback}_tracing.cpp

- invoke rocprofiler::kernel_tracing functions

* Update tests/common/serialization.hpp

- support operation and thread_id fields for rocprofiler_buffer_tracing_kernel_dispatch_record_t

* Update tests/tools/json-tool.cpp

- use external correlation id request service

* Rename sequence_id to dispatch_id
This commit is contained in:
Jonathan R. Madsen
2024-04-11 19:49:49 -05:00
committed by GitHub
parent 0f5c575435
commit 56030018dc
46 changed files with 2297 additions and 955 deletions
+25 -13
View File
@@ -122,20 +122,32 @@ typedef struct
/**
* @brief ROCProfiler Buffer Kernel Dispatch Tracer Record.
*/
typedef struct
typedef struct rocprofiler_buffer_tracing_kernel_dispatch_record_t
{
uint64_t size; ///< size of this struct
rocprofiler_buffer_tracing_kind_t kind; ///< ::ROCPROFILER_BUFFER_TRACING_KERNEL_DISPATCH
rocprofiler_correlation_id_t correlation_id; ///< correlation ids for record
rocprofiler_timestamp_t start_timestamp; ///< start time in nanoseconds
rocprofiler_timestamp_t end_timestamp; ///< end time in nanoseconds
rocprofiler_agent_id_t agent_id; ///< agent kernel was dispatched on
rocprofiler_queue_id_t queue_id; ///< queue kernel was dispatched on
rocprofiler_kernel_id_t kernel_id; ///< identifier for kernel
uint32_t private_segment_size; /// runtime private memory segment size
uint32_t group_segment_size; /// runtime group memory segment size
rocprofiler_dim3_t workgroup_size; /// runtime workgroup size (grid * threads)
rocprofiler_dim3_t grid_size; /// runtime grid size
uint64_t size; ///< size of this struct
rocprofiler_buffer_tracing_kind_t kind; ///< ::ROCPROFILER_BUFFER_TRACING_KERNEL_DISPATCH
rocprofiler_kernel_dispatch_operation_t operation; ///<
rocprofiler_correlation_id_t correlation_id; ///< correlation ids for record
rocprofiler_thread_id_t thread_id; ///< id for thread that launched kernel
rocprofiler_timestamp_t start_timestamp; ///< start time in nanoseconds
rocprofiler_timestamp_t end_timestamp; ///< end time in nanoseconds
rocprofiler_agent_id_t agent_id; ///< agent kernel was dispatched on
rocprofiler_queue_id_t queue_id; ///< queue kernel was dispatched on
rocprofiler_kernel_id_t kernel_id; ///< identifier for kernel
rocprofiler_dispatch_id_t dispatch_id; ///< unique id for each dispatch
uint32_t private_segment_size;
uint32_t group_segment_size;
rocprofiler_dim3_t workgroup_size;
rocprofiler_dim3_t grid_size;
/// @var private_segment_size
/// @brief runtime private memory segment size
/// @var group_segment_size
/// @brief runtime group memory segment size
/// @var workgroup_size
/// @brief runtime workgroup size (grid * threads)
/// @var grid_size
/// @brief runtime grid size
} rocprofiler_buffer_tracing_kernel_dispatch_record_t;
/**
@@ -156,10 +156,38 @@ typedef struct
} rocprofiler_callback_tracing_code_object_kernel_symbol_register_data_t;
/**
* @brief ROCProfiler Kernel Dispatch Callback Tracer Record.
*
*/
typedef struct rocprofiler_callback_tracing_kernel_dispatch_data_t
{
uint64_t size; ///< size of this struct
rocprofiler_timestamp_t start_timestamp; ///< start time in nanoseconds
rocprofiler_timestamp_t end_timestamp; ///< end time in nanoseconds
rocprofiler_agent_id_t agent_id; ///< agent kernel was dispatched on
rocprofiler_queue_id_t queue_id; ///< queue kernel was dispatched on
rocprofiler_kernel_id_t kernel_id; ///< identifier for kernel
rocprofiler_dispatch_id_t dispatch_id; ///< unique id for each dispatch
uint32_t private_segment_size;
uint32_t group_segment_size;
rocprofiler_dim3_t workgroup_size;
rocprofiler_dim3_t grid_size;
/// @var private_segment_size
/// @brief runtime private memory segment size
/// @var group_segment_size
/// @brief runtime group memory segment size
/// @var workgroup_size
/// @brief runtime workgroup size (grid * threads)
/// @var grid_size
/// @brief runtime grid size
} rocprofiler_callback_tracing_kernel_dispatch_data_t;
/**
* @brief ROCProfiler Scratch Memory Callback Data.
*/
typedef struct
typedef struct rocprofiler_callback_tracing_scratch_memory_data_t
{
uint64_t size; ///< size of this struct
rocprofiler_agent_id_t agent_id;
@@ -44,14 +44,15 @@ ROCPROFILER_EXTERN_C_INIT
typedef struct rocprofiler_profile_counting_dispatch_data_t
{
uint64_t size; ///< Size of this struct
rocprofiler_kernel_id_t kernel_id; ///< Kernel identifier
rocprofiler_agent_id_t agent_id; ///< Agent ID where kernel is launched
rocprofiler_queue_id_t queue_id; ///< Queue ID where kernel packet is enqueued
rocprofiler_kernel_id_t kernel_id; ///< Kernel identifier
rocprofiler_dispatch_id_t dispatch_id; ///< unique id for each dispatch
rocprofiler_correlation_id_t correlation_id; ///< Correlation ID for this dispatch
uint32_t private_segment_size; /// runtime private memory segment size
uint32_t group_segment_size; /// runtime group memory segment size
rocprofiler_dim3_t workgroup_size; /// runtime workgroup size (grid * threads)
rocprofiler_dim3_t grid_size; /// runtime grid size
uint32_t private_segment_size; ///< runtime private memory segment size
uint32_t group_segment_size; ///< runtime group memory segment size
rocprofiler_dim3_t workgroup_size; ///< runtime workgroup size (grid * threads)
rocprofiler_dim3_t grid_size; ///< runtime grid size
} rocprofiler_profile_counting_dispatch_data_t;
/**
@@ -34,6 +34,99 @@ ROCPROFILER_EXTERN_C_INIT
* @{
*/
/**
* @brief ROCProfiler External Correlation ID Operations.
*
* These kinds correspond to callback and buffered tracing kinds (@see
* ::rocprofiler_callback_tracing_kind_t and ::rocprofiler_buffer_tracing_kind_t) which generate
* correlation IDs. Typically, rocprofiler-sdk uses the most recent external correlation ID on the
* current thread set via ::rocprofiler_push_external_correlation_id; however, this approach can be
* problematic if a new external correlation ID should be set before the
* ::ROCPROFILER_CALLBACK_PHASE_ENTER callback or if relevant external correlation IDs are desired
* when the buffered tracing is used. Thus, rocprofiler-sdk provides a way for tools to get a
* callback whenever an external correlation ID is needed. However, this can add significant
* overhead for those who only need these callbacks for, say, kernel dispatches while the HSA API is
* being traced (i.e. lots of callbacks for HSA API functions). The enumeration below is provided to
* ensure that tools can default to using the external correlation IDs set via the push/pop methods
* where the external correlation ID value is not important while also getting a request for an
* external correlation ID for other tracing kinds.
*/
typedef enum // NOLINT(performance-enum-size)
{
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_NONE = 0, ///< Unknown kind
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_HSA_CORE_API, ///<
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_HSA_AMD_EXT_API, ///<
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_HSA_IMAGE_EXT_API, ///<
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_HSA_FINALIZE_EXT_API, ///<
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_HIP_RUNTIME_API, ///<
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_HIP_COMPILER_API, ///<
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_MARKER_CORE_API, ///<
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_MARKER_CONTROL_API, ///<
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_MARKER_NAME_API, ///<
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_MEMORY_COPY,
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_KERNEL_DISPATCH,
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_SCRATCH_MEMORY,
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_LAST,
} rocprofiler_external_correlation_id_request_kind_t;
/**
* @brief Callback requesting a value for the external correlation id.
*
* @param [in] thread_id Id of the thread making the request
* @param [in] context_id Id of the context making the request
* @param [in] kind Origin of the external correlation id request
* @param [in] operation Regardless of whether callback or buffer tracing is being used, the
* operation value will be the same, i.e., regardless of whether callback kind is
* ::ROCPROFILER_CALLBACK_TRACING_HSA_CORE_API or the buffer record kind is
* ::ROCPROFILER_BUFFER_TRACING_HSA_CORE_API, the data/record for `hsa_init` will have an operation
* value of ::ROCPROFILER_HSA_CORE_API_ID_hsa_init.
* @param [in] internal_corr_id_value Current internal correlation ID value for the request
* @param [out] external_corr_id_value Set this value to the desired external correlation ID value
* @param [in] data The `callback_args` value passed to
* ::rocprofiler_configure_external_correlation_id_request_service.
* @returns int
* @retval 0 Used to indicate the tool had zero issues setting the external correlation ID field
* @retval 1 (or any other non-zero number) Used to indicate the callback did not set an external
* correlation ID value and the thread-local value for the most recently pushed external correlation
* ID should be used instead
*/
typedef int (*rocprofiler_external_correlation_id_request_cb_t)(
rocprofiler_thread_id_t thread_id,
rocprofiler_context_id_t context_id,
rocprofiler_external_correlation_id_request_kind_t kind,
uint32_t operation,
uint64_t internal_corr_id_value,
rocprofiler_user_data_t* external_corr_id_value,
void* data);
/**
* @brief Configure External Correlation ID Request Service.
*
* @param [in] context_id Context to associate the service with
* @param [in] kinds Array of ::rocprofiler_external_correlation_id_request_kind_t values. If
* this parameter is null, all tracing operations will invoke the callback to request an external
* correlation ID.
* @param [in] kinds_count If the kinds array is non-null, set this to the size of the
* array.
* @param [in] callback The function to invoke for an external correlation ID request
* @param [in] callback_args Data provided to every invocation of the callback function
* @return ::rocprofiler_status_t
* @retval ::ROCPROFILER_STATUS_ERROR_CONFIGURATION_LOCKED Invoked outside of the initialization
* function in @ref rocprofiler_tool_configure_result_t provided to rocprofiler via @ref
* rocprofiler_configure function
* @retval ::ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_FOUND The provided context is not valid/registered
* @retval ::ROCPROFILER_STATUS_ERROR_SERVICE_ALREADY_CONFIGURED if the same @ref
* rocprofiler_callback_tracing_kind_t value is provided more than once (per context) -- in
* other words, we do not support overriding or combining the kinds in separate function calls.
*/
rocprofiler_status_t
rocprofiler_configure_external_correlation_id_request_service(
rocprofiler_context_id_t context_id,
rocprofiler_external_correlation_id_request_kind_t* kinds,
size_t kinds_count,
rocprofiler_external_correlation_id_request_cb_t callback,
void* callback_args) ROCPROFILER_API ROCPROFILER_NONNULL(4);
/**
* @brief Push default value for `external` field in @ref rocprofiler_correlation_id_t onto stack.
*
@@ -52,10 +145,11 @@ ROCPROFILER_EXTERN_C_INIT
* @retval ::ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_FOUND Context does not exist
* @retval ::ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT Thread id is not valid
*/
rocprofiler_status_t ROCPROFILER_API
rocprofiler_status_t
rocprofiler_push_external_correlation_id(rocprofiler_context_id_t context,
rocprofiler_thread_id_t tid,
rocprofiler_user_data_t external_correlation_id);
rocprofiler_user_data_t external_correlation_id)
ROCPROFILER_API;
/**
* @brief Pop default value for `external` field in @ref rocprofiler_correlation_id_t off of stack
@@ -67,10 +161,11 @@ rocprofiler_push_external_correlation_id(rocprofiler_context_id_t context,
* @retval ::ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_FOUND Context does not exist
* @retval ::ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT Thread id is not valid
*/
rocprofiler_status_t ROCPROFILER_API
rocprofiler_status_t
rocprofiler_pop_external_correlation_id(rocprofiler_context_id_t context,
rocprofiler_thread_id_t tid,
rocprofiler_user_data_t* external_correlation_id);
rocprofiler_user_data_t* external_correlation_id)
ROCPROFILER_API;
/** @} */
+52
View File
@@ -202,6 +202,52 @@ typedef enum // NOLINT(performance-enum-size)
ROCPROFILER_MEMORY_COPY_LAST,
} rocprofiler_memory_copy_operation_t;
/**
* @brief ROCProfiler Kernel Dispatch Tracing Operation Types.
*/
typedef enum // NOLINT(performance-enum-size)
{
ROCPROFILER_KERNEL_DISPATCH_NONE = 0, ///< Unknown kernel dispatch operation
ROCPROFILER_KERNEL_DISPATCH_ENQUEUE = 1,
ROCPROFILER_KERNEL_DISPATCH_COMPLETE,
ROCPROFILER_KERNEL_DISPATCH_LAST,
/// @var ROCPROFILER_KERNEL_DISPATCH_ENQUEUE
/// @brief Invoke callback prior to a kernel being enqueued and after the kernel has been
/// enqueued. When the phase is ::ROCPROFILER_CALLBACK_PHASE_ENTER, this is an opportunity to
/// push an external correlation id and/or modify the active contexts before a kernel is
/// launched. Any active contexts containing services related to a kernel dispatch (kernel
/// tracing, counter collection, etc.) will be captured after this callback and attached to the
/// kernel. These captured contexts will be considered "active" when the kernel completes even
/// if the context was stopped before the kernel completes -- this contract is designed to
/// ensure that tools do not have to delay stopping a context because of an async operation in
/// order to get the data they requested when the async operation was started. When the phase is
/// ::ROCPROFILER_CALLBACK_PHASE_EXIT, the active contexts for the kernel dispatch have been
/// captured and it is safe to disable those contexts without affecting the delivery of the
/// requested data when the kernel completes. It is important to note that, even if the context
/// associated with the kernel dispatch callback tracing service is disabled in between the
/// enter and exit phase, the exit phase callback is still delievered but that context will not
/// be captured when the kernel is enqueued and therefore will not provide a
/// ::ROCPROFILER_KERNEL_DISPATCH_COMPLETE callback. Furthermore, it should be
/// noted that if a tool encodes information into the `::rocprofiler_user_data_t` output
/// parameter in ::rocprofiler_callback_tracing_cb_t, that same value will be delivered in the
/// exit phase and in the ::ROCPROFILER_KERNEL_DISPATCH_COMPLETE callback. In
/// other words, any modifications to that user data value in the exit phase will not be
/// reflected in the ::ROCPROFILER_KERNEL_DISPATCH_COMPLETE callback because a
/// copy of that user data struct is attached to the kernel, not a reference to the user data
/// struct.
///
/// @var ROCPROFILER_KERNEL_DISPATCH_COMPLETE
/// @brief Invoke callback after a kernel has completed and the HSA runtime has processed the
/// signal indicating that the kernel has completed. The latter half of this statement is
/// important. There is no guarantee that these callbacks are invoked in any order related to
/// when the kernels were dispatched, i.e. even if kernel A is launched and fully executed
/// before kernel B is launched, it is entirely possible that the HSA runtime ends up processing
/// the signal associated with kernel B before processing the signal associated with kernel A --
/// resulting in rocprofiler-sdk invoking this operation callback for kernel B before invoking
/// the callback for kernel A.
} rocprofiler_kernel_dispatch_operation_t;
/**
* @brief PC Sampling Method.
*/
@@ -335,6 +381,12 @@ typedef uint32_t rocprofiler_tracing_operation_t;
*/
typedef uint64_t rocprofiler_kernel_id_t;
// /**
// * @brief Sequence identifier type
// *
// */
typedef uint64_t rocprofiler_dispatch_id_t;
// forward declaration of struct
typedef struct rocprofiler_pc_sampling_configuration_s rocprofiler_pc_sampling_configuration_t;
typedef struct rocprofiler_pc_sampling_record_s rocprofiler_pc_sampling_record_t;