"git@developer.sourcefind.cn:wangsen/mineru.git" did not exist on "6350f3492a8b107d7e97f54f60dfe8fc2ff8e964"
Commit bf794d08 authored by Paul's avatar Paul
Browse files

Calculate a more stable average

parent 46d6a1d4
...@@ -24,12 +24,13 @@ int main(int argc, char const* argv[]) ...@@ -24,12 +24,13 @@ int main(int argc, char const* argv[])
if(argc > 1) if(argc > 1)
{ {
std::string file = argv[1]; std::string file = argv[1];
std::size_t n = argc > 2 ? std::stoul(argv[2]) : 50;
auto p = migraph::parse_onnx(file); auto p = migraph::parse_onnx(file);
std::cout << "Compiling ... " << std::endl; std::cout << "Compiling ... " << std::endl;
p.compile(migraph::gpu::target{}); p.compile(migraph::gpu::target{});
std::cout << "Allocating params ... " << std::endl; std::cout << "Allocating params ... " << std::endl;
auto m = create_param_map(p); auto m = create_param_map(p);
std::cout << "Running performance report ... " << std::endl; std::cout << "Running performance report ... " << std::endl;
p.perf_report(std::cout, 50, m); p.perf_report(std::cout, n, m);
} }
} }
...@@ -320,21 +320,30 @@ argument program::eval(std::unordered_map<std::string, argument> params) const ...@@ -320,21 +320,30 @@ argument program::eval(std::unordered_map<std::string, argument> params) const
return generic_eval(*this, this->impl->ctx, params, [](auto&, auto f) { return f(); }); return generic_eval(*this, this->impl->ctx, params, [](auto&, auto f) { return f(); });
} }
double common_average(const std::vector<double>& v)
{
std::size_t n = v.size() / 4;
double total = std::accumulate(v.begin()+n, v.end()-n, 0.0);
return total / std::distance(v.begin()+n, v.end()-n);
}
void program::perf_report(std::ostream& os, std::size_t n, parameter_map params) const void program::perf_report(std::ostream& os, std::size_t n, parameter_map params) const
{ {
using milliseconds = std::chrono::duration<double, std::milli>; using milliseconds = std::chrono::duration<double, std::milli>;
// Run once by itself // Run once by itself
eval(params); eval(params);
// Run and time entire program // Run and time entire program
double total_acc = 0; std::vector<double> total_vec;
total_vec.reserve(n);
for(std::size_t i = 0; i < n; i++) for(std::size_t i = 0; i < n; i++)
{ {
total_acc += time<milliseconds>([&] { eval(params); }); total_vec.push_back(time<milliseconds>([&] { eval(params); }));
} }
std::unordered_map<instruction_ref, double> ins_acc; std::sort(total_vec.begin(), total_vec.end());
std::unordered_map<instruction_ref, std::vector<double>> ins_vec;
// Fill the map // Fill the map
generic_eval(*this, this->impl->ctx, params, [&](auto ins, auto) { generic_eval(*this, this->impl->ctx, params, [&](auto ins, auto) {
ins_acc[ins] = 0; ins_vec[ins].reserve(n);
return argument{}; return argument{};
}); });
// Run and time each instruction // Run and time each instruction
...@@ -342,30 +351,35 @@ void program::perf_report(std::ostream& os, std::size_t n, parameter_map params) ...@@ -342,30 +351,35 @@ void program::perf_report(std::ostream& os, std::size_t n, parameter_map params)
{ {
generic_eval(*this, this->impl->ctx, params, [&](auto ins, auto f) { generic_eval(*this, this->impl->ctx, params, [&](auto ins, auto f) {
argument result; argument result;
ins_acc[ins] += time<milliseconds>([&] { result = f(); }); ins_vec[ins].push_back(time<milliseconds>([&] { result = f(); }));
return result; return result;
}); });
} }
for(auto&& p : ins_vec)
std::sort(p.second.begin(), p.second.end());
// Run and time implicit overhead // Run and time implicit overhead
double overhead_acc = 0; std::vector<double> overhead_vec;
overhead_vec.reserve(n);
for(std::size_t i = 0; i < n; i++) for(std::size_t i = 0; i < n; i++)
{ {
overhead_acc += time<milliseconds>([&] { overhead_vec.push_back(time<milliseconds>([&] {
generic_eval(*this, this->impl->ctx, params, [](auto...) { return argument{}; }); generic_eval(*this, this->impl->ctx, params, [](auto...) { return argument{}; });
}); }));
} }
double total_time = total_acc / n; double total_time = common_average(total_vec);
double overhead_time = overhead_acc / n; double rate = std::ceil(1000.0 / total_time);
double overhead_time = common_average(overhead_vec);
double overhead_percent = overhead_time * 100.0 / total_time; double overhead_percent = overhead_time * 100.0 / total_time;
double total_instruction_time = 0.0; double total_instruction_time = 0.0;
for(auto&& p : ins_acc) for(auto&& p : ins_vec)
total_instruction_time += p.second / n; total_instruction_time += common_average(p.second);
double calculate_overhead_time = total_time - total_instruction_time; double calculate_overhead_time = total_time - total_instruction_time;
double calculate_overhead_percent = calculate_overhead_time * 100.0 / total_time; double calculate_overhead_percent = calculate_overhead_time * 100.0 / total_time;
print_program(os, *this, [&](auto ins, auto&&) { os << ": " << ins_acc[ins] / n << "ms"; }); print_program(os, *this, [&](auto ins, auto&&) { os << ": " << common_average(ins_vec[ins]) << "ms"; });
os << "Rate: " << rate << "/sec" << std::endl;
os << "Total time: " << total_time << "ms" << std::endl; os << "Total time: " << total_time << "ms" << std::endl;
os << "Total instructions time: " << total_instruction_time << "ms" << std::endl; os << "Total instructions time: " << total_instruction_time << "ms" << std::endl;
os << "Overhead time: " << overhead_time << "ms" os << "Overhead time: " << overhead_time << "ms"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment