rocprofiler-sdk/registration.h Source File

rocprofiler-sdk/registration.h Source File#

ROCprofiler-SDK developer API: rocprofiler-sdk/registration.h Source File
ROCprofiler-SDK developer API 1.0.0
ROCm Profiling API and tools
registration.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/defines.h>
26#include <rocprofiler-sdk/fwd.h>
27
28ROCPROFILER_EXTERN_C_INIT
29
30/**
31 * @defgroup REGISTRATION_GROUP Tool registration
32 *
33 * @brief Data types and functions for tool registration with rocprofiler
34 * @{
35 */
36
37/**
38 * @brief (experimental) A client refers to an individual or entity engaged in the configuration of
39 * ROCprofiler services. e.g: any third party tool like PAPI or any internal tool (Omnitrace). A
40 * pointer to this data structure is provided to the client tool initialization function. The name
41 * member can be set by the client to assist with debugging (e.g. rocprofiler cannot start your
42 * context because there is a conflicting context started by `<name>` -- at least that is the plan).
43 * The handle member is a unique identifer assigned by rocprofiler for the client and the client can
44 * store it and pass it to the ::rocprofiler_client_finalize_t function to force finalization
45 * (i.e. deactivate all of it's contexts) for the client.
46 */
47typedef struct ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_client_id_t
48{
49 size_t size; ///< size of this struct
50 const char* name; ///< clients should set this value for debugging
51 const uint32_t handle; ///< internal handle
53
54/**
55 * @brief Prototype for the function pointer provided to tool in ::rocprofiler_tool_initialize_t.
56 * This function can be used to explicitly invoke the client tools ::rocprofiler_tool_finalize_t
57 * finalization function prior to the `atexit` handler which calls it.
58 *
59 * If this function pointer is invoked explicitly, rocprofiler will disable calling the
60 * ::rocprofiler_tool_finalize_t functioin pointer during it's `atexit` handler.
61 */
63
64/**
65 * @brief Prototype for the initialize function where a tool creates contexts for the set of
66 * rocprofiler services used by the tool.
67 * @param [in] finalize_func Function pointer to explicitly invoke the finalize function for the
68 * client
69 * @param [in] tool_data `tool_data` field returned from ::rocprofiler_configure in
70 * ::rocprofiler_tool_configure_result_t.
71 */
73 void* tool_data);
74
75/**
76 * @brief Prototype for the finalize function where a tool does any cleanup or output operations
77 * once it has finished using rocprofiler services.
78 * @param [in] tool_data `tool_data` field returned from ::rocprofiler_configure in
79 * ::rocprofiler_tool_configure_result_t.
80 */
81typedef void (*rocprofiler_tool_finalize_t)(void* tool_data);
82
83/**
84 * @brief Data structure containing a initialization, finalization, and data.
85 *
86 * After rocprofiler has retrieved all instances of ::rocprofiler_tool_configure_result_t from the
87 tools -- via either ::rocprofiler_configure and/or ::rocprofiler_force_configure,
88 * rocprofiler will invoke all non-null `initialize` functions and provide the user a function
89 pointer which will explicitly invoke
90 * the `finalize` function pointer. Both the `initialize` and `finalize` functions will be passed
91 the value of the `tool_data` field.
92 * The `size` field is used for ABI reasons, in the event that rocprofiler changes the
93 ::rocprofiler_tool_configure_result_t struct
94 * and it should be set to `sizeof(rocprofiler_tool_configure_result_t)`
95 */
97{
98 size_t size; ///< size of this struct (in case of future extensions)
101 void* tool_data; ///< data to provide to init and fini callbacks
103
104/**
105 * @brief Query whether rocprofiler has already scanned the binary for all the instances of @ref
106 * rocprofiler_configure (or is currently scanning). If rocprofiler has completed it's scan, clients
107 * can directly register themselves with rocprofiler.
108 *
109 * @param [out] status 0 indicates rocprofiler has not been initialized (i.e. configured), 1
110 * indicates rocprofiler has been initialized, -1 indicates rocprofiler is currently initializing.
111 * @return ::rocprofiler_status_t
112 * @retval ::ROCPROFILER_STATUS_SUCCESS Returned unconditionally
113 */
115rocprofiler_is_initialized(int* status) ROCPROFILER_API ROCPROFILER_NONNULL(1);
116
117/**
118 * @brief Query rocprofiler finalization status.
119 *
120 * @param [out] status 0 indicates rocprofiler has not been finalized, 1 indicates rocprofiler has
121 * been finalized, -1 indicates rocprofiler is currently finalizing.
122 * @return ::rocprofiler_status_t
123 * @retval ::ROCPROFILER_STATUS_SUCCESS Returned unconditionally
124 */
126rocprofiler_is_finalized(int* status) ROCPROFILER_API ROCPROFILER_NONNULL(1);
127
128/**
129 * @brief This is the special function that tools define to enable rocprofiler support. The tool
130 * should return a pointer to
131 * ::rocprofiler_tool_configure_result_t which will contain a function pointer to (1) an
132 * initialization function where all the contexts are created, (2) a finalization function (if
133 * necessary) which will be invoked when rocprofiler shutdown and, (3) a pointer to any data that
134 * the tool wants communicated between the ::rocprofiler_tool_configure_result_t::initialize and
135 * ::rocprofiler_tool_configure_result_t::finalize functions. If the user
136 *
137 * @param [in] version The version of rocprofiler: `(10000 * major) + (100 * minor) + patch`
138 * @param [in] runtime_version String descriptor of the rocprofiler version and other relevant info.
139 * @param [in] priority How many client tools were initialized before this client tool
140 * @param [in, out] client_id tool identifier value.
141 * @return rocprofiler_tool_configure_result_t*
142 *
143 * @code{.cpp}
144 * #include <rocprofiler-sdk/registration.h>
145 *
146 * static rocprofiler_client_id_t my_client_id;
147 * static rocprofiler_client_finalize_t my_fini_func;
148 * static int my_tool_data = 1234;
149 *
150 * static int my_init_func(rocprofiler_client_finalize_t fini_func,
151 * void* tool_data)
152 * {
153 * my_fini_func = fini_func;
154 *
155 * assert(*static_cast<int*>(tool_data) == 1234 && "tool_data is wrong");
156 *
157 * rocprofiler_context_id_t ctx{0};
158 * rocprofiler_create_context(&ctx);
159 *
160 * if(int valid_ctx = 0;
161 * rocprofiler_context_is_valid(ctx, &valid_ctx) != ROCPROFILER_STATUS_SUCCESS ||
162 * valid_ctx != 0)
163 * {
164 * // notify rocprofiler that initialization failed
165 * // and all the contexts, buffers, etc. created
166 * // should be ignored
167 * return -1;
168 * }
169 *
170 * if(rocprofiler_start_context(ctx) != ROCPROFILER_STATUS_SUCCESS)
171 * {
172 * // notify rocprofiler that initialization failed
173 * // and all the contexts, buffers, etc. created
174 * // should be ignored
175 * return -1;
176 * }
177 *
178 * // no errors
179 * return 0;
180 * }
181 *
182 * static int my_fini_func(void* tool_data)
183 * {
184 * assert(*static_cast<int*>(tool_data) == 1234 && "tool_data is wrong");
185 * }
186 *
187 * rocprofiler_tool_configure_result_t*
188 * rocprofiler_configure(uint32_t version,
189 * const char* runtime_version,
190 * uint32_t priority,
191 * rocprofiler_client_id_t* client_id)
192 * {
193 * // only activate if main tool
194 * if(priority > 0) return nullptr;
195 *
196 * // set the client name
197 * client_id->name = "ExampleTool";
198 *
199 * // make a copy of client info
200 * my_client_id = *client_id;
201 *
202 * // compute major/minor/patch version info
203 * uint32_t major = version / 10000;
204 * uint32_t minor = (version % 10000) / 100;
205 * uint32_t patch = version % 100;
206 *
207 * // print info
208 * printf("Configuring %s with rocprofiler-sdk (v%u.%u.%u) [%s]\n",
209 * client_id->name, major, minor, patch, runtime_version);
210 *
211 * // create configure data
212 * static auto cfg = rocprofiler_tool_configure_result_t{ &my_init_func,
213 * &my_fini_func,
214 * &my_tool_data };
215 *
216 * // return pointer to configure data
217 * return &cfg;
218 * }
219 * @endcode
220 */
222rocprofiler_configure(uint32_t version,
223 const char* runtime_version,
224 uint32_t priority,
225 rocprofiler_client_id_t* client_id) ROCPROFILER_PUBLIC_API;
226
227// NOTE: we use ROCPROFILER_PUBLIC_API above instead of ROCPROFILER_API because we always
228// want the symbol to be visible when the user includes the header for the prototype
229
230/**
231 * @brief Function pointer typedef for ::rocprofiler_configure function
232 * @param [in] version The version of rocprofiler: `(10000 * major) + (100 * minor) + patch`
233 * @param [in] runtime_version String descriptor of the rocprofiler version and other relevant info.
234 * @param [in] priority How many client tools were initialized before this client tool
235 * @param [in, out] client_id tool identifier value.
236 */
237typedef rocprofiler_tool_configure_result_t* (*rocprofiler_configure_func_t)(
238 uint32_t version,
239 const char* runtime_version,
240 uint32_t priority,
241 rocprofiler_client_id_t* client_id);
242
243/**
244 * @brief Function for explicitly registering a configuration with rocprofiler. This can be invoked
245 * before any ROCm runtimes (lazily) initialize and context(s) can be started before the runtimes
246 * initialize.
247 * @param [in] configure_func Address of ::rocprofiler_configure function. A null pointer is
248 * acceptable if the address is not known
249 * @return ::rocprofiler_status_t
250 * @retval ::ROCPROFILER_STATUS_SUCCESS Registration was successfully triggered.
251 * @retval ::ROCPROFILER_STATUS_ERROR_CONFIGURATION_LOCKED Returned if rocprofiler has already been
252 * configured, or is currently being configured
253 */
256
257/** @} */
258
259ROCPROFILER_EXTERN_C_FINI
rocprofiler_status_t
Status codes.
Definition fwd.h:49
unsigned long size
size of this struct
rocprofiler_tool_finalize_t finalize
cleanup
rocprofiler_tool_initialize_t initialize
context creation
const char * name
clients should set this value for debugging
unsigned long size
size of this struct (in case of future extensions)
const uint32_t handle
internal handle
void * tool_data
data to provide to init and fini callbacks
void(* rocprofiler_tool_finalize_t)(void *tool_data)
Prototype for the finalize function where a tool does any cleanup or output operations once it has fi...
void(* rocprofiler_client_finalize_t)(rocprofiler_client_id_t)
Prototype for the function pointer provided to tool in rocprofiler_tool_initialize_t....
int(* rocprofiler_tool_initialize_t)(rocprofiler_client_finalize_t finalize_func, void *tool_data)
Prototype for the initialize function where a tool creates contexts for the set of rocprofiler servic...
rocprofiler_tool_configure_result_t *(* rocprofiler_configure_func_t)(uint32_t version, const char *runtime_version, uint32_t priority, rocprofiler_client_id_t *client_id)
Function pointer typedef for rocprofiler_configure function.
rocprofiler_tool_configure_result_t * rocprofiler_configure(uint32_t version, const char *runtime_version, uint32_t priority, rocprofiler_client_id_t *client_id)
This is the special function that tools define to enable rocprofiler support. The tool should return ...
rocprofiler_status_t rocprofiler_is_initialized(int *status)
Query whether rocprofiler has already scanned the binary for all the instances of rocprofiler_configu...
rocprofiler_status_t rocprofiler_force_configure(rocprofiler_configure_func_t configure_func)
Function for explicitly registering a configuration with rocprofiler. This can be invoked before any ...
rocprofiler_status_t rocprofiler_is_finalized(int *status)
Query rocprofiler finalization status.
(experimental) A client refers to an individual or entity engaged in the configuration of ROCprofiler...
Data structure containing a initialization, finalization, and data.