From f9017cbdc57166c417474b6794bfc08b703e356a Mon Sep 17 00:00:00 2001 From: Chun Yang Date: Wed, 11 Aug 2021 19:55:31 -0700 Subject: [PATCH] SWDEV-296922 : Incorrect rounding due to integer division in rocprofiler metrics Changed derived metrics to double from int64. Fixed standalone test due to int64 to float change Fixed intercept test due to int64 to float change. Change-Id: I49631c187406ae9dd94a869b3bb13772012e8cdf --- bin/tblextr.py | 5 ++++- src/core/context.h | 6 +++--- src/xml/expr.h | 5 +++-- test/app/intercept_test.cpp | 3 +++ test/app/standalone_test.cpp | 3 +++ test/tool/tool.cpp | 8 ++++++-- 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/bin/tblextr.py b/bin/tblextr.py index 9417a2de19..866890db3e 100755 --- a/bin/tblextr.py +++ b/bin/tblextr.py @@ -115,7 +115,10 @@ def parse_res(infile): beg_pattern = re.compile("^dispatch\[(\d*)\], (.*) kernel-name\(\"([^\"]*)\"\)") prop_pattern = re.compile("([\w-]+)\((\w+)\)"); ts_pattern = re.compile(", time\((\d*),(\d*),(\d*),(\d*)\)") - var_pattern = re.compile("^\s*([^\s]*)\s+\((\d*)\)") + # var pattern below matches a variable name and a variable value from a one + # line text in the format of for example "WRITE_SIZE (0.2500000000)" or + # "GRBM_GUI_ACTIVE (27867)" + var_pattern = re.compile("^\s*([a-zA-Z0-9_]+)\s+\((\d+(?:\.\d+)?)\)") dispatch_number = 0 for line in inp.readlines(): diff --git a/src/core/context.h b/src/core/context.h index a8026dd3f2..f629ef1ce4 100644 --- a/src/core/context.h +++ b/src/core/context.h @@ -55,7 +55,7 @@ inline unsigned align_size(unsigned size, unsigned alignment) { template class MetricArgs : public xml::args_cache_t { public: MetricArgs(const Map& map) : map_(map) {} - bool Lookup(const std::string& name, uint64_t& result) const { + bool Lookup(const std::string& name, double& result) const { rocprofiler_feature_t* info = NULL; auto it = map_.find(name); if (it == map_.end()) EXC_RAISING(HSA_STATUS_ERROR, "var '" << name << "' is not found"); @@ -311,8 +311,8 @@ class Context { if (it == info_map_.end()) EXC_RAISING(HSA_STATUS_ERROR, "metric '" << name << "', rocprofiler info is not found " << this); rocprofiler_feature_t* info = it->second; - info->data.result_int64 = expr->Eval(args); - info->data.kind = ROCPROFILER_DATA_KIND_INT64; + info->data.result_double = expr->Eval(args); + info->data.kind = ROCPROFILER_DATA_KIND_DOUBLE; } } } diff --git a/src/xml/expr.h b/src/xml/expr.h index 731e25e4fd..7f754b4cda 100644 --- a/src/xml/expr.h +++ b/src/xml/expr.h @@ -29,6 +29,7 @@ THE SOFTWARE. #include #include #include +#include namespace xml { class exception_t : public std::exception { @@ -45,8 +46,8 @@ class div_zero_exception_t : public exception_t { explicit div_zero_exception_t(const std::string& msg) : exception_t("Divide by zero exception " + msg) {} }; -typedef uint64_t args_t; -static const args_t ARGS_MAX = UINT64_MAX; +typedef double args_t; +static const args_t ARGS_MAX = DBL_MAX; typedef std::map args_map_t; class Expr; diff --git a/test/app/intercept_test.cpp b/test/app/intercept_test.cpp index e62bf6cee9..bbcdf806b7 100644 --- a/test/app/intercept_test.cpp +++ b/test/app/intercept_test.cpp @@ -124,6 +124,9 @@ void dump_context_entry(context_entry_t* entry, rocprofiler_feature_t* features, case ROCPROFILER_DATA_KIND_INT64: fprintf(stdout, "= (%lu)\n", p->data.result_int64); break; + case ROCPROFILER_DATA_KIND_DOUBLE: + fprintf(stdout, "= (%lf)\n", p->data.result_double); + break; default: fprintf(stderr, "Undefined data kind(%u)\n", p->data.kind); abort(); diff --git a/test/app/standalone_test.cpp b/test/app/standalone_test.cpp index 34bc05ea80..1344e0ebcb 100644 --- a/test/app/standalone_test.cpp +++ b/test/app/standalone_test.cpp @@ -78,6 +78,9 @@ void print_features(rocprofiler_feature_t* feature, uint32_t feature_count) { case ROCPROFILER_DATA_KIND_INT64: std::cout << std::dec << " result64 (" << p->data.result_int64 << ")" << std::endl; break; + case ROCPROFILER_DATA_KIND_DOUBLE: + std::cout << " result64 (" << p->data.result_double << ")" << std::endl; + break; case ROCPROFILER_DATA_KIND_BYTES: { const char* ptr = reinterpret_cast(p->data.result_bytes.ptr); uint64_t size = 0; diff --git a/test/tool/tool.cpp b/test/tool/tool.cpp index 4bdce5dd5d..1ccce95619 100644 --- a/test/tool/tool.cpp +++ b/test/tool/tool.cpp @@ -351,6 +351,9 @@ void output_results(const context_entry_t* entry, const char* label) { case ROCPROFILER_DATA_KIND_INT64: fprintf(file, "(%lu)\n", p->data.result_int64); break; + case ROCPROFILER_DATA_KIND_DOUBLE: + fprintf(file, "(%.10lf)\n", p->data.result_double); + break; default: fprintf(stderr, "RPL-tool: undefined data kind(%u)\n", p->data.kind); abort(); @@ -358,12 +361,13 @@ void output_results(const context_entry_t* entry, const char* label) { } } -// Output group intermeadate profiling results, created internally for complex metrics +// Output group intermediate profiling results, created internally for complex metrics void output_group(const context_entry_t* entry, const char* label) { const rocprofiler_group_t* group = &(entry->group); context_entry_t group_entry = *entry; for (unsigned i = 0; i < group->feature_count; ++i) { - if (group->features[i]->data.kind == ROCPROFILER_DATA_KIND_INT64) { + if (group->features[i]->data.kind == ROCPROFILER_DATA_KIND_INT64 || + group->features[i]->data.kind == ROCPROFILER_DATA_KIND_DOUBLE) { group_entry.features = group->features[i]; group_entry.feature_count = 1; output_results(&group_entry, label);