rocprofiler-sdk/counters.h Source File

rocprofiler-sdk/counters.h Source File#

ROCprofiler-SDK developer API: rocprofiler-sdk/counters.h Source File
ROCprofiler-SDK developer API 1.0.0
ROCm Profiling API and tools
counters.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/defines.h>
27#include <rocprofiler-sdk/fwd.h>
28
29#include <rocprofiler-sdk/deprecated/counters.h>
30
31ROCPROFILER_EXTERN_C_INIT
32
33/**
34 * @defgroup COUNTERS Hardware counters Information
35 * @brief Query functions related to hardware counters
36 * @{
37 */
38
39/**
40 * @brief (experimental) Counter info struct version 0
41 */
42typedef struct ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_counter_info_v0_t
43{
44 rocprofiler_counter_id_t id; ///< Id of this counter
45 const char* name; ///< Name of the counter
46 const char* description; ///< Description of the counter
47 const char* block; ///< Block of the counter (non-derived only)
48 const char* expression; ///< Counter expression (derived counters only)
49 uint8_t is_constant : 1; ///< If this counter is HW constant
50 uint8_t is_derived : 1; ///< If this counter is a derived counter
52
53/**
54 * @brief (experimental) Represents metadata about a single dimension of a counter instance.
55 *
56 * This structure provides the name of the dimension (e.g., "XCC", "SE", etc.)
57 * and the index indicating the position of a specific counter instance within that dimension.
58 */
59typedef struct ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_counter_dimension_info_t
60{
61 uint64_t size; ///< Size of this structure. Used for versioning and validation.
62 const char* dimension_name;
63 size_t index;
64
65 /**
66 * @var dimension_name
67 * @brief Name of the dimension this instance belongs to.
68
69 * @var index
70 * @brief Position (zero-based) of the instance within the specified dimension.
71 */
72
74
75/**
76 * @brief (experimental) Describes a specific counter instance and its position across multiple
77 * dimensions.
78 *
79 * This structure provides the unique instance ID, associated counter ID, number of dimensions for
80 * the instance, and a pointer to an array of metadata describing each dimension's name and index.
81 */
82typedef struct ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_counter_record_dimension_instance_info_t
83{
84 uint64_t size; ///< Size of this structure. Used for versioning and validation.
86 uint64_t counter_id;
89
90 /**
91 * @var instance_id
92 * @brief Encoded identifier for the instance, which includes the counter ID and all dimension
93 positions.
94
95 * @var counter_id
96 * @brief Identifier of the counter associated with this instance.
97
98 * @var dimensions_count
99 * @brief Number of dimensions associated with this instance.
100
101 * @var dimensions
102 * @brief Array of pointers to dimension info structures, each representing one dimension
103 * and the position of this instance within that dimension.
104 *
105 * The array has `dimensions_count` elements, and each element is a pointer to a
106 * `rocprofiler_counter_dimension_info_t` structure.
107 */
108
110
111/**
112 * @brief (experimental) Counter info struct version 1. Combines information from
113 * ::rocprofiler_counter_info_v0_t with the dimension information.
114 */
115typedef struct ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_counter_info_v1_t
116{
117 uint64_t size; ///< Size of this structure. Used for versioning and validation.
118 rocprofiler_counter_id_t id; ///< Id of this counter
119 const char* name; ///< Name of the counter
120 const char* description; ///< Description of the counter
121 const char* block; ///< Block of the counter (non-derived only)
122 const char* expression; ///< Counter expression (derived counters only)
123 uint8_t is_constant : 1; ///< If this counter is HW constant
124 uint8_t is_derived : 1; ///< If this counter is a derived counter
125
130
131 /// @var dimensions_count
132 /// @brief Number of dimensions for the counter
133 ///
134 /// @var dimensions
135 /// @brief Dimension information of the counter
136 ///
137 /// @var dimensions_instances_count
138 /// @brief Number of unique instances for this counter, across all dimension combinations.
139 ///
140 /// @var dimensions_instances
141 /// @brief Array of pointers to instance info structs, each describing a unique instance
142 /// and its specific dimension mapping.
144
145/**
146 * @brief (experimental) Query counter id information from record_id.
147 *
148 * @param [in] id record id from rocprofiler_counter_record_t
149 * @param [out] counter_id counter id associated with the record
150 * @return ::rocprofiler_status_t
151 * @retval ROCPROFILER_STATUS_SUCCESS if id decoded
152 */
153ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_status_t
155 rocprofiler_counter_id_t* counter_id) ROCPROFILER_API
156 ROCPROFILER_NONNULL(2);
157
158/**
159 * @brief (experimental) Query dimension position from record_id. If the dimension does not exist
160 * in the counter, the return will be 0.
161 *
162 * @param [in] id record id from ::rocprofiler_counter_record_t
163 * @param [in] dim dimension for which positional info is requested (currently only
164 * 0 is allowed, i.e. flat array without dimension).
165 * @param [out] pos value of the dimension in id
166 * @return ::rocprofiler_status_t
167 * @retval ROCPROFILER_STATUS_SUCCESS if dimension decoded
168 */
169ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_status_t
172 size_t* pos) ROCPROFILER_API ROCPROFILER_NONNULL(3);
173
174/**
175 * @brief (experimental) Query Counter info such as name or description.
176 *
177 * @param [in] counter_id counter to get info for
178 * @param [in] version Version of struct in info, see ::rocprofiler_counter_info_version_id_t for
179 * available types
180 * @param [out] info rocprofiler_counter_info_{version}_t struct to write info to.
181 * @return ::rocprofiler_status_t
182 * @retval ROCPROFILER_STATUS_SUCCESS if counter found
183 * @retval ROCPROFILER_STATUS_ERROR_COUNTER_NOT_FOUND if counter not found
184 * @retval ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_ABI Version is not supported
185 */
186ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_status_t
189 void* info) ROCPROFILER_API ROCPROFILER_NONNULL(3);
190
191/**
192 * @brief (experimental) Callback that gives a list of counters available on an agent. The
193 * counters variable is owned by rocprofiler and should not be free'd.
194 *
195 * @param [in] agent_id Agent ID of the current callback
196 * @param [in] counters An array of counters that are avialable on the agent
197 * ::rocprofiler_iterate_agent_supported_counters was called on.
198 * @param [in] num_counters Number of counters contained in counters
199 * @param [in] user_data User data supplied by
200 * ::rocprofiler_iterate_agent_supported_counters
201 */
202ROCPROFILER_SDK_EXPERIMENTAL typedef rocprofiler_status_t (*rocprofiler_available_counters_cb_t)(
203 rocprofiler_agent_id_t agent_id,
204 rocprofiler_counter_id_t* counters,
205 size_t num_counters,
206 void* user_data);
207
208/**
209 * @brief (experimental) Query Agent Counters Availability.
210 *
211 * @param [in] agent_id GPU agent identifier
212 * @param [in] cb callback to caller to get counters
213 * @param [in] user_data data to pass into the callback
214 * @return ::rocprofiler_status_t
215 * @retval ROCPROFILER_STATUS_SUCCESS if counters found for agent
216 * @retval ROCPROFILER_STATUS_ERROR if no counters found for agent
217 */
218ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_status_t
221 void* user_data) ROCPROFILER_API
222 ROCPROFILER_NONNULL(2);
223
224/**
225 * @brief (experimental) Creates a new counter based on a derived metric provided. The counter will
226 * only be available for counter collection profiles created after the addition of this counter. Due
227 * to the regeneration of internal ASTs and dimension cache, this call may be slow and should
228 * generally be avoided in performance sensitive code blocks (i.e. dispatch callbacks).
229 *
230 * @param [in] name The name of the new counter.
231 * @param [in] name_len The length of the counter name.
232 * @param [in] expr The counter expression, formatted identically to YAML counter definitions.
233 * @param [in] expr_len The length of the expression.
234 * @param [in] agent The rocprofiler_agent_id_t specifying the agent for which to create the
235 * counter.
236 * @param [in] description The description of the new counter (optional).
237 * @param [in] description_len The length of the description.
238 * @param [out] counter_id The rocprofiler_counter_id_t of the created counter.
239 * @return ::rocprofiler_status_t
240 * @retval ROCPROFILER_STATUS_SUCCESS if the counter was successfully created.
241 * @retval ROCPROFILER_STATUS_ERROR_AST_GENERATION_FAILED if the counter could not be created.
242 * @retval ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT if a counter argument is incorrect
243 * @retval ROCPROFILER_STATUS_ERROR_AGENT_NOT_FOUND if the agent is not found
244 */
245ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_status_t
247 size_t name_len,
248 const char* expr,
249 size_t expr_len,
250 const char* description,
251 size_t description_len,
253 rocprofiler_counter_id_t* counter_id) ROCPROFILER_NONNULL(1, 3, 8);
254
255/** @} */
256
257ROCPROFILER_EXTERN_C_FINI
uint64_t rocprofiler_counter_dimension_id_t
A dimension for counter instances. Some example dimensions include XCC, SM (Shader),...
Definition fwd.h:542
uint64_t rocprofiler_counter_instance_id_t
Unique record id encoding both the counter and dimensional values (positions) for the record.
Definition fwd.h:534
rocprofiler_status_t
Status codes.
Definition fwd.h:49
rocprofiler_counter_info_version_id_t
Enumeration for specifying the counter info struct version you want.
Definition fwd.h:445
Agent Identifier.
Definition fwd.h:677
Counter ID.
Definition fwd.h:685
(experimental) Details for the dimension, including its size, for a counter record.
Definition fwd.h:818
const char * name
Name of the counter.
Definition counters.h:45
const char * block
Block of the counter (non-derived only)
Definition counters.h:47
const rocprofiler_counter_dimension_info_t ** dimensions
Array of pointers to dimension info structures, each representing one dimension and the position of t...
Definition counters.h:88
const char * block
Block of the counter (non-derived only)
Definition counters.h:121
uint64_t size
Size of this structure. Used for versioning and validation.
Definition counters.h:84
const char * dimension_name
Name of the dimension this instance belongs to.
Definition counters.h:62
uint64_t size
Size of this structure. Used for versioning and validation.
Definition counters.h:61
const char * expression
Counter expression (derived counters only)
Definition counters.h:122
const char * description
Description of the counter.
Definition counters.h:120
rocprofiler_counter_id_t id
Id of this counter.
Definition counters.h:44
rocprofiler_counter_id_t id
Id of this counter.
Definition counters.h:118
const char * description
Description of the counter.
Definition counters.h:46
uint8_t is_constant
If this counter is HW constant.
Definition counters.h:123
uint8_t is_derived
If this counter is a derived counter.
Definition counters.h:124
uint8_t is_constant
If this counter is HW constant.
Definition counters.h:49
uint64_t counter_id
Identifier of the counter associated with this instance.
Definition counters.h:86
uint64_t dimensions_count
Number of dimensions associated with this instance.
Definition counters.h:87
const char * expression
Counter expression (derived counters only)
Definition counters.h:48
uint64_t dimensions_instances_count
Number of unique instances for this counter, across all dimension combinations.
Definition counters.h:128
const char * name
Name of the counter.
Definition counters.h:119
rocprofiler_counter_instance_id_t instance_id
Encoded identifier for the instance, which includes the counter ID and all dimension positions.
Definition counters.h:85
uint64_t dimensions_count
Number of dimensions for the counter.
Definition counters.h:126
uint8_t is_derived
If this counter is a derived counter.
Definition counters.h:50
unsigned long index
Position (zero-based) of the instance within the specified dimension.
Definition counters.h:63
const rocprofiler_counter_record_dimension_instance_info_t ** dimensions_instances
Array of pointers to instance info structs, each describing a unique instance and its specific dimens...
Definition counters.h:129
uint64_t size
Size of this structure. Used for versioning and validation.
Definition counters.h:117
const rocprofiler_counter_record_dimension_info_t ** dimensions
Dimension information of the counter.
Definition counters.h:127
rocprofiler_status_t rocprofiler_create_counter(const char *name, unsigned long name_len, const char *expr, unsigned long expr_len, const char *description, unsigned long description_len, rocprofiler_agent_id_t agent, rocprofiler_counter_id_t *counter_id)
(experimental) Creates a new counter based on a derived metric provided. The counter will only be ava...
rocprofiler_status_t rocprofiler_iterate_agent_supported_counters(rocprofiler_agent_id_t agent_id, rocprofiler_available_counters_cb_t cb, void *user_data)
(experimental) Query Agent Counters Availability.
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:202
rocprofiler_status_t rocprofiler_query_record_counter_id(rocprofiler_counter_instance_id_t id, rocprofiler_counter_id_t *counter_id)
(experimental) Query counter id information from record_id.
rocprofiler_status_t rocprofiler_query_record_dimension_position(rocprofiler_counter_instance_id_t id, rocprofiler_counter_dimension_id_t dim, unsigned long *pos)
(experimental) Query dimension position from record_id. If the dimension does not exist in the counte...
rocprofiler_status_t rocprofiler_query_counter_info(rocprofiler_counter_id_t counter_id, rocprofiler_counter_info_version_id_t version, void *info)
(experimental) Query Counter info such as name or description.
(experimental) Represents metadata about a single dimension of a counter instance.
Definition counters.h:60
(experimental) Counter info struct version 0
Definition counters.h:43
(experimental) Counter info struct version 1. Combines information from rocprofiler_counter_info_v0_t...
Definition counters.h:116
(experimental) Describes a specific counter instance and its position across multiple dimensions.
Definition counters.h:83