rocprofiler-sdk/dispatch_counting_service.h Source File

rocprofiler-sdk/dispatch_counting_service.h Source File#

ROCprofiler-SDK developer API: rocprofiler-sdk/dispatch_counting_service.h Source File
ROCprofiler-SDK developer API 1.0.0
ROCm Profiling API and tools
dispatch_counting_service.h
1// MIT License
2//
3// Copyright (c) 2023-2025 Advanced Micro Devices, Inc. All rights reserved.
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22
23#pragma once
24
25#include <rocprofiler-sdk/agent.h>
26#include <rocprofiler-sdk/counter_config.h>
27#include <rocprofiler-sdk/defines.h>
28#include <rocprofiler-sdk/fwd.h>
29#include <rocprofiler-sdk/hsa.h>
30
31ROCPROFILER_EXTERN_C_INIT
32
33/**
34 * @defgroup dispatch_counting_service Dispatch Profile Counting Service
35 * @brief Per-dispatch hardware counter collection service
36 *
37 * @{
38 */
39
40/**
41 * @brief (experimental) Kernel dispatch data for profile counting callbacks.
42 *
43 */
44typedef struct ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_dispatch_counting_service_data_t
45{
46 uint64_t size; ///< Size of this struct
47 rocprofiler_async_correlation_id_t correlation_id; ///< Correlation ID for this dispatch
48 rocprofiler_timestamp_t start_timestamp; ///< start time in nanoseconds
49 rocprofiler_timestamp_t end_timestamp; ///< end time in nanoseconds
52
53/**
54 * @brief (experimental) ROCProfiler Profile Counting Counter Record Header Information
55 *
56 * This is buffer equivalent of ::rocprofiler_dispatch_counting_service_data_t
57 */
58typedef struct ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_dispatch_counting_service_record_t
59{
60 uint64_t size; ///< Size of this struct
61 uint64_t num_records; ///< number of ::rocprofiler_counter_record_t records
62 rocprofiler_async_correlation_id_t correlation_id; ///< Correlation ID for this dispatch
63 rocprofiler_timestamp_t start_timestamp; ///< start time in nanoseconds
64 rocprofiler_timestamp_t end_timestamp; ///< end time in nanoseconds
65 rocprofiler_kernel_dispatch_info_t dispatch_info; ///< Contains the `dispatch_id`
67
68/**
69 * @brief (experimental) Kernel Dispatch Callback. This is a callback that is invoked before the
70 * kernel is enqueued into the HSA queue. What counters to collect for a kernel are set via passing
71 * back a profile config (config) in this callback. These counters will be collected and emplaced in
72 * the buffer with ::rocprofiler_buffer_id_t used when setting up this callback.
73 *
74 * @param [in] dispatch_data @see ::rocprofiler_dispatch_counting_service_data_t
75 * @param [out] config Profile config detailing the counters to collect for this kernel
76 * @param [out] user_data User data unique to this dispatch. Returned in record callback
77 * @param [in] callback_data_args Callback supplied via buffered_dispatch_counting_service
78 */
79ROCPROFILER_SDK_EXPERIMENTAL
83 rocprofiler_user_data_t* user_data,
84 void* callback_data_args);
85
86/**
87 * @brief (experimental) Counting record callback. This is a callback is invoked when the kernel
88 * execution is complete and contains the counter profile data requested in
89 * ::rocprofiler_dispatch_counting_service_cb_t. Only used with
90 * ::rocprofiler_configure_callback_dispatch_counting_service.
91 *
92 * @param [in] dispatch_data @see ::rocprofiler_dispatch_counting_service_data_t
93 * @param [in] record_data Counter record data.
94 * @param [in] record_count Number of counter records.
95 * @param [in] user_data User data instance from dispatch callback
96 * @param [in] callback_data_args Callback supplied via buffered_dispatch_counting_service
97 */
98ROCPROFILER_SDK_EXPERIMENTAL
101 rocprofiler_counter_record_t* record_data,
102 size_t record_count,
103 rocprofiler_user_data_t user_data,
104 void* callback_data_args);
105
106/**
107 * @brief (experimental) Configure buffered dispatch profile Counting Service.
108 * Collects the counters in dispatch packets and stores them
109 * in a buffer with @p buffer_id. The buffer may contain packets from more than
110 * one dispatch (denoted by correlation id). Will trigger the
111 * callback based on the parameters setup in buffer_id_t.
112 *
113 * NOTE: Interface is up for comment as to whether restrictions
114 * on agent should be made here (limiting the CB based on agent)
115 * or if the restriction should be performed by the tool in
116 * ::rocprofiler_dispatch_counting_service_cb_t (i.e.
117 * tool code checking the agent param to see if they want to profile
118 * it).
119 *
120 * Interface is up for comment as to whether restrictions
121 * on agent should be made here (limiting the CB based on agent)
122 * or if the restriction should be performed by the tool in
123 * ::rocprofiler_dispatch_counting_service_cb_t (i.e.
124 * tool code checking the agent param to see if they want to profile
125 * it).
126 *
127 * @param [in] context_id context id
128 * @param [in] buffer_id id of the buffer to use for the counting service
129 * @param [in] callback callback to perform when dispatch is enqueued
130 * @param [in] callback_data_args callback data
131 * @return ::rocprofiler_status_t
132 */
133ROCPROFILER_SDK_EXPERIMENTAL
136 rocprofiler_context_id_t context_id,
137 rocprofiler_buffer_id_t buffer_id,
139 void* callback_data_args) ROCPROFILER_API;
140
141/**
142 * @brief (experimental) Configure buffered dispatch profile Counting Service.
143 * Collects the counters in dispatch packets and calls a callback
144 * with the counters collected during that dispatch.
145 *
146 * @param [in] context_id context id
147 * @param [in] dispatch_callback callback to perform when dispatch is enqueued
148 * @param [in] dispatch_callback_args callback data for dispatch callback
149 * @param [in] record_callback Record callback for completed profile data
150 * @param [in] record_callback_args Callback args for record callback
151 * @return ::rocprofiler_status_t
152 */
153ROCPROFILER_SDK_EXPERIMENTAL
156 rocprofiler_context_id_t context_id,
158 void* dispatch_callback_args,
160 void* record_callback_args) ROCPROFILER_API;
161
162/** @} */
163
164ROCPROFILER_EXTERN_C_FINI
rocprofiler_status_t
Status codes.
Definition fwd.h:49
uint64_t rocprofiler_timestamp_t
ROCProfiler Timestamp.
Definition fwd.h:502
ROCProfiler Correlation ID record for async activity.
Definition fwd.h:643
Context ID.
Definition fwd.h:600
Profile Configurations.
Definition fwd.h:694
(experimental) ROCProfiler Profile Counting Counter Record per instance.
Definition fwd.h:835
ROCProfiler kernel dispatch information.
Definition fwd.h:793
User-assignable data type.
Definition fwd.h:555
rocprofiler_kernel_dispatch_info_t dispatch_info
Contains the dispatch_id
rocprofiler_timestamp_t end_timestamp
end time in nanoseconds
rocprofiler_async_correlation_id_t correlation_id
Correlation ID for this dispatch.
rocprofiler_kernel_dispatch_info_t dispatch_info
Dispatch info.
rocprofiler_async_correlation_id_t correlation_id
Correlation ID for this dispatch.
rocprofiler_timestamp_t start_timestamp
start time in nanoseconds
uint64_t num_records
number of rocprofiler_counter_record_t records
rocprofiler_timestamp_t start_timestamp
start time in nanoseconds
rocprofiler_timestamp_t end_timestamp
end time in nanoseconds
rocprofiler_status_t rocprofiler_configure_callback_dispatch_counting_service(rocprofiler_context_id_t context_id, rocprofiler_dispatch_counting_service_cb_t dispatch_callback, void *dispatch_callback_args, rocprofiler_dispatch_counting_record_cb_t record_callback, void *record_callback_args)
(experimental) Configure buffered dispatch profile Counting Service. Collects the counters in dispatc...
void(* rocprofiler_dispatch_counting_record_cb_t)(rocprofiler_dispatch_counting_service_data_t dispatch_data, rocprofiler_counter_record_t *record_data, unsigned long record_count, rocprofiler_user_data_t user_data, void *callback_data_args)
(experimental) Counting record callback. This is a callback is invoked when the kernel execution is c...
void(* rocprofiler_dispatch_counting_service_cb_t)(rocprofiler_dispatch_counting_service_data_t dispatch_data, rocprofiler_counter_config_id_t *config, rocprofiler_user_data_t *user_data, void *callback_data_args)
(experimental) Kernel Dispatch Callback. This is a callback that is invoked before the kernel is enqu...
rocprofiler_status_t rocprofiler_configure_buffer_dispatch_counting_service(rocprofiler_context_id_t context_id, rocprofiler_buffer_id_t buffer_id, rocprofiler_dispatch_counting_service_cb_t callback, void *callback_data_args)
(experimental) Configure buffered dispatch profile Counting Service. Collects the counters in dispatc...
(experimental) Kernel dispatch data for profile counting callbacks.
(experimental) ROCProfiler Profile Counting Counter Record Header Information