未验证 提交 fcf6fa0c 编写于 作者: Y Yuan Shuai 提交者: GitHub

[LITE][PROFILE] Fix profiler summary (#3724)

* [LITE][PROFILE] Fix summary info for profiler. test=develop
上级 2fbf2968
...@@ -24,14 +24,9 @@ namespace profile { ...@@ -24,14 +24,9 @@ namespace profile {
namespace { namespace {
auto op_comp = [](const OpCharacter& c1, const OpCharacter& c2) { auto op_comp = [](const OpCharacter& c1, const OpCharacter& c2) {
if (c1.kernel_func_name == "NotImpl" && c2.kernel_func_name == "NotImpl") { // compare for unique key of map
return (c1.target < c2.target) || (c1.op_type < c2.op_type) || return (c1.kernel_name + c1.kernel_func_name <
(c1.kernel_name < c2.kernel_name) || (c1.remark < c2.remark); c2.kernel_name + c2.kernel_func_name);
} else { // compare with ch.kernel_func_name
return (c1.target < c2.target) || (c1.op_type < c2.op_type) ||
(c1.kernel_name < c2.kernel_name) ||
(c1.kernel_func_name < c2.kernel_func_name);
}
}; };
} // namespace } // namespace
...@@ -95,14 +90,13 @@ void Profiler::StopTiming(Type type, const int index, KernelContext* ctx) { ...@@ -95,14 +90,13 @@ void Profiler::StopTiming(Type type, const int index, KernelContext* ctx) {
} }
int Profiler::GetKernelFuncCalledTimes(const std::string& op_type, int Profiler::GetKernelFuncCalledTimes(const std::string& op_type,
const std::string& kernel_attr,
const std::string& kernel_func_name) { const std::string& kernel_func_name) {
int count = 0; int count = 0;
for (size_t i = 0; i < units_.size(); ++i) { for (size_t i = 0; i < units_.size(); ++i) {
if ((units_[i].character.kernel_func_name == kernel_func_name) && if ((units_[i].character.kernel_func_name == kernel_func_name) &&
(units_[i].character.kernel_func_name != "NotImpl")) { (units_[i].character.kernel_attr == kernel_attr) &&
++count; (units_[i].character.op_type == op_type)) {
} else if ((units_[i].character.kernel_func_name == "NotImpl") &&
(units_[i].character.op_type == op_type)) {
++count; ++count;
} }
} }
...@@ -110,14 +104,13 @@ int Profiler::GetKernelFuncCalledTimes(const std::string& op_type, ...@@ -110,14 +104,13 @@ int Profiler::GetKernelFuncCalledTimes(const std::string& op_type,
} }
float Profiler::GetKernelFuncSummaryGOPs(const std::string& op_type, float Profiler::GetKernelFuncSummaryGOPs(const std::string& op_type,
const std::string& kernel_attr,
const std::string& kernel_func_name) { const std::string& kernel_func_name) {
float GOPs = 0; float GOPs = 0;
for (size_t i = 0; i < units_.size(); ++i) { for (size_t i = 0; i < units_.size(); ++i) {
if ((units_[i].character.kernel_func_name == kernel_func_name) && if ((units_[i].character.kernel_func_name == kernel_func_name) &&
(units_[i].character.kernel_func_name != "NotImpl")) { (units_[i].character.kernel_attr == kernel_attr) &&
GOPs += units_[i].character.macs; (units_[i].character.op_type == op_type)) {
} else if ((units_[i].character.kernel_func_name == "NotImpl") &&
(units_[i].character.op_type == op_type)) {
GOPs += units_[i].character.macs; GOPs += units_[i].character.macs;
} }
} }
...@@ -232,9 +225,11 @@ std::string Profiler::Summary(Type type, bool concise, size_t w) { ...@@ -232,9 +225,11 @@ std::string Profiler::Summary(Type type, bool concise, size_t w) {
<< " " << setprecision(2) << percent << "% " << " " << setprecision(2) << percent << "% "
<< " " << setw(7) << left << fixed << setprecision(3) << " " << setw(7) << left << fixed << setprecision(3)
<< GetKernelFuncSummaryGOPs(item.first.op_type, << GetKernelFuncSummaryGOPs(item.first.op_type,
item.first.kernel_attr,
item.first.kernel_func_name) item.first.kernel_func_name)
<< " " << setw(11) << left << fixed << " " << setw(11) << left << fixed
<< GetKernelFuncCalledTimes(item.first.op_type, << GetKernelFuncCalledTimes(item.first.op_type,
item.first.kernel_attr,
item.first.kernel_func_name); item.first.kernel_func_name);
#ifdef LITE_WITH_OPENCL #ifdef LITE_WITH_OPENCL
float cl_percent = 0; float cl_percent = 0;
......
...@@ -78,6 +78,13 @@ struct OpCharacter { ...@@ -78,6 +78,13 @@ struct OpCharacter {
} }
return dim_str; return dim_str;
} }
std::string str() {
std::string str{""};
str += kernel_name + "/" + kernel_func_name + "/" + remark + "/" +
input_shape + "/" + filter_shape + "/" + output_shape;
return str;
}
}; };
class StatisUnit final { class StatisUnit final {
...@@ -102,8 +109,10 @@ class Profiler final { ...@@ -102,8 +109,10 @@ class Profiler final {
void StopTiming(Type type, const int index, KernelContext* ctx); void StopTiming(Type type, const int index, KernelContext* ctx);
std::string Summary(Type type, bool concise = true, size_t warm_up = 10); std::string Summary(Type type, bool concise = true, size_t warm_up = 10);
int GetKernelFuncCalledTimes(const std::string& op_type, int GetKernelFuncCalledTimes(const std::string& op_type,
const std::string& kernel_attr,
const std::string& kernel_func_name); const std::string& kernel_func_name);
float GetKernelFuncSummaryGOPs(const std::string& op_type, float GetKernelFuncSummaryGOPs(const std::string& op_type,
const std::string& kernel_attr,
const std::string& kernel_func_name); const std::string& kernel_func_name);
OpCharacter* GetOpCharacter(const size_t index); OpCharacter* GetOpCharacter(const size_t index);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册