rocprofiler-sdk/experimental/thread-trace/trace_decoder.h Source File

rocprofiler-sdk/experimental/thread-trace/trace_decoder.h Source File#

ROCprofiler-SDK developer API: rocprofiler-sdk/experimental/thread-trace/trace_decoder.h Source File
ROCprofiler-SDK developer API 1.0.0
ROCm Profiling API and tools
trace_decoder.h
1// MIT License
2//
3// Copyright (c) 2024-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/experimental/thread-trace/trace_decoder_types.h>
26#include <rocprofiler-sdk/fwd.h>
27
28ROCPROFILER_EXTERN_C_INIT
29
30/**
31 * @defgroup THREAD_TRACE Thread Trace Service
32 * @brief ROCprof-trace-decoder wrapper. Provides API calls to decode thread trace shader data.
33 * @{
34 */
35
36/**
37 * @brief Handle containing a loaded rocprof-trace-decoder and a decoder state.
38 */
43
44/**
45 * @brief Initializes Trace Decoder library with a library search path
46 * @param[out] handle Handle to created decoder instance.
47 * @param[in] path Path to trace decoder library location (e.g. /opt/rocm/lib).
48 * @return ::rocprofiler_status_t
49 * @retval ::ROCPROFILER_STATUS_ERROR_NOT_AVAILABLE Library not found
50 * @retval ::ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_ABI Library found but version not supported
51 * @retval ::ROCPROFILER_STATUS_SUCCESS Handle created
52 */
55 const char* path) ROCPROFILER_API ROCPROFILER_NONNULL(1, 2);
56
57/**
58 * @brief Deletes handle created by ::rocprofiler_thread_trace_decoder_create
59 * @param[in] handle Handle to destroy
60 */
61void
63 ROCPROFILER_API;
64
65/**
66 * @brief Loads a code object binary to match with Thread Trace.
67 * The size, data and load_* are reported by rocprofiler-sdk's code object tracing service.
68 * Used for the decoder library to know what code objects to look into when decoding shader data.
69 * Not all application code objects are required to be reported here, only the ones containing code
70 * executed at the time the shader data was collected by thread_trace services.
71 * If a code object not reported here is encountered while decoding shader data, a record of type
72 * INFO_STITCH_INCOMPLETE will be generated and instructions will not be reported with a PC address.
73 *
74 * @param[in] handle Handle to decoder instance.
75 * @param[in] load_id Code object load ID.
76 * @param[in] load_addr Code object load address.
77 * @param[in] load_size Code object load size.
78 * @param[in] data Code object binary data.
79 * @param[in] size Code object binary data size.
80 * @return ::rocprofiler_status_t
81 * @retval ::ROCPROFILER_STATUS_ERROR Unable to load code object.
82 * @retval ::ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT Invalid handle
83 * @retval ::ROCPROFILER_STATUS_SUCCESS Code object loaded
84 */
87 uint64_t load_id,
88 uint64_t load_addr,
89 uint64_t load_size,
90 const void* data,
91 uint64_t size) ROCPROFILER_API ROCPROFILER_NONNULL(5);
92
93/**
94 * @brief Unloads a code object binary.
95 * @param[in] handle Handle to decoder instance.
96 * @param[in] load_id Code object load ID to remove.
97 * @return ::rocprofiler_status_t
98 * @retval ::ROCPROFILER_STATUS_ERROR Code object not loaded.
99 * @retval ::ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT Invalid handle
100 * @retval ::ROCPROFILER_STATUS_SUCCESS Code object unloaded
101 */
104 uint64_t load_id) ROCPROFILER_API;
105
106/**
107 * @brief Callback for rocprof-trace-decoder to return decoder traces back to user.
108 * @param[in] record_type_id One of ::rocprofiler_thread_trace_decoder_record_type_t
109 * @param[in] trace_events A pointer to sequence of events, of size trace_size.
110 * @param[in] trace_size The number of events in the trace.
111 * @param[in] userdata Arbitrary data pointer to be sent back to the user via callback.
112 */
115 void* trace_events,
116 uint64_t trace_size,
117 void* userdata);
118
119/**
120 * @brief Decodes shader data returned by ::rocprofiler_thread_trace_shader_data_callback_t.
121 * Use ::rocprofiler_thread_trace_decoder_codeobj_load to add references to loaded code objects
122 * during the trace.
123 * A ::rocprofiler_thread_trace_decoder_callback_t returns decoded data back to user. The first
124 * record is always of type ::ROCPROFILER_THREAD_TRACE_DECODER_RECORD_GFXIP.
125 *
126 * @param[in] handle Decoder handle
127 * @param[in] callback Decoded trace data returned to user.
128 * @param[in] data Thread trace binary data.
129 * @param[in] size Thread trace binary size.
130 * @param[in] userdata Userdata passed back to caller via callback.
131 * @return ::rocprofiler_status_t
132 * @retval ::ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT invalid argument
133 * @retval ::ROCPROFILER_STATUS_ERROR_AGENT_ARCH_NOT_SUPPORTED arch not supported
134 * @retval ::ROCPROFILER_STATUS_ERROR generic error
135 * @retval ::ROCPROFILER_STATUS_SUCCESS on success
136 */
140 void* data,
141 uint64_t size,
142 void* userdata) ROCPROFILER_API ROCPROFILER_NONNULL(2, 3);
143
144/**
145 * @brief Returns the string description of a ::rocprofiler_thread_trace_decoder_info_t record.
146 * @param[in] handle Decoder handle
147 * @param[in] info The decoder info received
148 * @retval null terminated string as description of "info".
149 */
150const char*
153 ROCPROFILER_API;
154
155/** @} */
156
157ROCPROFILER_EXTERN_C_FINI
rocprofiler_status_t
Status codes.
Definition fwd.h:49
rocprofiler_status_t rocprofiler_trace_decode(rocprofiler_thread_trace_decoder_id_t handle, rocprofiler_thread_trace_decoder_callback_t callback, void *data, uint64_t size, void *userdata)
Decodes shader data returned by rocprofiler_thread_trace_shader_data_callback_t. Use rocprofiler_thre...
const char * rocprofiler_thread_trace_decoder_info_string(rocprofiler_thread_trace_decoder_id_t handle, rocprofiler_thread_trace_decoder_info_t info)
Returns the string description of a rocprofiler_thread_trace_decoder_info_t record.
rocprofiler_status_t rocprofiler_thread_trace_decoder_create(rocprofiler_thread_trace_decoder_id_t *handle, const char *path)
Initializes Trace Decoder library with a library search path.
rocprofiler_thread_trace_decoder_record_type_t
Defines the type of payload received by rocprofiler_thread_trace_decoder_callback_t.
rocprofiler_thread_trace_decoder_info_t
Describes the type of info received.
rocprofiler_status_t rocprofiler_thread_trace_decoder_codeobj_unload(rocprofiler_thread_trace_decoder_id_t handle, uint64_t load_id)
Unloads a code object binary.
void rocprofiler_thread_trace_decoder_destroy(rocprofiler_thread_trace_decoder_id_t handle)
Deletes handle created by rocprofiler_thread_trace_decoder_create.
rocprofiler_status_t rocprofiler_thread_trace_decoder_codeobj_load(rocprofiler_thread_trace_decoder_id_t handle, uint64_t load_id, uint64_t load_addr, uint64_t load_size, const void *data, uint64_t size)
Loads a code object binary to match with Thread Trace. The size, data and load_* are reported by rocp...
void(* rocprofiler_thread_trace_decoder_callback_t)(rocprofiler_thread_trace_decoder_record_type_t record_type_id, void *trace_events, uint64_t trace_size, void *userdata)
Callback for rocprof-trace-decoder to return decoder traces back to user.
Handle containing a loaded rocprof-trace-decoder and a decoder state.