rocprofiler-sdk/amd_detail/thread_trace_core.h Source File

rocprofiler-sdk/amd_detail/thread_trace_core.h Source File#

Rocprofiler SDK Developer API: rocprofiler-sdk/amd_detail/thread_trace_core.h Source File
Rocprofiler SDK Developer API 0.4.0
ROCm Profiling API and tools
thread_trace_core.h
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2024 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
27#include <rocprofiler-sdk/fwd.h>
28#include <rocprofiler-sdk/hsa.h>
29
30ROCPROFILER_EXTERN_C_INIT
31
32/**
33 * @defgroup THREAD_TRACE Thread Trace Service
34 * @brief Provides API calls to enable and handle thread trace data
35 *
36 * @{
37 */
38
49
50typedef struct
51{
53 union
54 {
55 uint64_t value;
56 struct
57 {
58 rocprofiler_counter_id_t counter_id;
59 uint64_t simd_mask : 4;
60 };
61 };
63
64/**
65 * @brief Callback to be triggered every time some ATT data is generated by the device
66 * @param [in] shader_engine_id ID of shader engine, as enabled by SE_MASK
67 * @param [in] data Pointer to the buffer containing the ATT data
68 * @param [in] data_size Number of bytes in "data"
69 * @param [in] userdata_dispatch Passed back to user from rocprofiler_att_dispatch_callback_t()
70 * @param [in] userdata_config Passed back to user from configure_[...]_service()
71 */
72typedef void (*rocprofiler_att_shader_data_callback_t)(int64_t shader_engine_id,
73 void* data,
74 size_t data_size,
76
77/**
78 * @brief Callback for rocprofiler to parsed ATT data.
79 * The caller must copy a desired instruction on isa_instruction and source_reference,
80 * while obeying the max length passed by the caller.
81 * If the caller's length is insufficient, then this function writes the minimum sizes to isa_size
82 * and source_size and returns ROCPROFILER_STATUS_ERROR_OUT_OF_RESOURCES.
83 * If call returns ROCPROFILER_STATUS_SUCCESS, isa_size and source_size are written with bytes used.
84 * @param[out] isa_instruction Where to copy the ISA line to.
85 * @param[out] isa_memory_size (Auto) The number of bytes to next instruction. 0 for custom ISA.
86 * @param[inout] isa_size Size of returned ISA string.
87 * @param[in] marker_id The generated ATT marker for given codeobject ID.
88 * @param[in] offset The offset from base vaddr for given codeobj ID.
89 * If marker_id == 0, this parameter is raw virtual address with no codeobj ID information.
90 * @param[in] userdata Arbitrary data pointer to be sent back to the user via callback.
91 * @retval ROCPROFILER_STATUS_SUCCESS on success.
92 * @retval ROCPROFILER_STATUS_ERROR on generic error.
93 * @retval ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT for invalid offset or invalid marker_id.
94 * @retval ROCPROFILER_STATUS_ERROR_OUT_OF_RESOURCES for insufficient isa_size or source_size.
95 */
97 uint64_t* isa_memory_size,
98 uint64_t* isa_size,
99 uint64_t marker_id,
100 uint64_t offset,
101 void* userdata);
102
103/**
104 * @brief Callback for the ATT parser to retrieve Shader Engine data.
105 * Returns the amount of data filled. If no more data is available, then callback return 0
106 * If the space available in the buffer is less than required for parsing the full data,
107 * the full data is transfered over multiple calls.
108 * When all data has been transfered from current shader_engine_id, the caller has the option to
109 * 1) Return -1 on shader_engine ID and parsing terminates
110 * 2) Move to the next shader engine.
111 * @param[out] shader_engine_id The ID of given shader engine.
112 * @param[out] buffer The buffer to fill up with SE data.
113 * @param[out] buffer_size The space available in the buffer.
114 * @param[in] userdata Arbitrary data pointer to be sent back to the user via callback.
115 * @returns Number of bytes remaining in shader engine.
116 * @retval 0 if no more SE data is available. Parsing will stop.
117 * @retval ret Where 0 > ret > buffer_size for partially filled buffer, and caller moves over to
118 * next SE.
119 * @retval buffer_size if the buffer does not hold enough data for the current shader engine.
120 */
121typedef uint64_t (*rocprofiler_att_parser_se_data_callback_t)(int* shader_engine_id,
122 uint8_t** buffer,
123 uint64_t* buffer_size,
124 void* userdata);
125
131
132typedef struct
133{
134 uint64_t marker_id;
135 uint64_t offset;
136 uint64_t hitcount;
137 uint64_t latency;
139
140typedef struct
141{
142 uint64_t marker_id;
143 uint64_t offset;
144 uint64_t timestamp : 63;
145 uint64_t enabled : 1;
147
148/**
149 * @brief Callback for rocprofiler to return traces back to rocprofiler.
150 * @param[in] att_data A datapoint retrieved from thread_trace
151 * @param[in] userdata Arbitrary data pointer to be sent back to the user via callback.
152 */
154 void* att_data,
155 void* userdata);
156
157/**
158 * @brief Iterate over all event coordinates for a given agent_t and event_t.
159 * @param[in] se_data_callback Callback to return shader engine data from.
160 * @param[in] trace_callback Callback where the trace data is returned to.
161 * @param[in] isa_callback Callback to return ISA lines.
162 * @param[in] userdata Userdata passed back to caller via callback.
163 */
168 void* userdata);
169
170/** @} */
171
172ROCPROFILER_EXTERN_C_FINI
rocprofiler_status_t
Status codes.
Definition fwd.h:55
Counter ID.
Definition fwd.h:549
User-assignable data type.
Definition fwd.h:487
rocprofiler_att_parameter_type_t type
rocprofiler_status_t rocprofiler_att_parse_data(rocprofiler_att_parser_se_data_callback_t se_data_callback, rocprofiler_att_parser_trace_callback_t trace_callback, rocprofiler_att_parser_isa_callback_t isa_callback, void *userdata)
Iterate over all event coordinates for a given agent_t and event_t.
rocprofiler_att_parameter_type_t
rocprofiler_status_t(* rocprofiler_att_parser_isa_callback_t)(char *isa_instruction, uint64_t *isa_memory_size, uint64_t *isa_size, uint64_t marker_id, uint64_t offset, void *userdata)
Callback for rocprofiler to parsed ATT data. The caller must copy a desired instruction on isa_instru...
void(* rocprofiler_att_shader_data_callback_t)(int64_t shader_engine_id, void *data, unsigned long data_size, rocprofiler_user_data_t userdata)
Callback to be triggered every time some ATT data is generated by the device.
void(* rocprofiler_att_parser_trace_callback_t)(rocprofiler_att_parser_data_type_t type, void *att_data, void *userdata)
Callback for rocprofiler to return traces back to rocprofiler.
rocprofiler_att_parser_data_type_t
uint64_t(* rocprofiler_att_parser_se_data_callback_t)(int *shader_engine_id, uint8_t **buffer, uint64_t *buffer_size, void *userdata)
Callback for the ATT parser to retrieve Shader Engine data. Returns the amount of data filled....
@ ROCPROFILER_ATT_PARAMETER_SHADER_ENGINE_MASK
Bitmask of shader engines.
@ ROCPROFILER_ATT_PARAMETER_SIMD_SELECT
Bitmask (GFX9) or ID (Navi) of SIMDs.
@ ROCPROFILER_ATT_PARAMETER_TARGET_CU
Select the Target CU or WGP.
@ ROCPROFILER_ATT_PARAMETER_LAST
@ ROCPROFILER_ATT_PARAMETER_BUFFER_SIZE
Size of combined GPU buffer for ATT.
@ ROCPROFILER_ATT_PARAMETER_PERFCOUNTERS_CTRL
@ ROCPROFILER_ATT_PARAMETER_PERFCOUNTER
@ ROCPROFILER_ATT_PARSER_DATA_TYPE_ISA
@ ROCPROFILER_ATT_PARSER_DATA_TYPE_OCCUPANCY