From dcd5f1a39721995114269c76aacf2bf21f4e8eb8 Mon Sep 17 00:00:00 2001 From: Saurabh Verma Date: Thu, 20 Apr 2023 20:23:41 -0500 Subject: [PATCH] MI300 counters support for rocprof and rocprofv2(Accumulation from all xccs) 1. Xml files updated for gfx940 counters 2. File plugin changes to allow rocprofv2 backward compatibility for results.csv 3. Changes in rocprofv2 script to use tblextr.py, to generate results.csv just like rocprof Change-Id: I7798f4411ce01f6fbfffb126de654ed806ca7045 (cherry picked from commit 86cbaf38c436be876f0426fa27803b1e64d90378) [ROCm/rocprofiler commit: 8f82ff6a4640040a2e904fb35e180898a19110f5] --- projects/rocprofiler/bin/rocprofv2 | 28 ++ projects/rocprofiler/plugin/file/file.cpp | 14 +- .../core/counters/metrics/basic_counters.xml | 6 + .../counters/metrics/derived_counters.xml | 18 +- .../src/core/counters/metrics/metrics.h | 10 +- projects/rocprofiler/src/core/metrics.h | 68 +++-- .../rocprofiler/test/tool/gfx_metrics.xml | 267 +++++++++++++++++- projects/rocprofiler/test/tool/metrics.xml | 138 ++++++++- 8 files changed, 503 insertions(+), 46 deletions(-) diff --git a/projects/rocprofiler/bin/rocprofv2 b/projects/rocprofiler/bin/rocprofv2 index 8d708317de..319e70833f 100755 --- a/projects/rocprofiler/bin/rocprofv2 +++ b/projects/rocprofiler/bin/rocprofv2 @@ -262,6 +262,7 @@ if [ -n "$COUNTERS_PATH" ]; then done < $input fi +COUNTERS_PMC_DIRS="" if [ -n "$PMC_LINES" ]; then COUNTER=1 for i in ${!PMC_LINES[@]}; do @@ -269,6 +270,7 @@ if [ -n "$PMC_LINES" ]; then if [ -n "$OUTPUT_PATH" ]; then if [ ! -n "$ATT_ARGV" ]; then FINAL_PATH="$OUTPUT_PATH_INTERNAL/pmc_$COUNTER" + COUNTERS_PMC_DIRS="$COUNTERS_PMC_DIRS $FINAL_PATH" else FINAL_PATH="$OUTPUT_PATH" fi @@ -292,6 +294,32 @@ elif [ ! -n "$ATT_ARGV" ]; then fi fi +get_pmc_results_txt_path(){ + for file_name in `ls $1` ; do + if [[ $file_name == *results.txt ]]; then + echo "$1/$file_name" + fi + done +} + +if [ -n "$COUNTERS_PMC_DIRS" ]; then + COUNTERS_RESULTS_TXT="" + for PMC_DIR in $COUNTERS_PMC_DIRS; do + COUNTERS_RESULTS_TXT="$COUNTERS_RESULTS_TXT $(get_pmc_results_txt_path $PMC_DIR)" + done + CSV_RESULTS=$OUTPUT_PATH_INTERNAL/results.csv + if [ -n "$OUT_FILE_NAME" ]; then + CSV_RESULTS=$OUTPUT_PATH_INTERNAL/$OUT_FILE_NAME + fi + echo "csv results path: $CSV_RESULTS" + export ROCP_MERGE_PIDS=1 #required for tblextr.py to work correctly for counters + if [ $RUN_FROM_BUILD == 1 ]; then + eval "python3 $ROCM_DIR/bin/tblextr.py $CSV_RESULTS $COUNTERS_RESULTS_TXT" + else + eval "python3 $ROCPROFV2_DIR/../libexec/rocprofiler/tblextr.py $CSV_RESULTS $COUNTERS_RESULTS_TXT" + fi +fi + if [ -n "$ATT_PATH" ]; then if [ -n "$ATT_ARGV" ]; then eval "python3 $ATT_PATH $ATT_ARGV" diff --git a/projects/rocprofiler/plugin/file/file.cpp b/projects/rocprofiler/plugin/file/file.cpp index d3a643199b..b8fbaf4164 100644 --- a/projects/rocprofiler/plugin/file/file.cpp +++ b/projects/rocprofiler/plugin/file/file.cpp @@ -286,10 +286,10 @@ class file_plugin_t { profiler_record->kernel_id, &kernel_name_c)); } *output_file << std::string("dispatch[") << std::to_string(profiler_record->header.id.handle) - << "], " << std::string("gpu_id(") + << "], " << std::string("gpu-id(") << std::to_string(profiler_record->gpu_id.handle) << "), " - << std::string("queue_id(") << std::to_string(profiler_record->queue_id.handle) - << "), " << std::string("queue_index(") + << std::string("queue-id(") << std::to_string(profiler_record->queue_id.handle) + << "), " << std::string("queue-index(") << std::to_string(profiler_record->queue_idx.value) << "), " << std::string("pid(") << std::to_string(GetPid()) << "), " << std::string("tid(") << std::to_string(profiler_record->thread_id.value) << ")"; @@ -321,9 +321,9 @@ class file_plugin_t { << std::to_string(profiler_record->kernel_id.handle) << "), " << std::string("kernel-name(\"") << kernel_name << "\")" << std::string(", start_time(") - << std::to_string(profiler_record->timestamps.begin.value) << ")" - << std::string(", end_time(") - << std::to_string(profiler_record->timestamps.end.value) << ")"; + << std::string(", time(0,") + << std::to_string(profiler_record->timestamps.begin.value) << "," + << std::to_string(profiler_record->timestamps.end.value) << ",0)"; // For Counters *output_file << std::endl; @@ -339,7 +339,7 @@ class file_plugin_t { CHECK_ROCPROFILER(rocprofiler_query_counter_info( session_id, ROCPROFILER_COUNTER_NAME, profiler_record->counters[i].counter_handler, &name_c)); - *output_file << ", " << name_c << " (" + *output_file << " " << name_c << " (" << std::to_string(profiler_record->counters[i].value.value) << ")" << std::endl; } diff --git a/projects/rocprofiler/src/core/counters/metrics/basic_counters.xml b/projects/rocprofiler/src/core/counters/metrics/basic_counters.xml index ba2275accf..6095e3f2eb 100755 --- a/projects/rocprofiler/src/core/counters/metrics/basic_counters.xml +++ b/projects/rocprofiler/src/core/counters/metrics/basic_counters.xml @@ -498,6 +498,7 @@ + @@ -505,10 +506,12 @@ + + @@ -591,6 +594,7 @@ + @@ -599,6 +603,7 @@ + @@ -620,6 +625,7 @@ + diff --git a/projects/rocprofiler/src/core/counters/metrics/derived_counters.xml b/projects/rocprofiler/src/core/counters/metrics/derived_counters.xml index b32c950728..3119c4577d 100755 --- a/projects/rocprofiler/src/core/counters/metrics/derived_counters.xml +++ b/projects/rocprofiler/src/core/counters/metrics/derived_counters.xml @@ -49,8 +49,8 @@ - - + + @@ -291,8 +291,8 @@ - - + + @@ -369,7 +369,7 @@ - + @@ -411,9 +411,9 @@ - - - + + + @@ -503,6 +503,8 @@ # Aldebaran +#Mi300 + #Navi21 diff --git a/projects/rocprofiler/src/core/counters/metrics/metrics.h b/projects/rocprofiler/src/core/counters/metrics/metrics.h index d33c2849be..062285d344 100755 --- a/projects/rocprofiler/src/core/counters/metrics/metrics.h +++ b/projects/rocprofiler/src/core/counters/metrics/metrics.h @@ -203,10 +203,14 @@ class MetricsDict { xml_->AddConst("top.const.metric", "SE_NUM", agent_info->getShaderEngineCount()); ImportMetrics(agent_info, "const"); agent_name_ = agent_info->getName(); + if (agent_name_.substr(0, 6) == "gfx940") + agent_name_ = + "gfx940"; // To correct the agent_name from "gfx940:forcestoresc1+" -> "gfx940" if (std::string("gfx906") == agent_name_ || std::string("gfx908") == agent_name_ || - std::string("gfx90a") == agent_name_ || std::string("gfx1032") == agent_name_ || - std::string("gfx1031") == agent_name_ || std::string("gfx1030") == agent_name_ || - std::string("gfx1100") == agent_name_ || std::string("gfx1101") == agent_name_) { + std::string("gfx90a") == agent_name_ || std::string("gfx940") == agent_name_ || + std::string("gfx1032") == agent_name_ || std::string("gfx1031") == agent_name_ || + std::string("gfx1030") == agent_name_ || std::string("gfx1100") == agent_name_ || + std::string("gfx1101") == agent_name_) { ImportMetrics(agent_info, agent_name_); } else { agent_name_ = agent_info->getGfxip(); diff --git a/projects/rocprofiler/src/core/metrics.h b/projects/rocprofiler/src/core/metrics.h index 9ce4489252..02c2c36714 100755 --- a/projects/rocprofiler/src/core/metrics.h +++ b/projects/rocprofiler/src/core/metrics.h @@ -136,7 +136,8 @@ class MetricsDict { const Metric* metric = NULL; auto it = cache_.find(name); - if (it != cache_.end()) metric = it->second; + if (it != cache_.end()) + metric = it->second; else { const std::size_t pos = name.find(':'); if (pos != std::string::npos) { @@ -148,7 +149,8 @@ class MetricsDict { const std::size_t pos1 = block_name.find('['); if (pos1 != std::string::npos) { const std::size_t pos2 = block_name.find(']'); - if (pos2 == std::string::npos) EXC_RAISING(HSA_STATUS_ERROR, "Malformed metric name '" << name << "'"); + if (pos2 == std::string::npos) + EXC_RAISING(HSA_STATUS_ERROR, "Malformed metric name '" << name << "'"); block_name = name.substr(0, pos1); const std::string block_index_str = name.substr(pos1 + 1, pos2 - (pos1 + 1)); block_index = atol(block_index_str.c_str()); @@ -156,8 +158,10 @@ class MetricsDict { } const hsa_ven_amd_aqlprofile_id_query_t query = Translate(agent_info_, block_name); - const hsa_ven_amd_aqlprofile_block_name_t block_id = (hsa_ven_amd_aqlprofile_block_name_t)query.id; - if ((query.instance_count > 1) && (indexed == false)) EXC_RAISING(HSA_STATUS_ERROR, "Malformed indexed metric name '" << name << "'"); + const hsa_ven_amd_aqlprofile_block_name_t block_id = + (hsa_ven_amd_aqlprofile_block_name_t)query.id; + if ((query.instance_count > 1) && (indexed == false)) + EXC_RAISING(HSA_STATUS_ERROR, "Malformed indexed metric name '" << name << "'"); const uint32_t event_id = atol(event_str.c_str()); const counter_t counter = {name, {block_id, block_index, event_id}}; metric = new BaseMetric(name, counter); @@ -189,22 +193,23 @@ class MetricsDict { const char* xml_name = getenv("ROCP_METRICS"); if (xml_name != NULL) { xml_ = xml::Xml::Create(xml_name); - if (xml_ == NULL) EXC_RAISING(HSA_STATUS_ERROR, "metrics .xml open error '" << xml_name << "'"); + if (xml_ == NULL) + EXC_RAISING(HSA_STATUS_ERROR, "metrics .xml open error '" << xml_name << "'"); xml_->AddConst("top.const.metric", "MAX_WAVE_SIZE", agent_info->max_wave_size); xml_->AddConst("top.const.metric", "CU_NUM", agent_info->cu_num); xml_->AddConst("top.const.metric", "SIMD_NUM", agent_info->simds_per_cu * agent_info->cu_num); xml_->AddConst("top.const.metric", "SE_NUM", agent_info->se_num); ImportMetrics(agent_info, "const"); agent_name_ = agent_info->name; - if (std::string("gfx906") == agent_info->name || - std::string("gfx908") == agent_info->name || - std::string("gfx90a") == agent_info->name || - std::string("gfx1032") == agent_info->name || - std::string("gfx1031") == agent_info->name || - std::string("gfx1030") == agent_info->name || - std::string("gfx1100") == agent_info->name || - std::string("gfx1101") == agent_info->name) { - ImportMetrics(agent_info, agent_info->name); + if (agent_name_.substr(0, 6) == "gfx940") + agent_name_ = + "gfx940"; // To correct the agent_name from "gfx940:forcestoresc1+" -> "gfx940" + if (std::string("gfx906") == agent_name_ || std::string("gfx908") == agent_name_ || + std::string("gfx90a") == agent_name_ || std::string("gfx940") == agent_name_ || + std::string("gfx1032") == agent_name_ || std::string("gfx1031") == agent_name_ || + std::string("gfx1030") == agent_name_ || std::string("gfx1100") == agent_name_ || + std::string("gfx1101") == agent_name_) { + ImportMetrics(agent_info, agent_name_); } else { agent_name_ = agent_info->gfxip; ImportMetrics(agent_info, agent_info->gfxip); @@ -218,14 +223,16 @@ class MetricsDict { for (auto& entry : cache_) delete entry.second; } - static hsa_ven_amd_aqlprofile_id_query_t Translate(const util::AgentInfo* agent_info, const std::string& block_name) { + static hsa_ven_amd_aqlprofile_id_query_t Translate(const util::AgentInfo* agent_info, + const std::string& block_name) { hsa_ven_amd_aqlprofile_profile_t profile{}; profile.agent = agent_info->dev_id; hsa_ven_amd_aqlprofile_id_query_t query = {block_name.c_str(), 0, 0}; hsa_status_t status = util::HsaRsrcFactory::Instance().AqlProfileApi()->hsa_ven_amd_aqlprofile_get_info( &profile, HSA_VEN_AMD_AQLPROFILE_INFO_BLOCK_ID, &query); - if (status != HSA_STATUS_SUCCESS) AQL_EXC_RAISING(HSA_STATUS_ERROR, "ImportMetrics: bad block name '" << block_name << "'"); + if (status != HSA_STATUS_SUCCESS) + AQL_EXC_RAISING(HSA_STATUS_ERROR, "ImportMetrics: bad block name '" << block_name << "'"); return query; } @@ -251,7 +258,8 @@ class MetricsDict { const uint32_t event_id = atol(event_str.c_str()); const hsa_ven_amd_aqlprofile_id_query_t query = Translate(agent_info, block_name); - const hsa_ven_amd_aqlprofile_block_name_t block_id = (hsa_ven_amd_aqlprofile_block_name_t)query.id; + const hsa_ven_amd_aqlprofile_block_name_t block_id = + (hsa_ven_amd_aqlprofile_block_name_t)query.id; if (query.instance_count > 1) { for (unsigned block_index = 0; block_index < query.instance_count; ++block_index) { std::ostringstream full_name; @@ -272,9 +280,11 @@ class MetricsDict { xml::Expr* expr_obj = NULL; try { expr_obj = new xml::Expr(expr_str, new ExprCache(&cache_)); - } catch(const xml::exception_t& exc) { - if (do_lookup) metrics_list.push_back(node); - else throw(exc); + } catch (const xml::exception_t& exc) { + if (do_lookup) + metrics_list.push_back(node); + else + throw(exc); } if (expr_obj) { #if 0 @@ -285,7 +295,8 @@ class MetricsDict { for (const std::string& var : expr_obj->GetVars()) { auto it = cache_.find(var); if (it == cache_.end()) { - EXC_RAISING(HSA_STATUS_ERROR, "Bad metric '" << name << "', var '" << var << "' is not found"); + EXC_RAISING(HSA_STATUS_ERROR, + "Bad metric '" << name << "', var '" << var << "' is not found"); } it->second->GetCounters(counters_vec); } @@ -309,23 +320,27 @@ class MetricsDict { } } - const Metric* AddMetric(const std::string& name, const std::string& /*alias*/, const counter_t& counter) { + const Metric* AddMetric(const std::string& name, const std::string& /*alias*/, + const counter_t& counter) { const Metric* metric = NULL; const auto ret = cache_.insert({name, NULL}); if (ret.second) { metric = new BaseMetric(name, counter); ret.first->second = metric; - } else EXC_RAISING(HSA_STATUS_ERROR, "metric redefined '" << name << "'"); + } else + EXC_RAISING(HSA_STATUS_ERROR, "metric redefined '" << name << "'"); return metric; } - const Metric* AddMetric(const std::string& name, const counters_vec_t& counters_vec, const xml::Expr* expr_obj) { + const Metric* AddMetric(const std::string& name, const counters_vec_t& counters_vec, + const xml::Expr* expr_obj) { const Metric* metric = NULL; const auto ret = cache_.insert({name, NULL}); if (ret.second) { metric = new ExprMetric(name, counters_vec, expr_obj); ret.first->second = metric; - } else EXC_RAISING(HSA_STATUS_ERROR, "expr-metric redefined '" << name << "'"); + } else + EXC_RAISING(HSA_STATUS_ERROR, "expr-metric redefined '" << name << "'"); return metric; } @@ -336,7 +351,8 @@ class MetricsDict { printf("> Metric '%s'\n", metric->GetName().c_str()); metric->GetCounters(counters_vec); for (auto c : counters_vec) { - printf(" counter %s, b(%u), i (%u), e (%u)\n", c->name.c_str(), c->event.block_name, c->event.block_index, c->event.counter_id); + printf(" counter %s, b(%u), i (%u), e (%u)\n", c->name.c_str(), c->event.block_name, + c->event.block_index, c->event.counter_id); } } } diff --git a/projects/rocprofiler/test/tool/gfx_metrics.xml b/projects/rocprofiler/test/tool/gfx_metrics.xml index a1ff2ea710..768b896c7e 100755 --- a/projects/rocprofiler/test/tool/gfx_metrics.xml +++ b/projects/rocprofiler/test/tool/gfx_metrics.xml @@ -105,7 +105,7 @@ - + @@ -366,6 +366,271 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/projects/rocprofiler/test/tool/metrics.xml b/projects/rocprofiler/test/tool/metrics.xml index f3f7b7eac6..47ce197a95 100755 --- a/projects/rocprofiler/test/tool/metrics.xml +++ b/projects/rocprofiler/test/tool/metrics.xml @@ -49,6 +49,9 @@ + + + @@ -112,7 +115,7 @@ - + @@ -207,6 +210,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -290,6 +424,8 @@ # Aldebaran +#Mi300 + #Navi21