提交 a0a7849e 编写于 作者: 李寅

Merge branch 'log_feature_map' into 'master'

Log feature map size and arguments during benchmark

See merge request !380
...@@ -16,6 +16,8 @@ cc_library( ...@@ -16,6 +16,8 @@ cc_library(
hdrs = ["stat_summarizer.h"], hdrs = ["stat_summarizer.h"],
linkstatic = 1, linkstatic = 1,
deps = [ deps = [
"//mace/core",
"//mace/kernels",
"//mace/public", "//mace/public",
"//mace/utils", "//mace/utils",
], ],
......
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
#include "mace/public/mace.h" #include "mace/public/mace.h"
#include "mace/utils/logging.h" #include "mace/utils/logging.h"
#include "mace/core/types.h"
#include "mace/kernels/conv_pool_2d_util.h"
namespace mace { namespace mace {
namespace benchmark { namespace benchmark {
...@@ -55,6 +56,8 @@ void StatSummarizer::ProcessMetadata(const RunMetadata &run_metadata) { ...@@ -55,6 +56,8 @@ void StatSummarizer::ProcessMetadata(const RunMetadata &run_metadata) {
if (result.second) { if (result.second) {
detail->name = name; detail->name = name;
detail->type = op_type; detail->type = op_type;
detail->output_shape = ops.output_shape;
detail->args = ops.args;
detail->run_order = node_num; detail->run_order = node_num;
...@@ -83,7 +86,7 @@ std::string StatSummarizer::ShortSummary() const { ...@@ -83,7 +86,7 @@ std::string StatSummarizer::ShortSummary() const {
} }
std::ostream &InitField(std::ostream &stream, int width) { std::ostream &InitField(std::ostream &stream, int width) {
stream << "\t" << std::right << std::setw(width) << std::fixed stream << std::right << std::setw(width) << std::fixed
<< std::setprecision(3); << std::setprecision(3);
return stream; return stream;
} }
...@@ -98,12 +101,72 @@ std::string StatSummarizer::HeaderString(const std::string &title) const { ...@@ -98,12 +101,72 @@ std::string StatSummarizer::HeaderString(const std::string &title) const {
InitField(stream, 9) << "[start]"; InitField(stream, 9) << "[start]";
InitField(stream, 9) << "[first]"; InitField(stream, 9) << "[first]";
InitField(stream, 9) << "[avg ms]"; InitField(stream, 9) << "[avg ms]";
InitField(stream, 8) << "[%]"; InitField(stream, 9) << "[%]";
InitField(stream, 8) << "[cdf%]"; InitField(stream, 9) << "[cdf%]";
InitField(stream, 10) << "[mem KB]"; InitField(stream, 10) << "[mem KB]";
InitField(stream, 9) << "[times called]"; InitField(stream, 10) << "[Name]";
stream << "\t" InitField(stream, 8) << "[stride]";
<< "[Name]"; InitField(stream, 10) << "[padding]";
InitField(stream, 10) << "[dilation]";
InitField(stream, 15) << "[kernel]";
stream << std::right << std::setw(45) << "[output shape]";
return stream.str();
}
std::string PaddingTypeToString(int padding_type) {
std::stringstream stream;
Padding type = static_cast<Padding>(padding_type);
switch (type) {
case VALID: stream << "VALID"; break;
case SAME: stream << "SAME"; break;
case FULL: stream << "FULL"; break;
default: stream << padding_type; break;
}
return stream.str();
}
std::string ShapeToString(const std::vector<OutputShape> &output_shape) {
if (output_shape.empty()) {
return "";
}
std::stringstream stream;
stream << "[";
for (int i = 0; i < output_shape.size(); ++i) {
const std::vector<index_t> &dims = output_shape[i].dims();
for (int j = 0; j < dims.size(); ++j) {
stream << dims[j];
if (j != dims.size() - 1) {
stream << ",";
}
}
if (i != output_shape.size() - 1) {
stream << ":";
}
}
stream << "]";
return stream.str();
}
template <typename T>
std::string VectorToString(const std::vector<T> &vec) {
if (vec.empty()) {
return "";
}
std::stringstream stream;
stream << "[";
for (int i = 0; i < vec.size(); ++i) {
stream << vec[i];
if (i != vec.size() - 1) {
stream << ",";
}
}
stream << "]";
return stream.str(); return stream.str();
} }
...@@ -115,18 +178,25 @@ std::string StatSummarizer::ColumnString(const StatSummarizer::Detail &detail, ...@@ -115,18 +178,25 @@ std::string StatSummarizer::ColumnString(const StatSummarizer::Detail &detail,
const double avg_time_ms = detail.rel_end_us.avg() / 1000.0; const double avg_time_ms = detail.rel_end_us.avg() / 1000.0;
const double percentage = detail.rel_end_us.sum() * 100.0 / stat.sum(); const double percentage = detail.rel_end_us.sum() * 100.0 / stat.sum();
const double cdf_percentage = (cumulative_stat_on_node * 100.0f) / stat.sum(); const double cdf_percentage = (cumulative_stat_on_node * 100.0f) / stat.sum();
const int64_t times_called = detail.times_called / num_runs();
std::stringstream stream; std::stringstream stream;
InitField(stream, 24) << detail.type; InitField(stream, 24) << detail.type;
InitField(stream, 9) << start_ms; InitField(stream, 9) << start_ms;
InitField(stream, 9) << first_time_ms; InitField(stream, 9) << first_time_ms;
InitField(stream, 9) << avg_time_ms; InitField(stream, 9) << avg_time_ms;
InitField(stream, 7) << percentage << "%"; InitField(stream, 8) << percentage << "%";
InitField(stream, 7) << cdf_percentage << "%"; InitField(stream, 8) << cdf_percentage << "%";
InitField(stream, 10) << detail.mem_used.newest() / 1000.0; InitField(stream, 10) << detail.mem_used.newest() / 1000.0;
InitField(stream, 9) << times_called; InitField(stream, 10) << detail.name;
stream << "\t" << detail.name; InitField(stream, 8) << VectorToString<int>(detail.args.strides);
if (detail.args.padding_type != -1) {
InitField(stream, 10) << PaddingTypeToString(detail.args.padding_type);
} else {
InitField(stream, 10) << VectorToString<int>(detail.args.paddings);
}
InitField(stream, 10) << VectorToString<int>(detail.args.dilations);
InitField(stream, 15) << VectorToString<index_t>(detail.args.kernels);
stream << std::right << std::setw(45) << ShapeToString(detail.output_shape);
return stream.str(); return stream.str();
} }
...@@ -138,6 +208,7 @@ void StatSummarizer::OrderNodesByMetric( ...@@ -138,6 +208,7 @@ void StatSummarizer::OrderNodesByMetric(
for (const auto &det : details_) { for (const auto &det : details_) {
const Detail *detail = &(det.second); const Detail *detail = &(det.second);
std::stringstream stream; std::stringstream stream;
stream << std::setw(20) << std::right << std::setprecision(10) stream << std::setw(20) << std::right << std::setprecision(10)
<< std::fixed; << std::fixed;
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "mace/public/mace_types.h"
namespace mace { namespace mace {
class RunMetadata; class RunMetadata;
...@@ -175,6 +177,8 @@ class StatSummarizer { ...@@ -175,6 +177,8 @@ class StatSummarizer {
struct Detail { struct Detail {
std::string name; std::string name;
std::string type; std::string type;
std::vector<mace::OutputShape> output_shape;
ConvPoolArgs args;
int64_t run_order; int64_t run_order;
Stat<int64_t> start_us; Stat<int64_t> start_us;
Stat<int64_t> rel_end_us; Stat<int64_t> rel_end_us;
...@@ -189,7 +193,6 @@ class StatSummarizer { ...@@ -189,7 +193,6 @@ class StatSummarizer {
std::string ColumnString(const Detail &detail, std::string ColumnString(const Detail &detail,
const int64_t cumulative_stat_on_node, const int64_t cumulative_stat_on_node,
const Stat<int64_t> &stat) const; const Stat<int64_t> &stat) const;
Stat<int64_t> run_total_us_; Stat<int64_t> run_total_us_;
Stat<int64_t> memory_; Stat<int64_t> memory_;
......
...@@ -67,8 +67,32 @@ bool SerialNet::Run(RunMetadata *run_metadata) { ...@@ -67,8 +67,32 @@ bool SerialNet::Run(RunMetadata *run_metadata) {
} }
if (run_metadata != nullptr) { if (run_metadata != nullptr) {
std::vector<int> strides;
int padding_type = -1;
std::vector<int> paddings;
std::vector<int> dilations;
std::vector<index_t> kernels;
std::string type = op->debug_def().type();
if (type.compare("Conv2D") == 0 ||
type.compare("FusedConv2D") == 0 ||
type.compare("DepthwiseConv2d") == 0 ||
type.compare("Pooling") == 0) {
strides = op->GetRepeatedArgument<int>("strides");
padding_type = op->GetSingleArgument<int>("padding", -1);
paddings = op->GetRepeatedArgument<int>("padding_values");
dilations = op->GetRepeatedArgument<int>("dilations");
if (type.compare("Pooling") == 0) {
kernels = op->GetRepeatedArgument<index_t>("kernels");
} else {
kernels = op->Input(1)->shape();
}
}
OperatorStats op_stats = {op->debug_def().name(), op->debug_def().type(), OperatorStats op_stats = {op->debug_def().name(), op->debug_def().type(),
call_stats}; op->debug_def().output_shape(),
{strides, padding_type, paddings, dilations,
kernels}, call_stats};
run_metadata->op_stats.emplace_back(op_stats); run_metadata->op_stats.emplace_back(op_stats);
} }
......
...@@ -326,9 +326,19 @@ struct CallStats { ...@@ -326,9 +326,19 @@ struct CallStats {
int64_t end_micros; int64_t end_micros;
}; };
struct ConvPoolArgs {
std::vector<int> strides;
int padding_type;
std::vector<int> paddings;
std::vector<int> dilations;
std::vector<int64_t> kernels;
};
struct OperatorStats { struct OperatorStats {
std::string operator_name; std::string operator_name;
std::string type; std::string type;
std::vector<OutputShape> output_shape;
ConvPoolArgs args;
CallStats stats; CallStats stats;
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册