rocprofiler-sdk/external_correlation.h Source File

rocprofiler-sdk/external_correlation.h Source File#

ROCprofiler-SDK developer API: rocprofiler-sdk/external_correlation.h Source File
ROCprofiler-SDK developer API 1.0.0
ROCm Profiling API and tools
external_correlation.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 EXTERNAL_CORRELATION External Correlation IDs
32 * @brief User-defined correlation identifiers to supplement rocprofiler generated correlation ids
33 *
34 * @{
35 */
36
37/**
38 * @brief (experimental) ROCProfiler External Correlation ID Operations.
39 *
40 * These kinds correspond to callback and buffered tracing kinds (@see
41 * ::rocprofiler_callback_tracing_kind_t and ::rocprofiler_buffer_tracing_kind_t) which generate
42 * correlation IDs. Typically, rocprofiler-sdk uses the most recent external correlation ID on the
43 * current thread set via ::rocprofiler_push_external_correlation_id; however, this approach can be
44 * problematic if a new external correlation ID should be set before the
45 * ::ROCPROFILER_CALLBACK_PHASE_ENTER callback or if relevant external correlation IDs are desired
46 * when the buffered tracing is used. Thus, rocprofiler-sdk provides a way for tools to get a
47 * callback whenever an external correlation ID is needed. However, this can add significant
48 * overhead for those who only need these callbacks for, say, kernel dispatches while the HSA API is
49 * being traced (i.e. lots of callbacks for HSA API functions). The enumeration below is provided to
50 * ensure that tools can default to using the external correlation IDs set via the push/pop methods
51 * where the external correlation ID value is not important while also getting a request for an
52 * external correlation ID for other tracing kinds.
53 */
54// NOLINTNEXTLINE(performance-enum-size)
55typedef enum ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_external_correlation_id_request_kind_t
56{
58 ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_HSA_CORE_API, ///<
59 ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_HSA_AMD_EXT_API, ///<
60 ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_HSA_IMAGE_EXT_API, ///<
61 ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_HSA_FINALIZE_EXT_API, ///<
62 ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_HIP_RUNTIME_API, ///<
63 ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_HIP_COMPILER_API, ///<
64 ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_MARKER_CORE_API, ///<
65 ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_MARKER_CONTROL_API, ///<
66 ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_MARKER_NAME_API, ///<
67 ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_MEMORY_COPY, ///<
68 ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_KERNEL_DISPATCH, ///<
69 ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_SCRATCH_MEMORY, ///<
70 ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_RCCL_API, ///<
71 ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_OMPT, ///<
72 ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_MEMORY_ALLOCATION, ///<
73 ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_ROCDECODE_API, ///<
74 ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_ROCJPEG_API, ///<
75 ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_MARKER_CORE_RANGE_API, ///<
76 ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_LAST,
78
79/**
80 * @brief (experimental) Callback requesting a value for the external correlation id.
81 *
82 * @param [in] thread_id Id of the thread making the request
83 * @param [in] context_id Id of the context making the request
84 * @param [in] kind Origin of the external correlation id request
85 * @param [in] operation Regardless of whether callback or buffer tracing is being used, the
86 * operation value will be the same, i.e., regardless of whether callback kind is
87 * ::ROCPROFILER_CALLBACK_TRACING_HSA_CORE_API or the buffer record kind is
88 * ::ROCPROFILER_BUFFER_TRACING_HSA_CORE_API, the data/record for `hsa_init` will have an operation
89 * value of ::ROCPROFILER_HSA_CORE_API_ID_hsa_init.
90 * @param [in] internal_corr_id_value Current internal correlation ID value for the request
91 * @param [out] external_corr_id_value Set this value to the desired external correlation ID value
92 * @param [in] data The `callback_args` value passed to
93 * ::rocprofiler_configure_external_correlation_id_request_service.
94 * @returns int
95 * @retval 0 Used to indicate the tool had zero issues setting the external correlation ID field
96 * @retval 1 (or any other non-zero number) Used to indicate the callback did not set an external
97 * correlation ID value and the thread-local value for the most recently pushed external correlation
98 * ID should be used instead
99 */
100ROCPROFILER_SDK_EXPERIMENTAL
102 rocprofiler_thread_id_t thread_id,
103 rocprofiler_context_id_t context_id,
106 uint64_t internal_corr_id_value,
107 rocprofiler_user_data_t* external_corr_id_value,
108 void* data);
109
110/**
111 * @brief (experimental) Configure External Correlation ID Request Service.
112 *
113 * @param [in] context_id Context to associate the service with
114 * @param [in] kinds Array of ::rocprofiler_external_correlation_id_request_kind_t values. If
115 * this parameter is null, all tracing operations will invoke the callback to request an external
116 * correlation ID.
117 * @param [in] kinds_count If the kinds array is non-null, set this to the size of the
118 * array.
119 * @param [in] callback The function to invoke for an external correlation ID request
120 * @param [in] callback_args Data provided to every invocation of the callback function
121 * @return ::rocprofiler_status_t
122 * @retval ::ROCPROFILER_STATUS_ERROR_CONFIGURATION_LOCKED Invoked outside of the initialization
123 * function in ::rocprofiler_tool_configure_result_t provided to rocprofiler via
124 * ::rocprofiler_configure function
125 * @retval ::ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_FOUND The provided context is not valid/registered
126 * @retval ::ROCPROFILER_STATUS_ERROR_SERVICE_ALREADY_CONFIGURED if the same
127 * ::rocprofiler_callback_tracing_kind_t value is provided more than once (per context) -- in other
128 * words, we do not support overriding or combining the kinds in separate function calls.
129 */
130ROCPROFILER_SDK_EXPERIMENTAL
133 rocprofiler_context_id_t context_id,
135 size_t kinds_count,
137 void* callback_args) ROCPROFILER_API ROCPROFILER_NONNULL(4);
138
139/**
140 * @brief Query the name of the external correlation request kind. The name retrieved from this
141 * function is a string literal that is encoded in the read-only section of the binary (i.e. it is
142 * always "allocated" and never "deallocated").
143 *
144 * @param [in] kind External correlation id request domain
145 * @param [out] name If non-null and the name is a constant string that does not require dynamic
146 * allocation, this paramter will be set to the address of the string literal, otherwise it will
147 * be set to nullptr
148 * @param [out] name_len If non-null, this will be assigned the length of the name (regardless of
149 * the name is a constant string or requires dynamic allocation)
150 * @return ::rocprofiler_status_t
151 * @retval ::ROCPROFILER_STATUS_ERROR_KIND_NOT_FOUND Returned if the domain id is not valid
152 * @retval ::ROCPROFILER_STATUS_SUCCESS Returned if a valid domain, regardless if there is a
153 * constant string or not.
154 */
155ROCPROFILER_SDK_EXPERIMENTAL
159 const char** name,
160 uint64_t* name_len) ROCPROFILER_API;
161
162/**
163 * @brief Push default value for `external` field in ::rocprofiler_correlation_id_t onto stack.
164 *
165 * External correlation ids are thread-local values. However, if rocprofiler internally requests an
166 * external correlation id on a non-main thread and an external correlation id has not been pushed
167 * for this thread, the external correlation ID will default to the latest external correlation id
168 * on the main thread -- this allows tools to push an external correlation id once on the main
169 * thread for, say, the MPI rank or process-wide UUID and this value will be used by all subsequent
170 * child threads.
171 *
172 * @param [in] context Associated context
173 * @param [in] tid thread identifier. @see rocprofiler_get_thread_id
174 * @param [in] external_correlation_id User data to place in external field in
175 * ::rocprofiler_correlation_id_t
176 * @return ::rocprofiler_status_t
177 * @retval ::ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_FOUND Context does not exist
178 * @retval ::ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT Thread id is not valid
179 */
183 rocprofiler_user_data_t external_correlation_id)
184 ROCPROFILER_API;
185
186/**
187 * @brief Pop default value for `external` field in ::rocprofiler_correlation_id_t off of stack.
188 *
189 * @param [in] context Associated context
190 * @param [in] tid thread identifier. @see rocprofiler_get_thread_id
191 * @param [out] external_correlation_id Correlation id data popped off the stack
192 * @return ::rocprofiler_status_t
193 * @retval ::ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_FOUND Context does not exist
194 * @retval ::ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT Thread id is not valid
195 */
199 rocprofiler_user_data_t* external_correlation_id)
200 ROCPROFILER_API;
201
202/** @} */
203
204ROCPROFILER_EXTERN_C_FINI
int32_t rocprofiler_tracing_operation_t
Tracing Operation ID. Depending on the kind, operations can be determined. If the value is equal to z...
Definition fwd.h:516
rocprofiler_status_t
Status codes.
Definition fwd.h:49
uint64_t rocprofiler_thread_id_t
Thread ID. Value will be equivalent to syscall(__NR_gettid)
Definition fwd.h:507
Context ID.
Definition fwd.h:600
User-assignable data type.
Definition fwd.h:555
rocprofiler_status_t rocprofiler_configure_external_correlation_id_request_service(rocprofiler_context_id_t context_id, const rocprofiler_external_correlation_id_request_kind_t *kinds, unsigned long kinds_count, rocprofiler_external_correlation_id_request_cb_t callback, void *callback_args)
(experimental) Configure External Correlation ID Request Service.
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)
Push default value for external field in rocprofiler_correlation_id_t onto stack.
rocprofiler_status_t rocprofiler_query_external_correlation_id_request_kind_name(rocprofiler_external_correlation_id_request_kind_t kind, const char **name, uint64_t *name_len)
Query the name of the external correlation request kind. The name retrieved from this function is a s...
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, rocprofiler_tracing_operation_t operation, uint64_t internal_corr_id_value, rocprofiler_user_data_t *external_corr_id_value, void *data)
(experimental) Callback requesting a value for the external correlation id.
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)
Pop default value for external field in rocprofiler_correlation_id_t off of stack.
rocprofiler_external_correlation_id_request_kind_t
(experimental) ROCProfiler External Correlation ID Operations.
@ ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_NONE
Unknown kind.