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