diff --git a/inc/rocprofiler.h b/inc/rocprofiler.h index 9fd172c06a..fe64fc4e4c 100644 --- a/inc/rocprofiler.h +++ b/inc/rocprofiler.h @@ -48,7 +48,7 @@ SOFTWARE. #include #include -#define ROCPROFILER_VERSION_MAJOR 1 +#define ROCPROFILER_VERSION_MAJOR 2 #define ROCPROFILER_VERSION_MINOR 1 #ifdef __cplusplus @@ -331,8 +331,11 @@ typedef struct { union { struct { const char* name; // metric name + uint32_t instances; // instances number const char* expr; // metric expression, NULL for basic counters const char* description; // metric description + const char* block_name; // block name + uint32_t block_counters; // number of block counters } metric; struct { const char* name; // trace name diff --git a/src/core/rocprofiler.cpp b/src/core/rocprofiler.cpp index ac70dace6d..30247ff8aa 100644 --- a/src/core/rocprofiler.cpp +++ b/src/core/rocprofiler.cpp @@ -481,6 +481,43 @@ PUBLIC_API hsa_status_t rocprofiler_iterate_info( info.metric.name = strdup(name.c_str()); info.metric.description = strdup(descr.c_str()); info.metric.expr = expr.empty() ? NULL : strdup(expr.c_str()); + + if (expr.empty()) { + // Getting the block name + const std::string block_name = node->opts["block"]; + + // Querying profile + rocprofiler::profile_t profile = {}; + profile.agent = agent_info->dev_id; + profile.type = HSA_VEN_AMD_AQLPROFILE_EVENT_TYPE_PMC; + + // Query block id info + hsa_ven_amd_aqlprofile_id_query_t query = {block_name.c_str(), 0, 0}; + hsa_status_t status = rocprofiler::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, "get block id info: '" << block_name << "'"); + + // Metric object + const std::string metric_name = (query.instance_count > 1) ? name + "[0]" : name; + const rocprofiler::Metric* metric = dict->Get(metric_name); + if (metric == NULL) EXC_RAISING(HSA_STATUS_ERROR, "metric '" << name << "' is not found"); + + // Process metrics counters + const rocprofiler::counters_vec_t& counters_vec = metric->GetCounters(); + if (counters_vec.size() != 1) EXC_RAISING(HSA_STATUS_ERROR, "error: '" << metric->GetName() << "' is not basic"); + + // Query block counters number + uint32_t block_counters; + profile.events = &(counters_vec[0]->event); + status = rocprofiler::util::HsaRsrcFactory::Instance().AqlProfileApi()->hsa_ven_amd_aqlprofile_get_info( + &profile, HSA_VEN_AMD_AQLPROFILE_INFO_BLOCK_COUNTERS, &block_counters); + if (status != HSA_STATUS_SUCCESS) continue; + + info.metric.instances = query.instance_count; + info.metric.block_name = block_name.c_str(); + info.metric.block_counters = block_counters; + } + status = callback(info, data); if (status != HSA_STATUS_SUCCESS) break; } diff --git a/src/util/exception.h b/src/util/exception.h index e9231e0c3e..46d99bdcd4 100644 --- a/src/util/exception.h +++ b/src/util/exception.h @@ -49,7 +49,7 @@ SOFTWARE. #define AQL_EXC_RAISING(error, stream) \ { \ const char* error_string = NULL; \ - const rocprofiler::pfn_t* api = util::HsaRsrcFactory::Instance().AqlProfileApi(); \ + const rocprofiler::pfn_t* api = rocprofiler::util::HsaRsrcFactory::Instance().AqlProfileApi(); \ api->hsa_ven_amd_aqlprofile_error_string(&error_string); \ EXC_RAISING(error, stream << ", " << error_string); \ } diff --git a/test/tool/tool.cpp b/test/tool/tool.cpp index 106bb6546e..5cf8443a26 100644 --- a/test/tool/tool.cpp +++ b/test/tool/tool.cpp @@ -646,8 +646,16 @@ static hsa_status_t info_callback(const rocprofiler_info_data_t info, void * arg if (((symb == 'b') && (info.metric.expr == NULL)) || ((symb == 'd') && (info.metric.expr != NULL))) { - printf("\n gpu-agent%d : %s : %s\n", info.agent_index, info.metric.name, info.metric.description); - if (info.metric.expr != NULL) printf(" %s = %s\n", info.metric.name, info.metric.expr); + if (info.metric.expr != NULL) { + fprintf(stdout, "\n gpu-agent%d : %s : %s\n", info.agent_index, info.metric.name, info.metric.description); + fprintf(stdout, " %s = %s\n", info.metric.name, info.metric.expr); + } else { + fprintf(stdout, "\n gpu-agent%d : %s", info.agent_index, info.metric.name); + if (info.metric.instances > 1) fprintf(stdout, "[0-%u]", info.metric.instances - 1); + fprintf(stdout, " : %s\n", info.metric.description); + fprintf(stdout, " block %s has %u counters\n", info.metric.block_name, info.metric.block_counters); + } + fflush(stdout); } return HSA_STATUS_SUCCESS; } @@ -802,7 +810,8 @@ extern "C" PUBLIC_API void OnLoadToolProp(rocprofiler_settings_t* settings) } else { if (*info_symb == 'b') printf("Basic HW counters:\n"); else printf("Derived metrics:\n"); - rocprofiler_iterate_info(NULL, ROCPROFILER_INFO_KIND_METRIC, info_callback, info_symb); + hsa_status_t status = rocprofiler_iterate_info(NULL, ROCPROFILER_INFO_KIND_METRIC, info_callback, info_symb); + check_status(status); } exit(1); }