Thread trace and Trace Decoder API tests and samples (#416)
* Adding test and samples to decoder * Fix sample * Formatting * Fix multi test * Disable sample * Fix tests * Format * Version fix * Locking the decoder * Add atomic * Review comments * Format * Adding readme * merge conflict and adding PCS+ATT test * Review comments * Properly disable PCS test * Update tests/rocprofv3/advanced-thread-trace/CMakeLists.txt * Adding back env var test * Name fix * Preload sample * Addressing review comments * Update docs --------- Co-authored-by: Giovanni Baraldi <gbaraldi@amd.com>
This commit is contained in:
committed by
GitHub
parent
bf0fad1d54
commit
e898079a13
@@ -42,8 +42,6 @@ rocprofiler_configure_pytest_files(CONFIG pytest.ini COPY validate.py conftest.p
|
||||
|
||||
find_package(rocprofiler-sdk REQUIRED)
|
||||
|
||||
set(IS_DISABLED ON)
|
||||
|
||||
find_library(
|
||||
attdecoder_LIBRARY
|
||||
NAMES rocprof-trace-decoder
|
||||
@@ -58,43 +56,43 @@ endif()
|
||||
find_package_handle_standard_args(attdecoder REQUIRED_VARS attdecoder_LIB_DIR
|
||||
attdecoder_LIBRARY)
|
||||
|
||||
set(COMMON_PARAMS_NO_LIB ${PRELOAD_ARGS} --att --output-format json --log-level env -d
|
||||
${CMAKE_CURRENT_BINARY_DIR}/%argt%-trace/)
|
||||
|
||||
set(IS_DISABLED ON)
|
||||
if(attdecoder_FOUND)
|
||||
set(IS_DISABLED OFF)
|
||||
set(LIB_PATH_ENV "ROCPROF_ATT_LIBRARY_PATH=${attdecoder_LIB_DIR}")
|
||||
set(COMMON_PARAMS --att-library-path ${attdecoder_LIB_DIR} ${COMMON_PARAMS_NO_LIB})
|
||||
endif()
|
||||
|
||||
# hsa multiqueue dependency test with lib path
|
||||
add_test(
|
||||
NAME rocprofv3-test-hsa-multiqueue-att-cmd-env-att-lib-path-execute
|
||||
NAME rocprofv3-test-att-hsa-multiqueue-cmd-env-att-lib-path-execute
|
||||
COMMAND
|
||||
$<TARGET_FILE:rocprofiler-sdk::rocprofv3> --log-level env --advanced-thread-trace
|
||||
1 --att-target-cu 1 --att-shader-engine-mask 0x11 --kernel-include-regex copyD
|
||||
--att-buffer-size 0x6000000 --att-simd-select 0x3 --att-serialize-all 1 -d
|
||||
${CMAKE_CURRENT_BINARY_DIR}/%argt%-trace/cmd_input -o out --output-format json
|
||||
${PRELOAD_ARGS} --att-library-path ${attdecoder_LIB_DIR} --att-activity 8 --
|
||||
$<TARGET_FILE:rocprofiler-sdk::rocprofv3> ${COMMON_PARAMS}/cmd_input
|
||||
--att-target-cu 1 --att-shader-engine-mask 0x11 --kernel-include-regex copyD
|
||||
--att-buffer-size 0x6000000 --att-simd-select 0x3 --att-serialize-all 1 -o out --
|
||||
$<TARGET_FILE:hsa_code_object_testapp>)
|
||||
|
||||
set_tests_properties(
|
||||
rocprofv3-test-hsa-multiqueue-att-cmd-env-att-lib-path-execute
|
||||
rocprofv3-test-att-hsa-multiqueue-cmd-env-att-lib-path-execute
|
||||
PROPERTIES TIMEOUT 45 LABELS "integration-tests" DISABLED ${IS_DISABLED})
|
||||
|
||||
# hsa multiqueue dependency test with json input
|
||||
add_test(
|
||||
NAME rocprofv3-test-hsa-multiqueue-att-json-execute
|
||||
NAME rocprofv3-test-att-hsa-multiqueue-json-execute
|
||||
COMMAND
|
||||
$<TARGET_FILE:rocprofiler-sdk::rocprofv3> --log-level env --att-library-path
|
||||
${attdecoder_LIB_DIR} -d ${CMAKE_CURRENT_BINARY_DIR}/%argt%-trace/json_input -i
|
||||
${CMAKE_CURRENT_BINARY_DIR}/att_input.json ${PRELOAD_ARGS} --
|
||||
$<TARGET_FILE:rocprofiler-sdk::rocprofv3> ${COMMON_PARAMS}/json_input -i
|
||||
${CMAKE_CURRENT_BINARY_DIR}/att_input.json --
|
||||
$<TARGET_FILE:hsa_code_object_testapp>)
|
||||
|
||||
set_tests_properties(
|
||||
rocprofv3-test-hsa-multiqueue-att-json-execute
|
||||
PROPERTIES TIMEOUT 45 LABELS "integration-tests" DISABLED ${IS_DISABLED} ENVIRONMENT
|
||||
"${LIB_PATH_ENV}")
|
||||
rocprofv3-test-att-hsa-multiqueue-json-execute
|
||||
PROPERTIES TIMEOUT 45 LABELS "integration-tests" DISABLED ${IS_DISABLED})
|
||||
|
||||
# validate output
|
||||
add_test(
|
||||
NAME rocprofv3-test-hsa-multiqueue-att-cmd-validate
|
||||
NAME rocprofv3-test-att-hsa-multiqueue-cmd-validate
|
||||
COMMAND
|
||||
${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/validate.py --input
|
||||
${CMAKE_CURRENT_BINARY_DIR}/hsa_code_object_testapp-trace/cmd_input/out_results.json
|
||||
@@ -102,7 +100,7 @@ add_test(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/hsa_code_object_testapp-trace/cmd_input)
|
||||
|
||||
add_test(
|
||||
NAME rocprofv3-test-hsa-multiqueue-att-json-validate
|
||||
NAME rocprofv3-test-att-hsa-multiqueue-json-validate
|
||||
COMMAND
|
||||
${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/validate.py --input
|
||||
${CMAKE_CURRENT_BINARY_DIR}/hsa_code_object_testapp-trace/json_input/out_results.json
|
||||
@@ -110,46 +108,46 @@ add_test(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/hsa_code_object_testapp-trace/json_input)
|
||||
|
||||
set_tests_properties(
|
||||
rocprofv3-test-hsa-multiqueue-att-cmd-validate
|
||||
rocprofv3-test-att-hsa-multiqueue-cmd-validate
|
||||
PROPERTIES TIMEOUT
|
||||
45
|
||||
LABELS
|
||||
"integration-tests"
|
||||
DEPENDS
|
||||
"rocprofv3-test-hsa-multiqueue-att-cmd-ld-lib-path-execute"
|
||||
"rocprofv3-test-att-hsa-multiqueue-cmd-ld-lib-path-execute"
|
||||
FAIL_REGULAR_EXPRESSION
|
||||
"AssertionError"
|
||||
DISABLED
|
||||
${IS_DISABLED})
|
||||
|
||||
set_tests_properties(
|
||||
rocprofv3-test-hsa-multiqueue-att-json-validate
|
||||
rocprofv3-test-att-hsa-multiqueue-json-validate
|
||||
PROPERTIES TIMEOUT
|
||||
45
|
||||
LABELS
|
||||
"integration-tests"
|
||||
DEPENDS
|
||||
"rocprofv3-test-hsa-multiqueue-att-json-execute"
|
||||
"rocprofv3-test-att-hsa-multiqueue-json-execute"
|
||||
FAIL_REGULAR_EXPRESSION
|
||||
"AssertionError"
|
||||
DISABLED
|
||||
${IS_DISABLED})
|
||||
|
||||
function(configure_att_input _FILENAME _OUTDIR)
|
||||
set(LIBRARY_OUTPUT_DIR ${_OUTDIR})
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/att_input.yml.in
|
||||
function(configure_att_input _FILENAME)
|
||||
set(LIB_PATH_LOC "${attdecoder_LIB_DIR}")
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}//${_FILENAME}.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${_FILENAME} @ONLY)
|
||||
endfunction()
|
||||
|
||||
configure_att_input(att_input.yml "${attdecoder_LIB_DIR}")
|
||||
configure_att_input(att_input_will_fail.yml "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
|
||||
configure_att_input(att_input.yml)
|
||||
configure_att_input(att_input_will_fail.yml)
|
||||
|
||||
# test yaml input
|
||||
add_test(
|
||||
NAME rocprofv3-test-att-yaml-input
|
||||
COMMAND
|
||||
$<TARGET_FILE:rocprofiler-sdk::rocprofv3> -i
|
||||
${CMAKE_CURRENT_BINARY_DIR}/att_input.yml --log-level env --echo --
|
||||
$<TARGET_FILE:rocprofiler-sdk::rocprofv3> ${COMMON_PARAMS_NO_LIB}/yaml -i
|
||||
${CMAKE_CURRENT_BINARY_DIR}/att_input.yml --echo --
|
||||
$<TARGET_FILE:hsa_code_object_testapp>)
|
||||
|
||||
set_tests_properties(
|
||||
@@ -166,7 +164,7 @@ add_test(
|
||||
|
||||
set_tests_properties(
|
||||
rocprofv3-test-att-yaml-input-will-fail
|
||||
PROPERTIES TIMEOUT 45 LABELS "integration-tests" WILL_FAIL ON DISABLED True)
|
||||
PROPERTIES TIMEOUT 45 LABELS "integration-tests" WILL_FAIL ON DISABLED ${IS_DISABLED})
|
||||
|
||||
add_test(NAME rocprofv3-test-att-library-path-cmd-line-will-fail
|
||||
COMMAND $<TARGET_FILE:rocprofiler-sdk::rocprofv3> --att --att-library-path .
|
||||
@@ -174,11 +172,12 @@ add_test(NAME rocprofv3-test-att-library-path-cmd-line-will-fail
|
||||
|
||||
set_tests_properties(
|
||||
rocprofv3-test-att-library-path-cmd-line-will-fail
|
||||
PROPERTIES TIMEOUT 45 LABELS "integration-tests" WILL_FAIL ON DISABLED True)
|
||||
PROPERTIES TIMEOUT 45 LABELS "integration-tests" WILL_FAIL ON DISABLED ${IS_DISABLED})
|
||||
|
||||
add_test(NAME rocprofv3-test-att-library-path-env-var-will-fail
|
||||
COMMAND $<TARGET_FILE:rocprofiler-sdk::rocprofv3> --att --log-level env --echo
|
||||
-- $<TARGET_FILE:hsa_code_object_testapp>)
|
||||
add_test(
|
||||
NAME rocprofv3-test-att-library-path-env-var-will-fail
|
||||
COMMAND $<TARGET_FILE:rocprofiler-sdk::rocprofv3> ${COMMON_PARAMS_NO_LIB}/envfail
|
||||
--att-library-path . --echo -- $<TARGET_FILE:hsa_code_object_testapp>)
|
||||
|
||||
set_tests_properties(
|
||||
rocprofv3-test-att-library-path-env-var-will-fail
|
||||
@@ -187,65 +186,70 @@ set_tests_properties(
|
||||
LABELS
|
||||
"integration-tests"
|
||||
ENVIRONMENT
|
||||
"ROCPROF_ATT_LIBRARY_PATH=."
|
||||
"ROCPROF_ATT_LIBRARY_PATH=${attdecoder_LIB_DIR}"
|
||||
WILL_FAIL
|
||||
ON
|
||||
DISABLED
|
||||
True)
|
||||
${IS_DISABLED})
|
||||
|
||||
add_test(NAME rocprofv3-test-att-env-var
|
||||
COMMAND $<TARGET_FILE:rocprofiler-sdk::rocprofv3> ${COMMON_PARAMS_NO_LIB}/envvar
|
||||
-- $<TARGET_FILE:hsa_code_object_testapp>)
|
||||
|
||||
set_tests_properties(
|
||||
rocprofv3-test-att-env-var
|
||||
PROPERTIES TIMEOUT 45 LABELS "integration-tests" ENVIRONMENT
|
||||
"ROCPROF_ATT_LIBRARY_PATH=${attdecoder_LIB_DIR}" DISABLED ${IS_DISABLED})
|
||||
|
||||
#
|
||||
# Uses ATT and Counter Collection at the same time
|
||||
#
|
||||
add_test(
|
||||
NAME rocprofv3-test-hsa-multiqueue-att-plus-pmc-execute
|
||||
COMMAND
|
||||
$<TARGET_FILE:rocprofiler-sdk::rocprofv3> --log-level env --pmc SQ_WAVES
|
||||
--advanced-thread-trace -d ${CMAKE_CURRENT_BINARY_DIR}/%argt%-trace/cmd_input -o
|
||||
out --output-format json ${PRELOAD_ARGS} -- $<TARGET_FILE:vector-ops>)
|
||||
add_test(NAME rocprofv3-test-att-hsa-multiqueue-plus-pmc-execute
|
||||
COMMAND $<TARGET_FILE:rocprofiler-sdk::rocprofv3> ${COMMON_PARAMS}/cmd_input
|
||||
--pmc SQ_WAVES -o out -- $<TARGET_FILE:vector-ops>)
|
||||
|
||||
set_tests_properties(
|
||||
rocprofv3-test-hsa-multiqueue-att-plus-pmc-execute
|
||||
PROPERTIES TIMEOUT 45 LABELS "integration-tests" DISABLED ${IS_DISABLED} ENVIRONMENT
|
||||
"${LIB_PATH_ENV}")
|
||||
rocprofv3-test-att-hsa-multiqueue-plus-pmc-execute
|
||||
PROPERTIES TIMEOUT 45 LABELS "integration-tests" DISABLED ${IS_DISABLED})
|
||||
|
||||
# Check for conflict PMC + activity
|
||||
add_test(
|
||||
NAME rocprofv3-test-hsa-multiqueue-att-activity-pmc-will-fail
|
||||
COMMAND
|
||||
$<TARGET_FILE:rocprofiler-sdk::rocprofv3> --log-level env --pmc SQ_WAVES
|
||||
--advanced-thread-trace -d ${CMAKE_CURRENT_BINARY_DIR}/%argt%-trace/cmd_input -o
|
||||
out --att-activity 8 ${PRELOAD_ARGS} -- $<TARGET_FILE:vector-ops>)
|
||||
add_test(NAME rocprofv3-test-att-hsa-multiqueue-activity-pmc-will-fail
|
||||
COMMAND $<TARGET_FILE:rocprofiler-sdk::rocprofv3> ${COMMON_PARAMS}/cmd_input
|
||||
--pmc SQ_WAVES -o out --att-activity 8 -- $<TARGET_FILE:vector-ops>)
|
||||
|
||||
set_tests_properties(
|
||||
rocprofv3-test-hsa-multiqueue-att-activity-pmc-will-fail
|
||||
PROPERTIES TIMEOUT
|
||||
45
|
||||
LABELS
|
||||
"integration-tests"
|
||||
DISABLED
|
||||
${IS_DISABLED}
|
||||
ENVIRONMENT
|
||||
"${LIB_PATH_ENV}"
|
||||
WILL_FAIL
|
||||
ON)
|
||||
rocprofv3-test-att-hsa-multiqueue-activity-pmc-will-fail
|
||||
PROPERTIES TIMEOUT 45 LABELS "integration-tests" DISABLED ${IS_DISABLED} WILL_FAIL ON)
|
||||
|
||||
# Check for conflict Perfcounters + activity
|
||||
add_test(
|
||||
NAME rocprofv3-test-hsa-multiqueue-att-activity-perf-will-fail
|
||||
COMMAND
|
||||
$<TARGET_FILE:rocprofiler-sdk::rocprofv3> --log-level env --att
|
||||
--att-perfcounter-ctrl 8 -d ${CMAKE_CURRENT_BINARY_DIR}/%argt%-trace/cmd_input -o
|
||||
out --att-activity 8 ${PRELOAD_ARGS} -- $<TARGET_FILE:vector-ops>)
|
||||
NAME rocprofv3-test-att-hsa-multiqueue-activity-perf-will-fail
|
||||
COMMAND $<TARGET_FILE:rocprofiler-sdk::rocprofv3> ${COMMON_PARAMS}/cmd_input
|
||||
--att-perfcounter-ctrl 8 -o out --att-activity 8 -- $<TARGET_FILE:vector-ops>)
|
||||
|
||||
set_tests_properties(
|
||||
rocprofv3-test-hsa-multiqueue-att-activity-perf-will-fail
|
||||
PROPERTIES TIMEOUT
|
||||
45
|
||||
LABELS
|
||||
"integration-tests"
|
||||
DISABLED
|
||||
${IS_DISABLED}
|
||||
ENVIRONMENT
|
||||
"${LIB_PATH_ENV}"
|
||||
WILL_FAIL
|
||||
ON)
|
||||
rocprofv3-test-att-hsa-multiqueue-activity-perf-will-fail
|
||||
PROPERTIES TIMEOUT 45 LABELS "integration-tests" DISABLED ${IS_DISABLED} WILL_FAIL ON)
|
||||
|
||||
# ATT plus PC sampling
|
||||
|
||||
rocprofiler_sdk_pc_sampling_stochastic_disabled(IS_PC_SAMPLING_STOCHASTIC_DISABLED)
|
||||
|
||||
set(ATT_PLUS_PCS_DISABLE ${IS_DISABLED})
|
||||
if(${IS_PC_SAMPLING_STOCHASTIC_DISABLED})
|
||||
set(ATT_PLUS_PCS_DISABLE ON)
|
||||
endif()
|
||||
if(${ROCPROFILER_DISABLE_UNSTABLE_CTESTS})
|
||||
set(ATT_PLUS_PCS_DISABLE ON)
|
||||
endif()
|
||||
set(PCS_ARGS --pc-sampling-beta-enabled 1 --pc-sampling-unit cycles
|
||||
--pc-sampling-interval 16384 --pc-sampling-method stochastic)
|
||||
|
||||
add_test(NAME rocprofv3-test-att-plus-pc-sampling
|
||||
COMMAND $<TARGET_FILE:rocprofiler-sdk::rocprofv3> ${COMMON_PARAMS}/cmd_input
|
||||
${PCS_ARGS} -o out -- $<TARGET_FILE:vector-ops>)
|
||||
|
||||
set_tests_properties(
|
||||
rocprofv3-test-att-plus-pc-sampling
|
||||
PROPERTIES TIMEOUT 90 LABELS "integration-tests;thread-trace;pc-sampling" DISABLED
|
||||
${ATT_PLUS_PCS_DISABLE})
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
jobs:
|
||||
- advanced_thread_trace: True
|
||||
att_library_path:
|
||||
- @LIBRARY_OUTPUT_DIR@/att
|
||||
- @LIBRARY_OUTPUT_DIR@
|
||||
- @LIB_PATH_LOC@/att
|
||||
- @LIB_PATH_LOC@
|
||||
|
||||
- advanced_thread_trace: True
|
||||
att_library_path:
|
||||
- @LIBRARY_OUTPUT_DIR@
|
||||
- @LIB_PATH_LOC@
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2023-2025 Advanced Micro Devices, Inc. All rights reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
jobs:
|
||||
- advanced_thread_trace: True
|
||||
att_library_path:
|
||||
- @LIB_PATH_LOC@/att
|
||||
@@ -29,17 +29,6 @@
|
||||
|
||||
#include <set>
|
||||
|
||||
#define C_API_BEGIN \
|
||||
try \
|
||||
{
|
||||
#define C_API_END \
|
||||
} \
|
||||
catch(std::exception & e) \
|
||||
{ \
|
||||
std::cerr << "Error in " << __FILE__ << ':' << __LINE__ << ' ' << e.what() << std::endl; \
|
||||
} \
|
||||
catch(...) { std::cerr << "Error in " << __FILE__ << ':' << __LINE__ << std::endl; }
|
||||
|
||||
namespace ATTTest
|
||||
{
|
||||
namespace Agent
|
||||
@@ -135,9 +124,10 @@ query_available_agents(rocprofiler_agent_version_t /* version */,
|
||||
}
|
||||
|
||||
int
|
||||
tool_init(rocprofiler_client_finalize_t fini_func, void* tool_data)
|
||||
tool_init(rocprofiler_client_finalize_t /* fini_func */, void* /* tool_data */)
|
||||
{
|
||||
(void) fini_func;
|
||||
Callbacks::init();
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_create_context(&tracing_ctx), "context creation");
|
||||
ROCPROFILER_CALL(rocprofiler_create_context(&agent_ctx), "context creation");
|
||||
|
||||
@@ -147,7 +137,7 @@ tool_init(rocprofiler_client_finalize_t fini_func, void* tool_data)
|
||||
nullptr,
|
||||
0,
|
||||
Callbacks::tool_codeobj_tracing_callback,
|
||||
tool_data),
|
||||
nullptr),
|
||||
"code object tracing service configure");
|
||||
|
||||
ROCPROFILER_CALL(
|
||||
@@ -156,13 +146,13 @@ tool_init(rocprofiler_client_finalize_t fini_func, void* tool_data)
|
||||
nullptr,
|
||||
0,
|
||||
dispatch_tracing_callback,
|
||||
tool_data),
|
||||
nullptr),
|
||||
"dispatch tracing service configure");
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_query_available_agents(ROCPROFILER_AGENT_INFO_VERSION_0,
|
||||
&query_available_agents,
|
||||
sizeof(rocprofiler_agent_t),
|
||||
tool_data),
|
||||
nullptr),
|
||||
"Failed to find GPU agents");
|
||||
|
||||
int valid_ctx = 0;
|
||||
@@ -177,13 +167,6 @@ tool_init(rocprofiler_client_finalize_t fini_func, void* tool_data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
tool_fini(void* tool_data)
|
||||
{
|
||||
Callbacks::finalize_json(tool_data);
|
||||
delete static_cast<Callbacks::ToolData*>(tool_data);
|
||||
}
|
||||
|
||||
} // namespace Agent
|
||||
} // namespace ATTTest
|
||||
|
||||
@@ -206,8 +189,8 @@ rocprofiler_configure(uint32_t /* version */,
|
||||
static auto cfg =
|
||||
rocprofiler_tool_configure_result_t{sizeof(rocprofiler_tool_configure_result_t),
|
||||
&ATTTest::Agent::tool_init,
|
||||
&ATTTest::Agent::tool_fini,
|
||||
new Callbacks::ToolData{"att_agent_test/"}};
|
||||
&Callbacks::finalize,
|
||||
nullptr};
|
||||
|
||||
// return pointer to configure data
|
||||
return &cfg;
|
||||
|
||||
@@ -48,15 +48,17 @@ dispatch_callback(rocprofiler_agent_id_t /* agent */,
|
||||
static std::atomic<size_t> count{0};
|
||||
if(count.fetch_add(1) > NUM_KERNELS) return ROCPROFILER_THREAD_TRACE_CONTROL_NONE;
|
||||
|
||||
assert(userdata && "Dispatch callback passed null!");
|
||||
assert(dispatch_userdata && "Dispatch callback passed null!");
|
||||
dispatch_userdata->ptr = userdata;
|
||||
|
||||
return ROCPROFILER_THREAD_TRACE_CONTROL_START_AND_STOP;
|
||||
}
|
||||
|
||||
int
|
||||
tool_init(rocprofiler_client_finalize_t /* fini_func */, void* tool_data)
|
||||
tool_init(rocprofiler_client_finalize_t /* fini_func */, void* /* tool_data */)
|
||||
{
|
||||
Callbacks::init();
|
||||
|
||||
static rocprofiler_context_id_t client_ctx = {0};
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_create_context(&client_ctx), "context creation");
|
||||
@@ -67,7 +69,7 @@ tool_init(rocprofiler_client_finalize_t /* fini_func */, void* tool_data)
|
||||
nullptr,
|
||||
0,
|
||||
Callbacks::tool_codeobj_tracing_callback,
|
||||
tool_data),
|
||||
nullptr),
|
||||
"code object tracing service configure");
|
||||
|
||||
std::vector<rocprofiler_thread_trace_parameter_t> params{};
|
||||
@@ -100,7 +102,7 @@ tool_init(rocprofiler_client_finalize_t /* fini_func */, void* tool_data)
|
||||
params.size(),
|
||||
dispatch_callback,
|
||||
Callbacks::shader_data_callback,
|
||||
tool_data),
|
||||
nullptr),
|
||||
"thread trace service configure");
|
||||
}
|
||||
|
||||
@@ -121,13 +123,6 @@ tool_init(rocprofiler_client_finalize_t /* fini_func */, void* tool_data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
tool_fini(void* tool_data)
|
||||
{
|
||||
Callbacks::finalize_json(tool_data);
|
||||
delete static_cast<Callbacks::ToolData*>(tool_data);
|
||||
}
|
||||
|
||||
} // namespace Multi
|
||||
} // namespace ATTTest
|
||||
|
||||
@@ -147,11 +142,11 @@ rocprofiler_configure(uint32_t /* version */,
|
||||
ATTTest::Multi::client_id = id;
|
||||
|
||||
// create configure data
|
||||
static auto cfg = rocprofiler_tool_configure_result_t{
|
||||
sizeof(rocprofiler_tool_configure_result_t),
|
||||
&ATTTest::Multi::tool_init,
|
||||
&ATTTest::Multi::tool_fini,
|
||||
reinterpret_cast<void*>(new Callbacks::ToolData{"att_multi_test/"})};
|
||||
static auto cfg =
|
||||
rocprofiler_tool_configure_result_t{sizeof(rocprofiler_tool_configure_result_t),
|
||||
&ATTTest::Multi::tool_init,
|
||||
&Callbacks::finalize,
|
||||
nullptr};
|
||||
|
||||
// return pointer to configure data
|
||||
return &cfg;
|
||||
|
||||
@@ -41,35 +41,20 @@ dispatch_callback(rocprofiler_agent_id_t /* agent */,
|
||||
rocprofiler_async_correlation_id_t /* correlation_id */,
|
||||
rocprofiler_kernel_id_t kernel_id,
|
||||
rocprofiler_dispatch_id_t /* dispatch_id */,
|
||||
void* userdata,
|
||||
rocprofiler_user_data_t* dispatch_userdata)
|
||||
void* /* userdata */,
|
||||
rocprofiler_user_data_t* /* dispatch_userdata */)
|
||||
{
|
||||
C_API_BEGIN
|
||||
assert(userdata && "Dispatch callback passed null!");
|
||||
auto& tool = *reinterpret_cast<Callbacks::ToolData*>(userdata);
|
||||
dispatch_userdata->ptr = userdata;
|
||||
static rocprofiler_kernel_id_t target_kernel_id = kernel_id;
|
||||
if(target_kernel_id == kernel_id) return ROCPROFILER_THREAD_TRACE_CONTROL_START_AND_STOP;
|
||||
|
||||
static std::string_view desired_func_name = "branching_kernel";
|
||||
|
||||
try
|
||||
{
|
||||
auto& kernel_name = tool.kernel_id_to_kernel_name.at(kernel_id);
|
||||
if(kernel_name.find(desired_func_name) == std::string::npos)
|
||||
return ROCPROFILER_THREAD_TRACE_CONTROL_NONE;
|
||||
|
||||
return ROCPROFILER_THREAD_TRACE_CONTROL_START_AND_STOP;
|
||||
} catch(...)
|
||||
{
|
||||
std::cerr << "Could not find kernel id: " << kernel_id << std::endl;
|
||||
}
|
||||
|
||||
C_API_END
|
||||
return ROCPROFILER_THREAD_TRACE_CONTROL_NONE;
|
||||
}
|
||||
|
||||
int
|
||||
tool_init(rocprofiler_client_finalize_t /* fini_func */, void* tool_data)
|
||||
tool_init(rocprofiler_client_finalize_t /* fini_func */, void* /* tool_data */)
|
||||
{
|
||||
Callbacks::init();
|
||||
|
||||
static rocprofiler_context_id_t client_ctx = {0};
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_create_context(&client_ctx), "context creation");
|
||||
@@ -80,7 +65,7 @@ tool_init(rocprofiler_client_finalize_t /* fini_func */, void* tool_data)
|
||||
nullptr,
|
||||
0,
|
||||
Callbacks::tool_codeobj_tracing_callback,
|
||||
tool_data),
|
||||
nullptr),
|
||||
"code object tracing service configure");
|
||||
|
||||
std::vector<rocprofiler_agent_id_t> agents{};
|
||||
@@ -110,7 +95,7 @@ tool_init(rocprofiler_client_finalize_t /* fini_func */, void* tool_data)
|
||||
0,
|
||||
dispatch_callback,
|
||||
Callbacks::shader_data_callback,
|
||||
tool_data),
|
||||
nullptr),
|
||||
"thread trace service configure");
|
||||
}
|
||||
|
||||
@@ -131,13 +116,6 @@ tool_init(rocprofiler_client_finalize_t /* fini_func */, void* tool_data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
tool_fini(void* tool_data)
|
||||
{
|
||||
Callbacks::finalize_json(tool_data);
|
||||
delete static_cast<Callbacks::ToolData*>(tool_data);
|
||||
}
|
||||
|
||||
} // namespace Single
|
||||
} // namespace ATTTest
|
||||
|
||||
@@ -157,11 +135,11 @@ rocprofiler_configure(uint32_t /* version */,
|
||||
ATTTest::Single::client_id = id;
|
||||
|
||||
// create configure data
|
||||
static auto cfg = rocprofiler_tool_configure_result_t{
|
||||
sizeof(rocprofiler_tool_configure_result_t),
|
||||
&ATTTest::Single::tool_init,
|
||||
&ATTTest::Single::tool_fini,
|
||||
reinterpret_cast<void*>(new Callbacks::ToolData{"att_single_test/"})};
|
||||
static auto cfg =
|
||||
rocprofiler_tool_configure_result_t{sizeof(rocprofiler_tool_configure_result_t),
|
||||
&ATTTest::Single::tool_init,
|
||||
&Callbacks::finalize,
|
||||
nullptr};
|
||||
|
||||
// return pointer to configure data
|
||||
return &cfg;
|
||||
|
||||
@@ -26,11 +26,6 @@
|
||||
#endif
|
||||
|
||||
#include "trace_callbacks.hpp"
|
||||
#include <rocprofiler-sdk/cxx/codeobj/code_printing.hpp>
|
||||
|
||||
#ifdef ENABLE_ATT_FILES
|
||||
# include <nlohmann/json.hpp>
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
#include <cassert>
|
||||
@@ -38,135 +33,78 @@
|
||||
|
||||
namespace Callbacks
|
||||
{
|
||||
using code_obj_load_data_t = rocprofiler_callback_tracing_code_object_load_data_t;
|
||||
using kernel_symbol_data_t = rocprofiler_callback_tracing_code_object_kernel_symbol_register_data_t;
|
||||
rocprofiler_thread_trace_decoder_id_t decoder{};
|
||||
std::atomic<size_t> latency{0};
|
||||
|
||||
void
|
||||
tool_codeobj_tracing_callback(rocprofiler_callback_tracing_record_t record,
|
||||
rocprofiler_user_data_t* /* user_data */,
|
||||
void* userdata)
|
||||
void* /* userdata */)
|
||||
{
|
||||
C_API_BEGIN
|
||||
if(record.kind != ROCPROFILER_CALLBACK_TRACING_CODE_OBJECT) return;
|
||||
if(record.phase != ROCPROFILER_CALLBACK_PHASE_LOAD) return;
|
||||
|
||||
assert(userdata && "Dispatch callback passed null!");
|
||||
auto& tool = *reinterpret_cast<Callbacks::ToolData*>(userdata);
|
||||
|
||||
if(record.operation == ROCPROFILER_CODE_OBJECT_DEVICE_KERNEL_SYMBOL_REGISTER)
|
||||
{
|
||||
auto* data = static_cast<kernel_symbol_data_t*>(record.payload);
|
||||
tool.kernel_id_to_kernel_name.emplace(data->kernel_id, data->kernel_name);
|
||||
}
|
||||
|
||||
if(record.operation != ROCPROFILER_CODE_OBJECT_LOAD) return;
|
||||
|
||||
auto* data = static_cast<code_obj_load_data_t*>(record.payload);
|
||||
auto* data = static_cast<rocprofiler_callback_tracing_code_object_load_data_t*>(record.payload);
|
||||
if(data->storage_type == ROCPROFILER_CODE_OBJECT_STORAGE_TYPE_FILE) return;
|
||||
|
||||
static std::atomic<int> filecnt{0};
|
||||
std::string name = "codeobj_" + std::to_string(filecnt.fetch_add(1)) + ".out";
|
||||
|
||||
#ifdef ENABLE_ATT_FILES
|
||||
if(std::string_view(data->uri).find("file:///") == 0)
|
||||
if(record.phase != ROCPROFILER_CALLBACK_PHASE_LOAD)
|
||||
{
|
||||
rocprofiler::sdk::codeobj::disassembly::CodeObjectBinary binary(data->uri);
|
||||
|
||||
std::ofstream file(tool.out_dir + name, std::ios::binary);
|
||||
assert(file.is_open() && "Could not open codeobj file for writing");
|
||||
file.write((char*) binary.buffer.data(), binary.buffer.size());
|
||||
DECODER_CALL(
|
||||
rocprofiler_thread_trace_decoder_codeobj_unload(decoder, data->code_object_id));
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::ofstream file(tool.out_dir + name, std::ios::binary);
|
||||
file.write((char*) data->memory_base, data->memory_size);
|
||||
}
|
||||
#endif
|
||||
|
||||
auto _lk = std::unique_lock{tool.mut};
|
||||
tool.codeobjs.push_back(
|
||||
{data->load_delta, data->load_size, data->code_object_id, name, data->uri});
|
||||
DECODER_CALL(rocprofiler_thread_trace_decoder_codeobj_load(
|
||||
decoder,
|
||||
data->code_object_id,
|
||||
data->load_delta,
|
||||
data->load_size,
|
||||
reinterpret_cast<const void*>(data->memory_base),
|
||||
data->memory_size));
|
||||
}
|
||||
|
||||
C_API_END
|
||||
typedef 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);
|
||||
|
||||
void
|
||||
shader_data_callback(rocprofiler_agent_id_t /* agent */,
|
||||
int64_t /* se_id */,
|
||||
void* se_data,
|
||||
size_t data_size,
|
||||
rocprofiler_user_data_t /* userdata */)
|
||||
{
|
||||
auto parse = [](rocprofiler_thread_trace_decoder_record_type_t record_type_id,
|
||||
void* trace_events,
|
||||
uint64_t trace_size,
|
||||
void* /* userdata */) {
|
||||
if(record_type_id != ROCPROFILER_THREAD_TRACE_DECODER_RECORD_WAVE) return;
|
||||
|
||||
for(size_t w = 0; w < trace_size; w++)
|
||||
{
|
||||
auto* wave = static_cast<rocprofiler_thread_trace_decoder_wave_t*>(trace_events);
|
||||
for(size_t i = 0; i < wave->instructions_size; i++)
|
||||
latency += wave->instructions_array[i].duration;
|
||||
}
|
||||
};
|
||||
DECODER_CALL(rocprofiler_trace_decode(decoder, parse, se_data, data_size, nullptr));
|
||||
}
|
||||
|
||||
void
|
||||
shader_data_callback(rocprofiler_agent_id_t agent,
|
||||
int64_t se_id,
|
||||
void* se_data,
|
||||
size_t data_size,
|
||||
rocprofiler_user_data_t userdata)
|
||||
init()
|
||||
{
|
||||
C_API_BEGIN
|
||||
|
||||
assert(userdata.ptr && "Dispatch callback passed null!");
|
||||
auto& tool = *reinterpret_cast<Callbacks::ToolData*>(userdata.ptr);
|
||||
|
||||
std::string name = "agent_" + std::to_string(agent.handle) + "_shader_engine_" +
|
||||
std::to_string(se_id) + "_" + std::to_string(agent.handle) + ".att";
|
||||
|
||||
#ifdef ENABLE_ATT_FILES
|
||||
{
|
||||
std::ofstream file(tool.out_dir + name, std::ios::binary);
|
||||
assert(file.is_open() && "Could not open ATT file for writing");
|
||||
file.write((char*) se_data, data_size);
|
||||
}
|
||||
#endif
|
||||
|
||||
assert(se_data);
|
||||
assert(data_size);
|
||||
|
||||
auto _lk = std::unique_lock{tool.mut};
|
||||
tool.att_files.push_back(name);
|
||||
|
||||
C_API_END
|
||||
// const char* decoder_lib = std::getenv("ROCPROF_TRACE_DECODER_PATH");
|
||||
DECODER_CALL(rocprofiler_thread_trace_decoder_create(&decoder, "/opt/rocm/lib"));
|
||||
}
|
||||
|
||||
void
|
||||
finalize_json(void* userdata)
|
||||
finalize(void* /* tool_data */)
|
||||
{
|
||||
assert(userdata && "Dispatch callback passed null!");
|
||||
rocprofiler_thread_trace_decoder_destroy(decoder);
|
||||
|
||||
auto& tool = *reinterpret_cast<Callbacks::ToolData*>(userdata);
|
||||
auto _lk = std::unique_lock{tool.mut};
|
||||
assert(!tool.att_files.empty());
|
||||
|
||||
#ifdef ENABLE_ATT_FILES
|
||||
nlohmann::json att_json;
|
||||
for(auto& file : tool.att_files)
|
||||
att_json.push_back(file);
|
||||
|
||||
nlohmann::json codeobj_json;
|
||||
nlohmann::json snapshot_json;
|
||||
for(auto& file : tool.codeobjs)
|
||||
{
|
||||
nlohmann::json codeobj;
|
||||
codeobj["code_object_id"] = file.id;
|
||||
codeobj["load_delta"] = file.addr;
|
||||
codeobj["load_size"] = file.size;
|
||||
codeobj["uri"] = file.uri;
|
||||
codeobj["filename"] = file.filename;
|
||||
codeobj_json.push_back(codeobj);
|
||||
|
||||
nlohmann::json pair_json;
|
||||
pair_json["key"] = file.id;
|
||||
pair_json["value"] = file.filename;
|
||||
snapshot_json.push_back(pair_json);
|
||||
}
|
||||
nlohmann::json tool_json;
|
||||
tool_json["strings"]["att_files"] = att_json;
|
||||
tool_json["code_objects"] = codeobj_json;
|
||||
tool_json["strings"]["code_object_snapshot_files"] = snapshot_json;
|
||||
|
||||
nlohmann::json array;
|
||||
array.push_back(tool_json);
|
||||
|
||||
nlohmann::json sdk_json;
|
||||
sdk_json["rocprofiler-sdk-tool"] = array;
|
||||
|
||||
std::ofstream json_file(tool.out_dir + (std::to_string(getpid()) + "_results.json"));
|
||||
assert(json_file.is_open() && "Could not open json file for writing!");
|
||||
json_file << sdk_json;
|
||||
#endif
|
||||
if(latency.load() == 0) std::cerr << "Error: No latency was assigned to the trace!";
|
||||
}
|
||||
|
||||
} // namespace Callbacks
|
||||
|
||||
@@ -40,60 +40,21 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#define ROCPROFILER_VAR_NAME_COMBINE(X, Y) X##Y
|
||||
#define ROCPROFILER_VARIABLE(X, Y) ROCPROFILER_VAR_NAME_COMBINE(X, Y)
|
||||
|
||||
#define C_API_BEGIN \
|
||||
try \
|
||||
{
|
||||
#define C_API_END \
|
||||
} \
|
||||
catch(std::exception & e) \
|
||||
{ \
|
||||
std::cerr << "Error in " << __FILE__ << ':' << __LINE__ << ' ' << e.what() << std::endl; \
|
||||
} \
|
||||
catch(...) { std::cerr << "Error in " << __FILE__ << ':' << __LINE__ << std::endl; }
|
||||
|
||||
#define ROCPROFILER_CALL(result, msg) \
|
||||
if((result) != ROCPROFILER_STATUS_SUCCESS) \
|
||||
{ \
|
||||
rocprofiler_status_t CHECKSTATUS = result; \
|
||||
if(CHECKSTATUS != ROCPROFILER_STATUS_SUCCESS) \
|
||||
{ \
|
||||
std::string status_msg = rocprofiler_get_status_string(CHECKSTATUS); \
|
||||
std::cerr << "[" #result "][" << __FILE__ << ":" << __LINE__ << "] " << msg \
|
||||
<< " failed with error code " << CHECKSTATUS << ": " << status_msg \
|
||||
<< std::endl; \
|
||||
std::stringstream errmsg{}; \
|
||||
errmsg << "[" #result "][" << __FILE__ << ":" << __LINE__ << "] " << msg " failure (" \
|
||||
<< status_msg << ")"; \
|
||||
throw std::runtime_error(errmsg.str()); \
|
||||
} \
|
||||
std::cerr << "Error: " << msg << std::endl; \
|
||||
abort(); \
|
||||
}
|
||||
|
||||
#define DECODER_CALL(result) \
|
||||
if((result) != ROCPROFILER_STATUS_SUCCESS) \
|
||||
{ \
|
||||
std::cerr << "Error: Generic decoder error" << std::endl; \
|
||||
}
|
||||
|
||||
namespace Callbacks
|
||||
{
|
||||
struct CodeobjInfo
|
||||
{
|
||||
int64_t addr = 0;
|
||||
size_t size = 0;
|
||||
size_t id = 0;
|
||||
std::string filename{};
|
||||
std::string uri{};
|
||||
};
|
||||
|
||||
struct ToolData
|
||||
{
|
||||
ToolData(const char* out)
|
||||
: out_dir(out){};
|
||||
|
||||
std::string out_dir{};
|
||||
std::mutex mut{};
|
||||
std::vector<CodeobjInfo> codeobjs{};
|
||||
std::vector<std::string> att_files{};
|
||||
|
||||
std::unordered_map<uint64_t, std::string> kernel_id_to_kernel_name = {};
|
||||
};
|
||||
|
||||
void
|
||||
tool_codeobj_tracing_callback(rocprofiler_callback_tracing_record_t record,
|
||||
rocprofiler_user_data_t*,
|
||||
@@ -107,6 +68,9 @@ shader_data_callback(rocprofiler_agent_id_t agent,
|
||||
rocprofiler_user_data_t userdata);
|
||||
|
||||
void
|
||||
finalize_json(void* userdata);
|
||||
init();
|
||||
|
||||
void
|
||||
finalize(void* /* tool_data */);
|
||||
|
||||
} // namespace Callbacks
|
||||
|
||||
Reference in New Issue
Block a user