rocprofiler-sdk/experimental/spm.h Source File

rocprofiler-sdk/experimental/spm.h Source File#

ROCprofiler-SDK developer API: rocprofiler-sdk/experimental/spm.h Source File
ROCprofiler-SDK developer API 1.4.1
ROCm Profiling API and tools
spm.h
1// MIT License
2//
3// Copyright (c) 2026 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/counters.h>
27#include <rocprofiler-sdk/defines.h>
28#include <rocprofiler-sdk/fwd.h>
29
30ROCPROFILER_EXTERN_C_INIT
31
32/**
33 * @brief (experimental) SPM parameter types for configuring sampling behavior.
34 **/
35typedef enum ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_spm_parameter_type_t
36{
37 ROCPROFILER_SPM_PARAMETER_TYPE_NONE = 0,
38 ROCPROFILER_SPM_PARAMETER_TYPE_SAMPLE_INTERVAL_SCLK_CYCLES,
39 ROCPROFILER_SPM_PARAMETER_TYPE_LAST,
40} rocprofiler_spm_parameter_type_t;
41
42/**
43 * @brief (experimental) Describes an available SPM configuration for an agent.
44 *
45 * Returned via ::rocprofiler_spm_query_agent_configurations to describe the
46 * supported SPM parameter types and their valid value ranges for a given agent.
47 **/
48typedef struct ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_spm_available_configuration_t
49{
50 uint64_t size; ///< Size of this struct
51 rocprofiler_spm_parameter_type_t type; ///< The SPM parameter type; used to tag the union below
52 union
53 {
54 struct
55 {
56 uint64_t min_interval; ///< Minimum supported value for this parameter
57 uint64_t max_interval; ///< Maximum supported value for this parameter
58 } interval; ///< Interval configuration for sample interval parameter types
59 };
61
62/**
63 * @brief (experimental) Callback that provides the available SPM configurations for an agent.
64 * The config array is owned by rocprofiler and should not be freed.
65 *
66 * @param [in] config Array of pointers to available SPM configurations
67 * @param [in] num_config Number of configurations in the array
68 * @param [in] user_data User data supplied by ::rocprofiler_spm_query_agent_configurations
69 */
70ROCPROFILER_SDK_EXPERIMENTAL
71typedef rocprofiler_status_t (*rocprofiler_spm_available_configurations_cb_t)(
73 size_t num_config,
74 void* user_data);
75
76/**
77 * @brief (experimental) Query supported agent configurations for SPM.
78 * Supported configurations are returned in a callback.
79 *
80 * @param [in] agent_id agent for which the configurations are queried for
81 * @param [in] cb callback in which configurations are returned
82 * @param [in] user_data user data to be passed to the callback
83 * @return ::rocprofiler_status_t
84 * @retval ROCPROFILER_STATUS_SUCCESS if configurations were successfully queried
85 * @retval ROCPROFILER_STATUS_ERROR if configurations could not be queried
86 * @retval ROCPROFILER_STATUS_ERROR_AGENT_NOT_FOUND if agent not found
87 * @retval ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_ABI incompatible aqlprofile version is used
88 **/
89ROCPROFILER_SDK_EXPERIMENTAL
91rocprofiler_spm_query_agent_configurations(rocprofiler_agent_id_t agent_id,
92 rocprofiler_spm_available_configurations_cb_t cb,
93 void* user_data) ROCPROFILER_API ROCPROFILER_NONNULL(2);
94
95/**
96 * @brief (experimental) SPM configuration parameter used to configure sampling behavior.
97 *
98 * Passed to ::rocprofiler_spm_create_counter_config to specify SPM sampling parameters.
99 * Supported configurations can be queried via ::rocprofiler_spm_query_agent_configurations.
100 * @var size
101 * @brief Size of this struct.
102 *
103 * @var type
104 * @brief The SPM parameter type.
105 *
106 * @var value
107 * @brief The value for this parameter.
108 */
109typedef struct ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_spm_parameters_t
110{
111 uint64_t size;
112 rocprofiler_spm_parameter_type_t type;
113 uint64_t value;
114} rocprofiler_spm_parameters_t;
115
116/**
117 * @brief (experimental) Create SPM Counter Configuration. A config is bound to an agent but can
118 * be used across many contexts. The config has a fixed set of counters
119 * that are collected (and specified by counter_list) and parameters. The available
120 * counters for an agent can be queried using
121 * ::rocprofiler_spm_iterate_agent_supported_counters. An existing config
122 * may be supplied via config_id to use as a base for the new config.
123 * All counters in the existing config will be copied over to the new
124 * config. The existing config will remain unmodified and usable with
125 * the new config id being returned in config_id.
126 *
127 * @param [in] agent_id Agent identifier
128 * @param [in] counters_list List of GPU counters
129 * @param [in] counters_count Size of counters list
130 * @param [in] parameters SPM parameter configuration
131 * @param [in] parameters_count Number of parameters
132 * @param [in,out] config_id Identifier for GPU SPM counters group. If an existing
133 config is supplied, that counters will be copied
134 over to a new config (returned via this id)
135 * @return ::rocprofiler_status_t
136 * @retval ROCPROFILER_STATUS_SUCCESS if config created
137 * @retval ROCPROFILER_STATUS_ERROR_METRIC_NOT_VALID_FOR_AGENT if agent does not support an input
138 counter for sampling
139 * @retval ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_ABI incompatible aqlprofile version is used
140 * @retval ROCPROFILER_STATUS_ERROR_NOT_IMPLEMENTED if the ROCPROFILER_SPM_BETA_ENABLED is not set
141 * @retval ROCPROFILER_STATUS_ERROR_EXCEEDS_HW_LIMIT if input counters exceed the hardware limit
142 * @retval ROCPROFILER_STATUS_ERROR_AGENT_NOT_FOUND if agent not found
143 * @retval ROCPROFILER_STATUS_ERROR_COUNTER_NOT_FOUND if an input counter is not found in metrics
144 file
145 */
146ROCPROFILER_SDK_EXPERIMENTAL
148rocprofiler_spm_create_counter_config(rocprofiler_agent_id_t agent_id,
149 rocprofiler_counter_id_t* counters_list,
150 size_t counters_count,
151 rocprofiler_spm_parameters_t** parameters,
152 size_t parameters_count,
153 rocprofiler_counter_config_id_t* config_id) ROCPROFILER_API
154 ROCPROFILER_NONNULL(2, 4, 6);
155
156/**
157 * @brief (experimental) Destroy SPM Profile Configuration.
158 *
159 * @param [in] config_id
160 * @return ::rocprofiler_status_t
161 * @retval ROCPROFILER_STATUS_SUCCESS if config destroyed
162 * @retval ROCPROFILER_STATUS_ERROR_PROFILE_NOT_FOUND if the profile is not found
163 * @retval ROCPROFILER_STATUS_ERROR if config could not be destroyed
164 */
165ROCPROFILER_SDK_EXPERIMENTAL
167rocprofiler_spm_destroy_counter_config(rocprofiler_counter_config_id_t config_id) ROCPROFILER_API;
168
169/**
170 * @brief (experimental) SPM record flags.
171 *
172 **/
173typedef enum ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_spm_record_flag_t
174{
175 ROCPROFILER_SPM_RECORD_FLAG_NONE = 0, ///< flag value none
176 ROCPROFILER_SPM_RECORD_FLAG_DATA = 1 << 0, ///< records with data
177 ROCPROFILER_SPM_RECORD_FLAG_DATA_LOSS = 1 << 1, ///< records with data loss
178 ROCPROFILER_SPM_RECORD_FLAG_DISPATCH_END = 1 << 2, ///< dispatch complete, no records
179 ROCPROFILER_SPM_RECORD_FLAG_LAST = 1 << 3,
180} rocprofiler_spm_record_flag_t;
181
182/**
183 * @brief (experimental) Kernel dispatch data for profile counting callbacks.
184 *
185 */
186typedef struct ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_spm_dispatch_counting_service_data_t
187{
188 uint64_t size; ///< Size of this struct
189 rocprofiler_async_correlation_id_t correlation_id; ///< Correlation ID for this dispatch
192
193typedef struct ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_spm_counter_record_t
194{
195 uint64_t size; ///< Size of this structure. Used for versioning and validation.
196 rocprofiler_dispatch_id_t
197 dispatch_id; ///< dispatch id used to determine the dispatch this record belongs to.
198 rocprofiler_counter_instance_id_t id; ///< Counter instance id
199 rocprofiler_agent_id_t agent_id; ///< Agent on which the record is collected
200 rocprofiler_timestamp_t timestamp; ///< timestamp of the sample
201 double value; ///< SPM sample for the counter with counter instance id: id
202} rocprofiler_spm_counter_record_t;
203
204/**
205 * @brief (experimental) Counting record callback. This is a callback is invoked when the kernel
206 * execution is complete and contains the counter profile data requested in
207 * ::rocprofiler_spm_dispatch_counting_service_cb_t. Only used with
208 * ::rocprofiler_spm_configure_callback_dispatch_service
209 *
210 * @param [in] dispatch_data kernel dispatch data
211 * @param [in] records array of pointers to the rocprofiler_spm_counter_record_t.
212 Memory of records is managed by the SDK. It is valid only within this callback
213 * @param [in] record_count size of the record array
214 * @param [in] flags rocprofiler_spm_record_flag_t
215 * @param [in] userdata user data supplied by dispatch callback
216 * @param [in] record Callback data supplied via dispatch configure service
217 */
218ROCPROFILER_SDK_EXPERIMENTAL
219typedef void (*rocprofiler_spm_dispatch_counting_record_cb_t)(
221 const rocprofiler_spm_counter_record_t** records,
222 size_t record_count,
223 rocprofiler_spm_record_flag_t flags,
225 void* record_callback_args);
226
227/**
228 * @brief (experimental) Kernel Dispatch Callback. This is a callback that is invoked before the
229 * kernel is enqueued into the HSA queue. What counters to collect for a kernel are set via passing
230 * back a profile config (config) in this callback. These counters will be collected and emplaced in
231 * the buffer with ::rocprofiler_buffer_id_t used when setting up this callback or will be returned
232 * via a callback used when setting up this callback
233 *
234 * @param [in] dispatch_data kernel dispatch data
235 * @param [out] config spm counter config
236 * @param [out] user_data User data unique to this dispatch. Returned in record callback
237 * @param [in] callback_data_args Callback supplied via dispatch configure service
238 */
239ROCPROFILER_SDK_EXPERIMENTAL
240typedef void (*rocprofiler_spm_dispatch_counting_service_cb_t)(
243 rocprofiler_user_data_t* user_data,
244 void* callback_data_args);
245
246/**
247 * @brief (experimental) Query Agent SPM Counters Availability.
248 *
249 * @param [in] agent_id GPU agent identifier
250 * @param [in] cb callback to caller to get counters
251 * @param [in] user_data data to pass into the callback
252 * @return ::rocprofiler_status_t
253 * @retval ROCPROFILER_STATUS_SUCCESS if all counters found for agent
254 * @retval ROCPROFILER_STATUS_ERROR_AGENT_NOT_FOUND invalid agent
255 * @retval ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_ABI incompatible aqlprofile version is used
256 * @retval ROCPROFILER_STATUS_ERROR_AGENT_ARCH_NOT_SUPPORTED agent has no supported SPM counter
257 */
258ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_status_t
259rocprofiler_spm_iterate_agent_supported_counters(rocprofiler_agent_id_t agent_id,
261 void* user_data) ROCPROFILER_API
262 ROCPROFILER_NONNULL(2);
263
264/**
265 * @brief (experimental) Configure callback dispatch profile Counting Service.
266 * Collects the counters in dispatch packets and calls a callback
267 * with the counters collected during that dispatch.
268 *
269 * @param [in] context_id context id
270 * @param [in] dispatch_callback callback to perform when dispatch is enqueued
271 * @param [in] dispatch_callback_args callback data for dispatch callback
272 * @param [in] record_callback Record callback for completed profile data
273 * @param [in] record_callback_args Callback args for record callback
274 * @return ::rocprofiler_status_t
275 * @retval ROCPROFILER_STATUS_SUCCESS if the context can be configured for SPM dispatch service
276 * @retval ROCPROFILER_STATUS_ERROR_NOT_IMPLEMENTED if the ROCPROFILER_SPM_BETA_ENABLED is not set
277 * @retval ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_ABI incompatible aqlprofile version is used
278 * @retval ROCPROFILER_STATUS_ERROR_CONTEXT_INVALID Invalid context
279 * @retval ROCPROFILER_STATUS_ERROR_CONTEXT_CONFLICT conflicting services being enabled in the
280 * context
281 */
282ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_status_t
283rocprofiler_spm_configure_callback_dispatch_service(
284 rocprofiler_context_id_t context_id,
285 rocprofiler_spm_dispatch_counting_service_cb_t dispatch_callback,
286 void* dispatch_callback_args,
287 rocprofiler_spm_dispatch_counting_record_cb_t record_callback,
288 void* record_callback_args) ROCPROFILER_API ROCPROFILER_NONNULL(2, 4);
289
290/**
291 * @brief (experimental) Configure buffered dispatch spm service.
292 * Collects the counters in dispatch packets and stores them
293 * in a buffer with buffer_id. The buffer may contain packets from more than
294 * one dispatch (denoted by dispatch id). Will trigger the
295 * callback based on the parameters setup in buffer_id_t.
296 *
297 * @param [in] context_id context id
298 * @param [in] buffer_id id of the buffer to use for the counting service
299 * @param [in] callback callback to perform when dispatch is enqueued
300 * @param [in] callback_data_args callback data
301 * @return ::rocprofiler_status_t
302 * @retval ROCPROFILER_STATUS_SUCCESS if the context can be configured for SPM buffer dispatch
303 * service
304 * @retval ROCPROFILER_STATUS_ERROR_BUFFER_NOT_FOUND if the buffer is not found
305 * @retval ROCPROFILER_STATUS_ERROR_CONTEXT_INVALID invalid input context
306 * @retval ROCPROFILER_STATUS_ERROR_CONTEXT_CONFLICT conflicting services being enabled in the
307 * context
308 * @retval ROCPROFILER_STATUS_ERROR_NOT_IMPLEMENTED if the ROCPROFILER_SPM_BETA_ENABLED is not set
309 * @retval ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_ABI incompatible aqlprofile version is used
310 */
311ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_status_t
312rocprofiler_spm_configure_buffer_dispatch_service(
313 rocprofiler_context_id_t context_id,
314 rocprofiler_buffer_id_t buffer_id,
315 rocprofiler_spm_dispatch_counting_service_cb_t callback,
316 void* callback_data_args) ROCPROFILER_API ROCPROFILER_NONNULL(3);
317
318ROCPROFILER_EXTERN_C_FINI
uint64_t rocprofiler_counter_instance_id_t
Unique record id encoding both the counter and dimensional values (positions) for the record.
Definition fwd.h:629
rocprofiler_status_t
Status codes.
Definition fwd.h:49
uint64_t rocprofiler_timestamp_t
ROCProfiler Timestamp.
Definition fwd.h:597
Agent Identifier.
Definition fwd.h:790
ROCProfiler Correlation ID record for async activity.
Definition fwd.h:756
Context ID.
Definition fwd.h:695
Profile Configurations.
Definition fwd.h:807
Counter ID.
Definition fwd.h:798
ROCProfiler kernel dispatch information.
Definition fwd.h:906
User-assignable data type.
Definition fwd.h:650
rocprofiler_status_t(* rocprofiler_available_counters_cb_t)(rocprofiler_agent_id_t agent_id, rocprofiler_counter_id_t *counters, unsigned long num_counters, void *user_data)
(experimental) Callback that gives a list of counters available on an agent. The counters variable is...
Definition counters.h:204
(experimental) Describes an available SPM configuration for an agent.
Definition spm.h:49
uint64_t size
Size of this struct.
Definition spm.h:50
rocprofiler_spm_parameter_type_t type
The SPM parameter type; used to tag the union below.
Definition spm.h:51
(experimental) Kernel dispatch data for profile counting callbacks.
Definition spm.h:187
uint64_t size
Size of this struct.
Definition spm.h:188
rocprofiler_kernel_dispatch_info_t dispatch_info
Dispatch info.
Definition spm.h:190
rocprofiler_async_correlation_id_t correlation_id
Correlation ID for this dispatch.
Definition spm.h:189