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