From 78939e705aee866b85a51283aaf0e7993f18d149 Mon Sep 17 00:00:00 2001 From: Vladimir Indic <139573562+vlaindic@users.noreply.github.com> Date: Fri, 15 Mar 2024 20:04:06 +0100 Subject: [PATCH] PCS parser is aware of external correlation IDs (#639) * PCS parser is aware of external correlation IDs * source formatting (clang-format v11) (#640) Co-authored-by: vlaindic <139573562+vlaindic@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../pc_sampling/parser/correlation.hpp | 14 +++++++++----- .../pc_sampling/parser/parser_types.h | 8 +++++--- .../pc_sampling/parser/pc_record_interface.cpp | 2 +- .../pc_sampling/parser/pc_record_interface.hpp | 1 + .../lib/rocprofiler-sdk/pc_sampling/parser/rocr.h | 7 +++++-- .../parser/tests/correlation_id_test.cpp | 2 +- .../pc_sampling/parser/tests/gfx9test.cpp | 14 +++++++------- .../pc_sampling/parser/tests/mocks.hpp | 12 ++++++------ 8 files changed, 35 insertions(+), 25 deletions(-) diff --git a/source/lib/rocprofiler-sdk/pc_sampling/parser/correlation.hpp b/source/lib/rocprofiler-sdk/pc_sampling/parser/correlation.hpp index 8669e04ad2..f3339e9dcd 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/parser/correlation.hpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/parser/correlation.hpp @@ -22,6 +22,8 @@ #pragma once +#include + #include #include #include @@ -133,7 +135,7 @@ public: * Given a device dev, doorbell and and wrapped dispatch_id, * @returns the correlation_id set by dispatch_pkt_id_t */ - uint64_t get(device_handle dev, trap_correlation_id_t correlation_in) + rocprofiler_correlation_id_t get(device_handle dev, trap_correlation_id_t correlation_in) { #ifndef _PARSER_CORRELATION_DISABLE_CACHE if(dev.handle == cache_dev_id && correlation_in == cache_correlation_id_in) @@ -166,12 +168,14 @@ public: } private: - std::unordered_map dispatch_to_correlation{}; + std::unordered_map dispatch_to_correlation{}; // Making get() const and these cache variables mutable causes performance to be unstable - trap_correlation_id_t cache_correlation_id_in{.raw = ~0ul}; // Invalid value in cache - uint64_t cache_correlation_id_out = ~0ul; - uint64_t cache_dev_id = ~0ul; // Invalid device Id in cache + trap_correlation_id_t cache_correlation_id_in{.raw = ~0ul}; // Invalid value in cache + rocprofiler_correlation_id_t cache_correlation_id_out{ + .internal = ~0ul, + .external = rocprofiler_user_data_t{.value = ~0ul}}; + uint64_t cache_dev_id = ~0ul; // Invalid device Id in cache }; } // namespace Parser diff --git a/source/lib/rocprofiler-sdk/pc_sampling/parser/parser_types.h b/source/lib/rocprofiler-sdk/pc_sampling/parser/parser_types.h index 5542c9567a..9b087a334f 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/parser/parser_types.h +++ b/source/lib/rocprofiler-sdk/pc_sampling/parser/parser_types.h @@ -22,6 +22,8 @@ #pragma once +#include + /** * ######## Parser Definitions ######## */ @@ -130,9 +132,9 @@ typedef struct uint32_t workgroup_id_y; uint32_t workgroup_id_z; - uint32_t wave_count; - uint64_t timestamp; - uint64_t correlation_id; + uint32_t wave_count; + uint64_t timestamp; + rocprofiler_correlation_id_t correlation_id; pcsample_snapshot_v1_t snapshot; 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 fc4e824403..4a39865d4e 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 @@ -61,7 +61,7 @@ PCSamplingParserContext::newDispatch(const dispatch_pkt_id_t& pkt) { std::unique_lock lock(mut); corr_map->newDispatch(pkt); - active_dispatches[pkt.correlation_id] = pkt; + active_dispatches[pkt.correlation_id.internal] = pkt; } void 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 b68e126cfb..41de7fe447 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 @@ -148,6 +148,7 @@ protected: //! Data allocated to store samples. Temporary. std::vector> data; //! Dispatches not yet completed. + // Uses only the internal correlation_id. std::unordered_map active_dispatches; //! List of correlation ids whose dispatches have been completed and can be forgotten after the //! buffer flip. diff --git a/source/lib/rocprofiler-sdk/pc_sampling/parser/rocr.h b/source/lib/rocprofiler-sdk/pc_sampling/parser/rocr.h index caad7fd341..b396b40669 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/parser/rocr.h +++ b/source/lib/rocprofiler-sdk/pc_sampling/parser/rocr.h @@ -22,6 +22,8 @@ #pragma once +#include + #include /** @@ -69,8 +71,9 @@ typedef struct uint64_t queue_size; uint64_t write_index; uint64_t read_index; - uint64_t correlation_id; - reserved_type _[4]; + /// both internal and external correlation ID. + rocprofiler_correlation_id_t correlation_id; + reserved_type _[2]; } dispatch_pkt_id_t; typedef struct 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 663d9367b8..28ffb61d60 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 @@ -52,7 +52,7 @@ static bool check_samples(pcsample_v1_t* samples, uint64_t size) { for(size_t i = 0; i < size; i++) - if(samples[i].correlation_id != samples[i].pc) return false; + if(samples[i].correlation_id.internal != samples[i].pc) return false; return true; } 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 8c85971b44..49ab68fee0 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/gfx9test.cpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/gfx9test.cpp @@ -296,8 +296,8 @@ class WaveIssueAndErrorTest : public WaveSnapTest { pcsample_v1_t sample; ::memset(&sample, 0, sizeof(sample)); - sample.pc = dispatch->unique_id; - sample.correlation_id = dispatch->getMockId().raw; + sample.pc = dispatch->unique_id; + sample.correlation_id.internal = dispatch->getMockId().raw; sample.flags.valid = valid && !error; sample.wave_issued = issued; @@ -353,7 +353,7 @@ class WaveOtherFieldsTest : public WaveSnapTest assert(compare[i].chiplet == parsed[0][i].chiplet); assert(compare[i].wave_id == parsed[0][i].wave_id); assert(compare[i].hw_id == parsed[0][i].hw_id); - assert(compare[i].correlation_id == parsed[0][i].correlation_id); + assert(compare[i].correlation_id.internal == parsed[0][i].correlation_id.internal); } } @@ -367,10 +367,10 @@ class WaveOtherFieldsTest : public WaveSnapTest sample.workgroup_id_y = blky; sample.workgroup_id_z = blkz; - sample.chiplet = chip; - sample.wave_id = wave; - sample.hw_id = hwid; - sample.correlation_id = dispatch->unique_id; + sample.chiplet = chip; + sample.wave_id = wave; + sample.hw_id = hwid; + sample.correlation_id.internal = dispatch->unique_id; compare.push_back(sample); 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 d56f434665..a7fc6c83aa 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/mocks.hpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/parser/tests/mocks.hpp @@ -188,12 +188,12 @@ public: packet_union_t uni; ::memset(&uni, 0, sizeof(uni)); - uni.dispatch_id.type = AMD_DISPATCH_PKT_ID; - uni.dispatch_id.doorbell_id = doorbell_id; - uni.dispatch_id.queue_size = queue->size; - uni.dispatch_id.write_index = dispatch_id; - uni.dispatch_id.read_index = queue->read_index; - uni.dispatch_id.correlation_id = unique_id; + uni.dispatch_id.type = AMD_DISPATCH_PKT_ID; + uni.dispatch_id.doorbell_id = doorbell_id; + uni.dispatch_id.queue_size = queue->size; + uni.dispatch_id.write_index = dispatch_id; + uni.dispatch_id.read_index = queue->read_index; + uni.dispatch_id.correlation_id.internal = unique_id; queue->submit(uni); queue->write_index++; };