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 0.4.0
ROCm Profiling API and tools
external_correlation.h
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2023 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
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 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 */
71
72/**
73 * @brief Callback requesting a value for the external correlation id.
74 *
75 * @param [in] thread_id Id of the thread making the request
76 * @param [in] context_id Id of the context making the request
77 * @param [in] kind Origin of the external correlation id request
78 * @param [in] operation Regardless of whether callback or buffer tracing is being used, the
79 * operation value will be the same, i.e., regardless of whether callback kind is
80 * ::ROCPROFILER_CALLBACK_TRACING_HSA_CORE_API or the buffer record kind is
81 * ::ROCPROFILER_BUFFER_TRACING_HSA_CORE_API, the data/record for `hsa_init` will have an operation
82 * value of ::ROCPROFILER_HSA_CORE_API_ID_hsa_init.
83 * @param [in] internal_corr_id_value Current internal correlation ID value for the request
84 * @param [out] external_corr_id_value Set this value to the desired external correlation ID value
85 * @param [in] data The `callback_args` value passed to
86 * ::rocprofiler_configure_external_correlation_id_request_service.
87 * @returns int
88 * @retval 0 Used to indicate the tool had zero issues setting the external correlation ID field
89 * @retval 1 (or any other non-zero number) Used to indicate the callback did not set an external
90 * correlation ID value and the thread-local value for the most recently pushed external correlation
91 * ID should be used instead
92 */
95 rocprofiler_context_id_t context_id,
97 uint32_t operation,
98 uint64_t internal_corr_id_value,
99 rocprofiler_user_data_t* external_corr_id_value,
100 void* data);
101
102/**
103 * @brief Configure External Correlation ID Request Service.
104 *
105 * @param [in] context_id Context to associate the service with
106 * @param [in] kinds Array of ::rocprofiler_external_correlation_id_request_kind_t values. If
107 * this parameter is null, all tracing operations will invoke the callback to request an external
108 * correlation ID.
109 * @param [in] kinds_count If the kinds array is non-null, set this to the size of the
110 * array.
111 * @param [in] callback The function to invoke for an external correlation ID request
112 * @param [in] callback_args Data provided to every invocation of the callback function
113 * @return ::rocprofiler_status_t
114 * @retval ::ROCPROFILER_STATUS_ERROR_CONFIGURATION_LOCKED Invoked outside of the initialization
115 * function in @ref rocprofiler_tool_configure_result_t provided to rocprofiler via @ref
116 * rocprofiler_configure function
117 * @retval ::ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_FOUND The provided context is not valid/registered
118 * @retval ::ROCPROFILER_STATUS_ERROR_SERVICE_ALREADY_CONFIGURED if the same @ref
119 * rocprofiler_callback_tracing_kind_t value is provided more than once (per context) -- in
120 * other words, we do not support overriding or combining the kinds in separate function calls.
121 */
124 rocprofiler_context_id_t context_id,
126 size_t kinds_count,
128 void* callback_args) ROCPROFILER_API ROCPROFILER_NONNULL(4);
129
130/**
131 * @brief Push default value for `external` field in @ref rocprofiler_correlation_id_t onto stack.
132 *
133 * External correlation ids are thread-local values. However, if rocprofiler internally requests an
134 * external correlation id on a non-main thread and an external correlation id has not been pushed
135 * for this thread, the external correlation ID will default to the latest external correlation id
136 * on the main thread -- this allows tools to push an external correlation id once on the main
137 * thread for, say, the MPI rank or process-wide UUID and this value will be used by all subsequent
138 * child threads.
139 *
140 * @param [in] context Associated context
141 * @param [in] tid thread identifier. @see rocprofiler_get_thread_id
142 * @param [in] external_correlation_id User data to place in external field in @ref
143 * rocprofiler_correlation_id_t
144 * @return ::rocprofiler_status_t
145 * @retval ::ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_FOUND Context does not exist
146 * @retval ::ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT Thread id is not valid
147 */
151 rocprofiler_user_data_t external_correlation_id)
152 ROCPROFILER_API;
153
154/**
155 * @brief Pop default value for `external` field in @ref rocprofiler_correlation_id_t off of stack
156 *
157 * @param [in] context Associated context
158 * @param [in] tid thread identifier. @see rocprofiler_get_thread_id
159 * @param [out] external_correlation_id Correlation id data popped off the stack
160 * @return ::rocprofiler_status_t
161 * @retval ::ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_FOUND Context does not exist
162 * @retval ::ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT Thread id is not valid
163 */
167 rocprofiler_user_data_t* external_correlation_id)
168 ROCPROFILER_API;
169
170/** @} */
171
172ROCPROFILER_EXTERN_C_FINI
rocprofiler_status_t
Status codes.
Definition fwd.h:55
uint64_t rocprofiler_thread_id_t
Thread ID. Value will be equivalent to syscall(__NR_gettid)
Definition fwd.h:439
Context ID.
Definition fwd.h:502
User-assignable data type.
Definition fwd.h:487
rocprofiler_status_t rocprofiler_configure_external_correlation_id_request_service(rocprofiler_context_id_t context_id, rocprofiler_external_correlation_id_request_kind_t *kinds, unsigned long kinds_count, rocprofiler_external_correlation_id_request_cb_t callback, void *callback_args)
Configure External Correlation ID Request Service.
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, uint32_t operation, uint64_t internal_corr_id_value, rocprofiler_user_data_t *external_corr_id_value, void *data)
Callback requesting a value for the external correlation id.
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_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
ROCProfiler External Correlation ID Operations.
@ ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_LAST
@ ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_SCRATCH_MEMORY
@ ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_MARKER_NAME_API
@ ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_HSA_FINALIZE_EXT_API
@ ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_HIP_RUNTIME_API
@ ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_MEMORY_COPY
@ ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_MARKER_CORE_API
@ ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_NONE
Unknown kind.
@ ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_KERNEL_DISPATCH
@ ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_HSA_IMAGE_EXT_API
@ ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_MARKER_CONTROL_API
@ ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_HSA_CORE_API
@ ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_HIP_COMPILER_API
@ ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_HSA_AMD_EXT_API