[SDK] Expose counter dims in rocprofiler_counter_info_v1_t and only show counters being profiled in metadata. (#325)

* expose dimensional info in rocprofiler_counter_info_v1_t.

* add counter_id in dim info.

* address review comments

* format.

* address comments.

* use array of pointers for dimensions_instaces.

* format and comments.

* address comments.

* new line.

* Update counter_defs.yaml

* Update counter_defs.yaml

* Update counter_defs.yaml

* counter_defs.

* format counter defs.

* format counter defs.

* format counter defs.

* show only counters being profiled in metadata.

* Format.

* use config for counters and fix warnings.

* add version for rocprofiler_counter_dimension_info_v1_t struct.

* rename rocprofiler_counter_record_dimension_instance_v1_info_t.

* account device id from pmc for counters metadata.

* move dim structs to counters.h.

* address comments to compare value.

* fix tests.

* Address comments. use pointer of arrays for ABI.

* rebase.

* fix build error.

* use separate metadata::init() for rocprofv3.

* also print not found counters.

* precompute all the perf counters needed to be in metadata.

* Misc.

* format

* Format.

* rocprofiler::sdk::container::c_array

* Address comments.

* source/lib/output/metadata.cpp

* lint.

* add unit test for c_array.

* add unit test and serialization support for c_array container.

* Misc.

* Clean files.

* Format.

* clang-tidy.

* add more checks to c_array.

* misc. typo

* Addr comments.

---------

Co-authored-by: Venkateshwar Reddy Kandula <vkandula@amd.com>
Co-authored-by: Jonathan R. Madsen <Jonathan.Madsen@amd.com>

[ROCm/rocprofiler-sdk commit: bf0fad1d54]
This commit is contained in:
Kandula, Venkateshwar reddy
2025-07-22 16:24:25 -05:00
committad av GitHub
förälder b88018d24d
incheckning 0ff0ffffa2
19 ändrade filer med 796 tillägg och 103 borttagningar
@@ -1128,6 +1128,7 @@ construct_counter_collection_profile(rocprofiler_agent_id_t agent_id,
auto profile = std::optional<rocprofiler_counter_config_id_t>{};
auto counters_v = counter_vec_t{};
auto found_v = std::vector<std::string_view>{};
auto not_found_counters_v = std::vector<std::string_view>{};
const auto* agent_v = tool_metadata->get_agent(agent_id);
auto expected_v = counters.size();
@@ -1158,24 +1159,31 @@ construct_counter_collection_profile(rocprofiler_agent_id_t agent_id,
}
// search the gpu agent counter info for a counter with a matching name
bool counter_found = false;
for(const auto& citr : gpu_agents_counter_info.at(agent_id))
{
if(name_v == std::string_view{citr.name})
{
counters_v.emplace_back(citr.id);
found_v.emplace_back(itr);
counter_found = true;
}
}
if(!counter_found) not_found_counters_v.emplace_back(itr);
}
if(expected_v != counters_v.size())
{
auto requested_counters =
fmt::format("{}", fmt::join(counters.begin(), counters.end(), ", "));
auto found_counters = fmt::format("{}", fmt::join(found_v.begin(), found_v.end(), ", "));
auto found_counters = fmt::format("{}", fmt::join(found_v.begin(), found_v.end(), ", "));
auto missing_counters = fmt::format(
"{}", fmt::join(not_found_counters_v.begin(), not_found_counters_v.end(), ", "));
ROCP_WARNING << "Unable to find all counters for agent " << agent_v->node_id << " (gpu-"
<< agent_v->gpu_index << ", " << agent_v->name << ") in ["
<< requested_counters << "]. Found: [" << found_counters << "]";
<< requested_counters << "]. Found: [" << found_counters << "]. Missing: ["
<< missing_counters << "]";
}
if(!counters_v.empty())
@@ -1246,6 +1254,22 @@ get_instruction_index(rocprofiler_pc_t pc)
return CHECK_NOTNULL(tool_metadata)->get_instruction_index(pc);
}
std::set<std::string>
get_config_perf_counters()
{
auto tool_pmc_counters = std::set<std::string>{};
for(const auto& counters_group : tool::config().counters)
{
for(const auto& counter : counters_group)
tool_pmc_counters.emplace(counter);
}
for(const auto& att_counter : tool::config().att_param_perfcounters)
{
tool_pmc_counters.emplace(att_counter.counter_name);
}
return tool_pmc_counters;
}
} // namespace
std::vector<rocprofiler_thread_trace_parameter_t>
@@ -1679,7 +1703,7 @@ tool_init(rocprofiler_client_finalize_t fini_func, void* tool_data)
const uint64_t buffer_size = 16 * common::units::get_page_size();
const uint64_t buffer_watermark = 15 * common::units::get_page_size();
tool_metadata->init(tool::metadata::inprocess{});
tool_metadata->init(tool::metadata::inprocess_with_counters{get_config_perf_counters()});
ROCPROFILER_CALL(rocprofiler_create_context(&get_client_ctx()), "create context failed");