Skip to content

Commit 49c4992

Browse files
author
Baraldi, Giovanni
authored
SWDEV-492607: Adding ATT wrapper (#40)
* Adding att parser wrapper * Adding ATT tests as optional * Adding decoder API for query capability * Removed samples * Formatting * adding new line * Removed perfetto and moved to static library * using default search for lib * Updated to SDK * Namespace changes * Added tests * Small refactor * Updated API to receive agent_id * Fixing tests * Tidy fixes * Not write to file * Switch to filesystem.hpp * Compilation fixes * Formatting * Tidy fix * Removed likely * Adding tests * Added gfx9 test * Adding gfx12 tests * Formatting * Enable tidy * Fix tests * Fix deadlock on agent test * Workaround ASAN * Moving query outside class. * Fix standalone tool * Addressing comments * Formatting * Change query name * Fixed some tests. Updated PR comments. * Formatting * Improved coverage * Formatting * Fix for comments * Formatting * Adding some description. Fix error type. --------- Co-authored-by: Giovanni Baraldi <gbaraldi@amd.com> [ROCm/rocprofiler-sdk commit: 2c8e88a]
1 parent 63172af commit 49c4992

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+4240
-1076
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
/compile_commands.json
3636
/build*
3737
/.cache
38-
/.vscode
38+
*.vscode
3939

4040
# Github Workflows
4141
/.github

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@
2828
[submodule "external/yaml-cpp"]
2929
path = external/yaml-cpp
3030
url = https://github.com/jbeder/yaml-cpp.git
31+
[submodule "external/json"]
32+
path = external/json
33+
url = https://github.com/nlohmann/json.git

cmake/rocprofiler_interfaces.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ rocprofiler_add_interface_library(rocprofiler-sdk-dw "ElfUtils dw library" INTER
5959
rocprofiler_add_interface_library(rocprofiler-sdk-elfio "ELFIO header-only C++ library"
6060
INTERNAL)
6161
rocprofiler_add_interface_library(rocprofiler-sdk-yaml-cpp "YAML CPP Parser" INTERNAL)
62+
rocprofiler_add_interface_library(rocprofiler-sdk-json "nlohmann json" INTERNAL)
6263

6364
#
6465
# interface for libraries (ROCm-specific)

external/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,17 @@ endif()
209209

210210
# OTF2
211211
add_subdirectory(otf2)
212+
213+
rocprofiler_checkout_git_submodule(
214+
RECURSIVE
215+
RELATIVE_PATH external/json
216+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
217+
REPO_URL https://github.com/nlohmann/json.git
218+
REPO_BRANCH "develop")
219+
220+
add_subdirectory(json)
221+
222+
# target_link_libraries(rocprofiler-sdk-json INTERFACE $<BUILD_INTERFACE:json::json>)
223+
target_include_directories(
224+
rocprofiler-sdk-json SYSTEM
225+
INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/external/json/include>)

external/json

Submodule json added at e41905f

samples/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ add_subdirectory(code_object_tracing)
3030
add_subdirectory(counter_collection)
3131
add_subdirectory(intercept_table)
3232
add_subdirectory(code_object_isa_decode)
33-
add_subdirectory(advanced_thread_trace)
3433
add_subdirectory(external_correlation_id_request)
3534
add_subdirectory(pc_sampling)
3635
if(ROCPROFILER_BUILD_OPENMP_TESTS)

source/include/rocprofiler-sdk/amd_detail/thread_trace_agent.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ ROCPROFILER_EXTERN_C_INIT
4848
* @param [in] num_parameters Number of parameters. Zero is allowed.
4949
* @param [in] agent_id agent to configure profiling on.
5050
* @param [in] shader_callback Callback fn where the collected data will be sent to.
51-
* @param [in] callback_userdata Passed back to user.
51+
* @param [in] callback_userdata Passed back to user in shader_callback.
52+
* @return ::rocprofiler_status_t
53+
* @retval ROCPROFILER_STATUS_SUCCESS on success
54+
* @retval ROCPROFILER_STATUS_ERROR_CONFIGURATION_LOCKED for configuration locked
55+
* @retval ROCPROFILER_STATUS_ERROR_CONTEXT_INVALID for conflicting configurations in the same ctx
56+
* @retval ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_FOUND for invalid context id
57+
* @retval ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT for invalid rocprofiler_att_parameter_t
5258
*/
5359
rocprofiler_status_t
5460
rocprofiler_configure_agent_thread_trace_service(
@@ -57,7 +63,7 @@ rocprofiler_configure_agent_thread_trace_service(
5763
size_t num_parameters,
5864
rocprofiler_agent_id_t agent_id,
5965
rocprofiler_att_shader_data_callback_t shader_callback,
60-
void* callback_userdata) ROCPROFILER_API;
66+
rocprofiler_user_data_t callback_userdata) ROCPROFILER_API;
6167

6268
/** @} */
6369

source/include/rocprofiler-sdk/amd_detail/thread_trace_core.h

Lines changed: 2 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -68,104 +68,12 @@ typedef struct
6868
* @param [in] data_size Number of bytes in "data"
6969
* @param [in] userdata Passed back to user from rocprofiler_att_dispatch_callback_t()
7070
*/
71-
typedef void (*rocprofiler_att_shader_data_callback_t)(int64_t shader_engine_id,
71+
typedef void (*rocprofiler_att_shader_data_callback_t)(rocprofiler_agent_id_t agent,
72+
int64_t shader_engine_id,
7273
void* data,
7374
size_t data_size,
7475
rocprofiler_user_data_t userdata);
7576

76-
/**
77-
* @brief Callback for rocprofiler to parsed ATT data.
78-
* The caller must copy a desired instruction on isa_instruction and source_reference,
79-
* while obeying the max length passed by the caller.
80-
* If the caller's length is insufficient, then this function writes the minimum sizes to isa_size
81-
* and source_size and returns ROCPROFILER_STATUS_ERROR_OUT_OF_RESOURCES.
82-
* If call returns ROCPROFILER_STATUS_SUCCESS, isa_size and source_size are written with bytes used.
83-
* @param[out] isa_instruction Where to copy the ISA line to.
84-
* @param[out] isa_memory_size (Auto) The number of bytes to next instruction. 0 for custom ISA.
85-
* @param[inout] isa_size Size of returned ISA string.
86-
* @param[in] marker_id The generated ATT marker for given codeobject ID.
87-
* @param[in] offset The offset from base vaddr for given codeobj ID.
88-
* If marker_id == 0, this parameter is raw virtual address with no codeobj ID information.
89-
* @param[in] userdata Arbitrary data pointer to be sent back to the user via callback.
90-
* @retval ROCPROFILER_STATUS_SUCCESS on success.
91-
* @retval ROCPROFILER_STATUS_ERROR on generic error.
92-
* @retval ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT for invalid offset or invalid marker_id.
93-
* @retval ROCPROFILER_STATUS_ERROR_OUT_OF_RESOURCES for insufficient isa_size or source_size.
94-
*/
95-
typedef rocprofiler_status_t (*rocprofiler_att_parser_isa_callback_t)(char* isa_instruction,
96-
uint64_t* isa_memory_size,
97-
uint64_t* isa_size,
98-
uint64_t marker_id,
99-
uint64_t offset,
100-
void* userdata);
101-
102-
/**
103-
* @brief Callback for the ATT parser to retrieve Shader Engine data.
104-
* Returns the amount of data filled. If no more data is available, then callback return 0
105-
* If the space available in the buffer is less than required for parsing the full data,
106-
* the full data is transfered over multiple calls.
107-
* When all data has been transfered from current shader_engine_id, the caller has the option to
108-
* 1) Return -1 on shader_engine ID and parsing terminates
109-
* 2) Move to the next shader engine.
110-
* @param[out] shader_engine_id The ID of given shader engine.
111-
* @param[out] buffer The buffer to fill up with SE data.
112-
* @param[out] buffer_size The space available in the buffer.
113-
* @param[in] userdata Arbitrary data pointer to be sent back to the user via callback.
114-
* @returns Number of bytes remaining in shader engine.
115-
* @retval 0 if no more SE data is available. Parsing will stop.
116-
* @retval ret Where 0 > ret > buffer_size for partially filled buffer, and caller moves over to
117-
* next SE.
118-
* @retval buffer_size if the buffer does not hold enough data for the current shader engine.
119-
*/
120-
typedef uint64_t (*rocprofiler_att_parser_se_data_callback_t)(int* shader_engine_id,
121-
uint8_t** buffer,
122-
uint64_t* buffer_size,
123-
void* userdata);
124-
125-
typedef enum
126-
{
127-
ROCPROFILER_ATT_PARSER_DATA_TYPE_ISA = 0,
128-
ROCPROFILER_ATT_PARSER_DATA_TYPE_OCCUPANCY,
129-
} rocprofiler_att_parser_data_type_t;
130-
131-
typedef struct
132-
{
133-
uint64_t marker_id;
134-
uint64_t offset;
135-
uint64_t hitcount;
136-
uint64_t latency;
137-
} rocprofiler_att_data_type_isa_t;
138-
139-
typedef struct
140-
{
141-
uint64_t marker_id;
142-
uint64_t offset;
143-
uint64_t timestamp : 63;
144-
uint64_t enabled : 1;
145-
} rocprofiler_att_data_type_occupancy_t;
146-
147-
/**
148-
* @brief Callback for rocprofiler to return traces back to rocprofiler.
149-
* @param[in] att_data A datapoint retrieved from thread_trace
150-
* @param[in] userdata Arbitrary data pointer to be sent back to the user via callback.
151-
*/
152-
typedef void (*rocprofiler_att_parser_trace_callback_t)(rocprofiler_att_parser_data_type_t type,
153-
void* att_data,
154-
void* userdata);
155-
156-
/**
157-
* @brief Iterate over all event coordinates for a given agent_t and event_t.
158-
* @param[in] se_data_callback Callback to return shader engine data from.
159-
* @param[in] trace_callback Callback where the trace data is returned to.
160-
* @param[in] isa_callback Callback to return ISA lines.
161-
* @param[in] userdata Userdata passed back to caller via callback.
162-
*/
163-
rocprofiler_status_t
164-
rocprofiler_att_parse_data(rocprofiler_att_parser_se_data_callback_t se_data_callback,
165-
rocprofiler_att_parser_trace_callback_t trace_callback,
166-
rocprofiler_att_parser_isa_callback_t isa_callback,
167-
void* userdata) ROCPROFILER_API;
168-
16977
/** @} */
17078

17179
ROCPROFILER_EXTERN_C_FINI

source/include/rocprofiler-sdk/amd_detail/thread_trace_dispatch.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,23 @@ typedef enum
4545

4646
/**
4747
* @brief Callback to be triggered every kernel dispatch, indicating to start and/or stop ATT
48+
* @param [in] agent_id agent_id.
49+
* @param [in] queue_id queue_id.
50+
* @param [in] correlation_id internal correlation id.
51+
* @param [in] kernel_id kernel_id.
52+
* @param [in] dispatch_id dispatch_id.
53+
* @param [in] userdata_config Userdata passed back from
54+
* rocprofiler_configure_dispatch_thread_trace_service.
55+
* @param [out] userdata_shader Userdata to be passed in shader_callback
4856
*/
4957
typedef rocprofiler_att_control_flags_t (*rocprofiler_att_dispatch_callback_t)(
58+
rocprofiler_agent_id_t agent_id,
5059
rocprofiler_queue_id_t queue_id,
51-
const rocprofiler_agent_t* agent,
5260
rocprofiler_correlation_id_t correlation_id,
5361
rocprofiler_kernel_id_t kernel_id,
5462
rocprofiler_dispatch_id_t dispatch_id,
55-
rocprofiler_user_data_t* userdata_shader,
56-
void* userdata_config);
63+
void* userdata_config,
64+
rocprofiler_user_data_t* userdata_shader);
5765

5866
/**
5967
* @brief Enables the advanced thread trace service for dispatch-based tracing.
@@ -64,7 +72,14 @@ typedef rocprofiler_att_control_flags_t (*rocprofiler_att_dispatch_callback_t)(
6472
* @param [in] num_parameters Number of parameters. Zero is allowed.
6573
* @param [in] dispatch_callback Control fn which decides when ATT starts/stop collecting.
6674
* @param [in] shader_callback Callback fn where the collected data will be sent to.
67-
* @param [in] callback_userdata Passed back to user.
75+
* @param [in] callback_userdata Passed back to user in dispatch_callback.
76+
* @return ::rocprofiler_status_t
77+
* @retval ROCPROFILER_STATUS_SUCCESS on success
78+
* @retval ROCPROFILER_STATUS_ERROR_CONFIGURATION_LOCKED for configuration locked
79+
* @retval ROCPROFILER_STATUS_ERROR_CONTEXT_INVALID for conflicting configurations in the same ctx
80+
* @retval ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_FOUND for invalid context id
81+
* @retval ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT for invalid rocprofiler_att_parameter_t
82+
* @retval ROCPROFILER_STATUS_ERROR_SERVICE_ALREADY_CONFIGURED if already configured
6883
*/
6984
rocprofiler_status_t
7085
rocprofiler_configure_dispatch_thread_trace_service(

source/lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ add_subdirectory(rocprofiler-sdk)
99
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "tools")
1010
add_subdirectory(rocprofiler-sdk-codeobj)
1111
add_subdirectory(rocprofiler-sdk-roctx)
12+
add_subdirectory(rocprofiler-sdk-att)
1213
add_subdirectory(rocprofiler-sdk-tool)
1314

1415
if(ROCPROFILER_BUILD_TESTS)

0 commit comments

Comments
 (0)