Skip to content

Commit

Permalink
Use fixed size array for serialization (#906)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Welton <ben@amd.com>
  • Loading branch information
bwelton and Benjamin Welton authored Jun 5, 2024
1 parent b0c4182 commit 2f3a8b0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
4 changes: 3 additions & 1 deletion source/lib/rocprofiler-sdk-tool/generateCSV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <rocprofiler-sdk/marker/api_id.h>
#include <unistd.h>

#include <cstdint>
#include <iomanip>
#include <string_view>
#include <utility>
Expand Down Expand Up @@ -553,8 +554,9 @@ generate_csv(tool_table* too
{
auto kernel_id = record.dispatch_data.dispatch_info.kernel_id;
auto counter_name_value = std::map<std::string, uint64_t>{};
for(const auto& count : record.records)
for(uint64_t i = 0; i < record.counter_count; i++)
{
const auto& count = record.records.at(i);
auto rec = count.record_counter;
std::string counter_name = tool_functions->tool_get_counter_info_name_fn(rec.id);
auto search = counter_name_value.find(counter_name);
Expand Down
19 changes: 12 additions & 7 deletions source/lib/rocprofiler-sdk-tool/helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <rocprofiler-sdk/fwd.h>
#include <rocprofiler-sdk/registration.h>
#include <rocprofiler-sdk/rocprofiler.h>
#include <cstdint>
#include <rocprofiler-sdk/cxx/name_info.hpp>
#include <rocprofiler-sdk/cxx/serialization.hpp>

Expand Down Expand Up @@ -270,18 +271,22 @@ struct rocprofiler_tool_record_counter_t

struct rocprofiler_tool_counter_collection_record_t
{
rocprofiler_profile_counting_dispatch_data_t dispatch_data = {};
std::vector<rocprofiler_tool_record_counter_t> records = {};
uint64_t thread_id = 0;
uint64_t arch_vgpr_count = 0;
uint64_t sgpr_count = 0;
uint64_t lds_block_size_v = 0;
rocprofiler_profile_counting_dispatch_data_t dispatch_data = {};
std::array<rocprofiler_tool_record_counter_t, 256> records = {};
uint64_t thread_id = 0;
uint64_t arch_vgpr_count = 0;
uint64_t sgpr_count = 0;
uint64_t lds_block_size_v = 0;
uint64_t counter_count = 0;

template <typename ArchiveT>
void save(ArchiveT& ar) const
{
ar(cereal::make_nvp("dispatch_data", dispatch_data));
ar(cereal::make_nvp("records", records));
// should be removed when moving to buffered tracing
std::vector<rocprofiler_tool_record_counter_t> tmp{records.begin(),
records.begin() + counter_count};
ar(cereal::make_nvp("records", tmp));
ar(cereal::make_nvp("thread_id", thread_id));
ar(cereal::make_nvp("arch_vgpr_count", arch_vgpr_count));
ar(cereal::make_nvp("sgpr_count", sgpr_count));
Expand Down
12 changes: 10 additions & 2 deletions source/lib/rocprofiler-sdk-tool/tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,11 +941,19 @@ counter_record_callback(rocprofiler_profile_counting_dispatch_data_t dispatch_da

for(size_t count = 0; count < record_count; count++)
{
// Unlikely to trigger, temporary until we move to buffered callbacks
if(count >= counter_record.records.size())
{
ROCP_WARNING << "Exceeded maximum counter capacity, skipping remaining";
break;
}

auto _counter_id = rocprofiler_counter_id_t{};
ROCPROFILER_CALL(rocprofiler_query_record_counter_id(record_data[count].id, &_counter_id),
"query record counter id");
counter_record.records.emplace_back(
rocprofiler_tool_record_counter_t{_counter_id, record_data[count]});
counter_record.records[count] =
rocprofiler_tool_record_counter_t{_counter_id, record_data[count]};
counter_record.counter_count++;
}

write_ring_buffer(counter_record, domain_type::COUNTER_COLLECTION);
Expand Down
2 changes: 1 addition & 1 deletion tests/counter-collection/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_counter_values(input_data):
counter_data = data["buffer_records"]["counter_collection"]

for itr in counter_info:
if itr["is_constant"] == 1 and itr["name"] == "size":
if itr["is_constant"] == 1:
continue
assert itr["id"]["handle"] > 0, f"{itr}"
assert itr["is_constant"] in (0, 1), f"{itr}"
Expand Down

0 comments on commit 2f3a8b0

Please sign in to comment.