From 200be03bb47a8e2fd69818ff187021b207c8622f Mon Sep 17 00:00:00 2001 From: Vladimir Indic <139573562+vlaindic@users.noreply.github.com> Date: Fri, 8 Dec 2023 17:36:32 +0100 Subject: [PATCH] pcs parser: includes fixed, GLOB removed (#286) * pcs parser: includes fixed, GLOB removed * source formatting (clang-format v11) (#287) Co-authored-by: vlaindic * cmake formatting (cmake-format) (#288) Co-authored-by: vlaindic --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: vlaindic --- .../pc_sampling/parser/CMakeLists.txt | 4 +- .../pc_sampling/parser/correlation.cpp | 142 ------------------ .../pc_sampling/parser/correlation.hpp | 2 +- .../parser/pc_record_interface.cpp | 2 +- .../parser/pc_record_interface.hpp | 4 +- .../pc_sampling/parser/tests/CMakeLists.txt | 18 ++- .../parser/tests/benchmark_test.cpp | 2 +- .../parser/tests/correlation_id_test.cpp | 4 +- .../pc_sampling/parser/tests/gfx9test.cpp | 4 +- .../pc_sampling/parser/tests/mocks.hpp | 2 +- .../pc_sampling/parser/translation.cpp | 113 -------------- .../pc_sampling/parser/translation.hpp | 10 +- 12 files changed, 31 insertions(+), 276 deletions(-) delete mode 100644 source/lib/rocprofiler-sdk/pc_sampling/parser/correlation.cpp delete mode 100644 source/lib/rocprofiler-sdk/pc_sampling/parser/translation.cpp diff --git a/source/lib/rocprofiler-sdk/pc_sampling/parser/CMakeLists.txt b/source/lib/rocprofiler-sdk/pc_sampling/parser/CMakeLists.txt index 5dc9f77271..87ec7533be 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/parser/CMakeLists.txt +++ b/source/lib/rocprofiler-sdk/pc_sampling/parser/CMakeLists.txt @@ -1,5 +1,7 @@ set(ROCPROFILER_LIB_PC_SAMPLING_PARSER_SOURCES pc_record_interface.cpp) -file(GLOB ROCPROFILER_LIB_PC_SAMPLING_PARSER_HEADERS *.h *.hpp) +set(ROCPROFILER_LIB_PC_SAMPLING_PARSER_HEADERS + correlation.hpp gfx9.hpp gfx11.hpp gfx_unknown.hpp parser_types.h pc_record_interface.hpp + rocr.h translation.hpp) target_sources( rocprofiler-object-library PRIVATE ${ROCPROFILER_LIB_PC_SAMPLING_PARSER_SOURCES} diff --git a/source/lib/rocprofiler-sdk/pc_sampling/parser/correlation.cpp b/source/lib/rocprofiler-sdk/pc_sampling/parser/correlation.cpp deleted file mode 100644 index 45db722a55..0000000000 --- a/source/lib/rocprofiler-sdk/pc_sampling/parser/correlation.cpp +++ /dev/null @@ -1,142 +0,0 @@ -// MIT License -// -// Copyright (c) 2023 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. - -#include "correlation.hpp" - -template <> -struct std::hash -{ - size_t operator()(const device_handle& d) const { return d.handle; } -}; -bool -operator==(device_handle a, device_handle b) -{ - return a.handle == b.handle; -} - -namespace Parser -{ -bool -operator==(const DispatchPkt& a, const DispatchPkt& b) -{ - return a.correlation_id_in == b.correlation_id_in && a.dev == b.dev; -} -} // namespace Parser - -namespace Parser -{ -/** - * Coordinates DispatchMap and DoorBellMap to reconstruct the original correlation_id - * from the correlation_id seen by the trap handler. - */ - -/** - * Checks wether a dispatch pkt will generate a collision. - * Returns true on collision and false when slot is available. - */ -bool -CorrelationMap::checkDispatch(const dispatch_pkt_id_t& pkt) const -{ - uint64_t trap = wrap_correlation_id(pkt.doorbell_id, pkt.write_index, pkt.queue_size); - return dispatch_to_correlation.find({trap, pkt.device}) != dispatch_to_correlation.end(); -} - -/** - * Updates the mapping of dispatch_id to correlation_id - */ -void -CorrelationMap::newDispatch(const dispatch_pkt_id_t& pkt) -{ - cache_dev_id = ~0ul; - uint64_t trap_id = wrap_correlation_id(pkt.doorbell_id, pkt.write_index, pkt.queue_size); - dispatch_to_correlation[{trap_id, pkt.device}] = pkt.correlation_id; -} - -void -CorrelationMap::forget(const dispatch_pkt_id_t& pkt) -{ - cache_dev_id = ~0ul; - uint64_t trap_id = wrap_correlation_id(pkt.doorbell_id, pkt.write_index, pkt.queue_size); - dispatch_to_correlation.erase({trap_id, pkt.device}); -} - -/** - * Given a device dev, doorbell and and wrapped dispatch_id, returns the - * correlation_id set by dispatch_pkt_id_t - */ -uint64_t -CorrelationMap::get(device_handle dev, uint64_t correlation_in) -{ -#ifndef _PARSER_CORRELATION_DISABLE_CACHE - if(dev.handle == cache_dev_id && correlation_in == cache_correlation_id_in) - return cache_correlation_id_out; -#endif - cache_dev_id = dev.handle; - cache_correlation_id_in = correlation_in; - cache_correlation_id_out = dispatch_to_correlation.at({correlation_in, dev}); - return cache_correlation_id_out; -} - -uint64_t -CorrelationMap::wrap_correlation_id(uint64_t doorbell, uint64_t write_idx, uint64_t queue_size) -{ - static constexpr uint64_t WRITE_WRAP = (1 << 25) - 1; - return ((write_idx % queue_size) & WRITE_WRAP) | (uint64_t(doorbell) << 32); -} - -} // namespace Parser - -/** - * @brief Parses a given set of pc samples. - * @param[in] buffer Pointer to a buffer containing metadata and pcsamples. - * @param[in] buffer_size The number of elements in the buffer. - * @param[in] gfxip_major GFXIP major version of the samples. - * @param[in] callback A callback function that accepts a double pointer to write the samples to, - * a size requested parameter (number of pc_sample_t) and a void* to userdata. - * The callback is expected to allocate 64B-aligned memory where the parsed samples are going to - * be written to, and return the size of memory that was allocated, in multiples of - * sizeof(generic_sample_t). If the callback returns 0 or a larger size than requested, - * parse_buffer() will return PCSAMPLE_STATUS_CALLBACK_ERROR. If the callback returns - * a size smaller than requested, then it may be called again requesting more memory. - * @param[in] userdata parameter forwarded to the user callback. - */ -pcsample_status_t -parse_buffer(generic_sample_t* buffer, - uint64_t buffer_size, - int gfxip_major, - user_callback_t callback, - void* userdata) -{ - static auto corr_map = std::make_unique(); - - auto parseSample_func = _parse_buffer; - if(gfxip_major == 9) - parseSample_func = _parse_buffer; - else if(gfxip_major == 11) - parseSample_func = _parse_buffer; - else if(gfxip_major == 0) - parseSample_func = _parse_buffer; - else - return PCSAMPLE_STATUS_INVALID_GFXIP; - - return parseSample_func(buffer, buffer_size, callback, userdata, corr_map.get()); -}; diff --git a/source/lib/rocprofiler-sdk/pc_sampling/parser/correlation.hpp b/source/lib/rocprofiler-sdk/pc_sampling/parser/correlation.hpp index 3270b63c68..12781de423 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/parser/correlation.hpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/parser/correlation.hpp @@ -28,7 +28,7 @@ #include #include -#include "translation.hpp" +#include "lib/rocprofiler-sdk/pc_sampling/parser/translation.hpp" template <> struct std::hash diff --git a/source/lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.cpp b/source/lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.cpp index 1259cc96f8..fc4e824403 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.cpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "pc_record_interface.hpp" +#include "lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp" uint64_t PCSamplingParserContext::alloc(pcsample_v1_t** buffer, uint64_t size) diff --git a/source/lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp b/source/lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp index 1cddb80935..b68e126cfb 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp @@ -29,8 +29,8 @@ #include #include -#include "correlation.hpp" -#include "parser_types.h" +#include "lib/rocprofiler-sdk/pc_sampling/parser/correlation.hpp" +#include "lib/rocprofiler-sdk/pc_sampling/parser/parser_types.h" struct PCSamplingData { diff --git a/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/CMakeLists.txt b/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/CMakeLists.txt index 00f34961ab..401c7c08ec 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/CMakeLists.txt +++ b/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/CMakeLists.txt @@ -8,8 +8,7 @@ set(PCTEST_INCLUDE_DIR set(ROCPROFILER_LIB_PC_SAMPLING_PARSER_ID_TEST_SOURCES correlation_id_test.cpp) set(ROCPROFILER_LIB_PC_SAMPLING_PARSER_BENCH_TEST_SOURCES benchmark_test.cpp) set(ROCPROFILER_LIB_PC_SAMPLING_PARSER_GFX9_TEST_SOURCES gfx9test.cpp) -file(GLOB ROCPROFILER_LIB_PC_SAMPLING_PARSER_TEST_HEADERS mocks.hpp - ${ROCPROFILER_LIB_PC_SAMPLING_PARSER_HEADERS}) +set(ROCPROFILER_LIB_PC_SAMPLING_PARSER_TEST_HEADERS mocks.hpp) add_executable(pcs_gfx9_test) @@ -17,7 +16,10 @@ target_sources(pcs_gfx9_test PRIVATE ${ROCPROFILER_LIB_PC_SAMPLING_PARSER_GFX9_TEST_SOURCES}) target_include_directories(pcs_gfx9_test PRIVATE ${PCTEST_INCLUDE_DIR}) -target_link_libraries(pcs_gfx9_test PRIVATE GTest::gtest GTest::gtest_main) +target_link_libraries( + pcs_gfx9_test + PRIVATE rocprofiler::rocprofiler-common-library + rocprofiler::rocprofiler-static-library GTest::gtest GTest::gtest_main) gtest_add_tests( TARGET pcs_gfx9_test @@ -32,7 +34,10 @@ add_executable(pcs_id_test) target_sources(pcs_id_test PRIVATE ${ROCPROFILER_LIB_PC_SAMPLING_PARSER_ID_TEST_SOURCES}) target_include_directories(pcs_id_test PRIVATE ${PCTEST_INCLUDE_DIR}) -target_link_libraries(pcs_id_test PRIVATE GTest::gtest GTest::gtest_main) +target_link_libraries( + pcs_id_test + PRIVATE rocprofiler::rocprofiler-common-library + rocprofiler::rocprofiler-static-library GTest::gtest GTest::gtest_main) gtest_add_tests( TARGET pcs_id_test @@ -49,4 +54,7 @@ target_sources(pcs_bench_test PRIVATE ${ROCPROFILER_LIB_PC_SAMPLING_PARSER_BENCH_TEST_SOURCES}) target_include_directories(pcs_bench_test PRIVATE ${PCTEST_INCLUDE_DIR}) -target_link_libraries(pcs_bench_test PRIVATE GTest::gtest GTest::gtest_main) +target_link_libraries( + pcs_bench_test + PRIVATE rocprofiler::rocprofiler-common-library + rocprofiler::rocprofiler-static-library GTest::gtest GTest::gtest_main) diff --git a/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/benchmark_test.cpp b/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/benchmark_test.cpp index 34d9131396..52288beb52 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/benchmark_test.cpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/benchmark_test.cpp @@ -23,7 +23,7 @@ #include #include -#include "mocks.hpp" +#include "lib/rocprofiler-sdk/pc_sampling/parser/tests/mocks.hpp" #define GFXIP_MAJOR 9 diff --git a/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/correlation_id_test.cpp b/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/correlation_id_test.cpp index 1245e64986..663d9367b8 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/correlation_id_test.cpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/correlation_id_test.cpp @@ -23,8 +23,8 @@ #include #include -#include "mocks.hpp" -#include "pc_record_interface.hpp" +#include "lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp" +#include "lib/rocprofiler-sdk/pc_sampling/parser/tests/mocks.hpp" #define GFXIP_MAJOR 9 diff --git a/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/gfx9test.cpp b/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/gfx9test.cpp index 98a2c9a09c..044572e112 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/gfx9test.cpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/gfx9test.cpp @@ -28,8 +28,8 @@ #include #include -#include "mocks.hpp" -#include "pc_record_interface.hpp" +#include "lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp" +#include "lib/rocprofiler-sdk/pc_sampling/parser/tests/mocks.hpp" #define GFXIP_MAJOR 9 diff --git a/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/mocks.hpp b/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/mocks.hpp index 77c25de236..70cf5044d5 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/mocks.hpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/mocks.hpp @@ -31,7 +31,7 @@ #include #include -#include "correlation.hpp" +#include "lib/rocprofiler-sdk/pc_sampling/parser/correlation.hpp" #define CHECK_PARSER(x) \ { \ diff --git a/source/lib/rocprofiler-sdk/pc_sampling/parser/translation.cpp b/source/lib/rocprofiler-sdk/pc_sampling/parser/translation.cpp deleted file mode 100644 index 43ccc6307f..0000000000 --- a/source/lib/rocprofiler-sdk/pc_sampling/parser/translation.cpp +++ /dev/null @@ -1,113 +0,0 @@ -// MIT License -// -// Copyright (c) 2023 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. - -#include "lib/rocprofiler-sdk/pc_sampling/parser/translation.hpp" - -pcsample_v1_t -copyHostTrapSample(const perf_sample_host_trap_v1& sample) -{ - pcsample_v1_t ret = PCSParserTranslation::copySampleHeader(sample); - ret.flags.type = AMD_HOST_TRAP_V1; - return ret; -} - -template -pcsample_v1_t -PCSParserTranslation::copySampleHeader(const SType& sample) -{ - pcsample_v1_t ret; - ret.flags.type = AMD_SNAPSHOT_V1; - - ret.pc = sample.pc; - ret.exec_mask = sample.exec_mask; - ret.workgroup_id_x = sample.workgroup_id_x; - ret.workgroup_id_y = sample.workgroup_id_y; - ret.workgroup_id_z = sample.workgroup_id_z; - - ret.chiplet = sample.chiplet_and_wave_id >> 8; - ret.wave_id = sample.chiplet_and_wave_id & 0x3F; - ret.hw_id = sample.hw_id; - ret.timestamp = sample.timestamp; - return ret; -} - -template -pcsample_v1_t -PCSParserTranslation::copyStochasticSample(const perf_sample_snapshot_v1& sample) -{ - (void) sample; - return {}; -}; - -template <> -pcsample_v1_t -PCSParserTranslation::copyStochasticSample(const perf_sample_snapshot_v1& sample) -{ - pcsample_v1_t ret = copySampleHeader(sample); - ret.flags.valid = sample.perf_snapshot_data & (~sample.perf_snapshot_data >> 26) & 0x1; - // Check wave_id matches snapshot_wave_id - - ret.flags.has_wave_cnt = true; - ret.flags.has_stall_reason = true; - - ret.wave_count = sample.perf_snapshot_data1 & 0x3F; - - ret.wave_issued = sample.perf_snapshot_data >> 1; - ret.snapshot.dual_issue_valu = sample.perf_snapshot_data >> 2; - ret.snapshot.inst_type = sample.perf_snapshot_data >> 3; - ret.snapshot.reason_not_issued = (sample.perf_snapshot_data >> 7) & 0x7; - ret.snapshot.arb_state_issue = (sample.perf_snapshot_data >> 10) & 0xFF; - ret.snapshot.arb_state_stall = (sample.perf_snapshot_data >> 18) & 0xFF; - return ret; -} - -template <> -pcsample_v1_t -PCSParserTranslation::copyStochasticSample(const perf_sample_snapshot_v1& sample) -{ - // TODO: finish this - return copySampleHeader(sample); -} - -template <> -pcsample_v1_t -PCSParserTranslation::copyStochasticSample(const perf_sample_snapshot_v1& sample) -{ - pcsample_v1_t ret = copySampleHeader(sample); - ret.flags.valid = sample.perf_snapshot_data & 0x1; - // Check wave_id matches snapshot_wave_id - - ret.flags.has_wave_cnt = true; - ret.flags.has_stall_reason = true; - - ret.wave_issued = sample.perf_snapshot_data >> 1; - ret.snapshot.inst_type = sample.perf_snapshot_data >> 2; - ret.snapshot.reason_not_issued = (sample.perf_snapshot_data >> 6) & 0x7; - - ret.wave_count = sample.perf_snapshot_data1 & 0x3F; - ret.snapshot.arb_state_issue = (sample.perf_snapshot_data1 >> 6) & 0xFF; - ret.snapshot.arb_state_stall = (sample.perf_snapshot_data1 >> 14) & 0xFF; - - ret.flags.has_memory_counter = true; - ret.memory_counters.raw = sample.perf_snapshot_data2; - return ret; -} diff --git a/source/lib/rocprofiler-sdk/pc_sampling/parser/translation.hpp b/source/lib/rocprofiler-sdk/pc_sampling/parser/translation.hpp index 133856ba49..f81857a044 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/parser/translation.hpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/parser/translation.hpp @@ -26,11 +26,11 @@ #include #include -#include "gfx11.hpp" -#include "gfx_unknown.hpp" -#include "gfx9.hpp" -#include "parser_types.h" -#include "rocr.h" +#include "lib/rocprofiler-sdk/pc_sampling/parser/gfx11.hpp" +#include "lib/rocprofiler-sdk/pc_sampling/parser/gfx_unknown.hpp" +#include "lib/rocprofiler-sdk/pc_sampling/parser/gfx9.hpp" +#include "lib/rocprofiler-sdk/pc_sampling/parser/parser_types.h" +#include "lib/rocprofiler-sdk/pc_sampling/parser/rocr.h" template inline pcsample_v1_t