Commit 46d6a1d4 authored by Paul's avatar Paul
Browse files

Formatting

parent a83a717a
...@@ -11,9 +11,9 @@ template <class T> ...@@ -11,9 +11,9 @@ template <class T>
struct xorshf96_generator struct xorshf96_generator
{ {
unsigned long max = 31; unsigned long max = 31;
unsigned long x = 123456789; unsigned long x = 123456789;
unsigned long y = 362436069; unsigned long y = 362436069;
unsigned long z = 521288629; unsigned long z = 521288629;
constexpr T operator()() noexcept constexpr T operator()() noexcept
{ {
......
...@@ -165,17 +165,17 @@ inline shape compute_shape(operation op, std::vector<instruction_ref> args) ...@@ -165,17 +165,17 @@ inline shape compute_shape(operation op, std::vector<instruction_ref> args)
} // namespace migraph } // namespace migraph
namespace std namespace std {
template <>
struct hash<migraph::instruction_ref>
{ {
template<> struct hash<migraph::instruction_ref> using argument_type = migraph::instruction_ref;
using result_type = std::size_t;
result_type operator()(const argument_type& x) const noexcept
{ {
using argument_type = migraph::instruction_ref; return std::hash<migraph::instruction*>{}(&*x);
using result_type = std::size_t; }
result_type operator()(const argument_type& x) const noexcept };
{
return std::hash<migraph::instruction*>{}(&*x);
}
};
} // namespace std } // namespace std
#endif #endif
...@@ -278,7 +278,7 @@ argument generic_eval(const program& p, ...@@ -278,7 +278,7 @@ argument generic_eval(const program& p,
{ {
assert(p.validate() == p.end()); assert(p.validate() == p.end());
std::unordered_map<instruction_ref, argument> results; std::unordered_map<instruction_ref, argument> results;
results.reserve(p.size()*2); results.reserve(p.size() * 2);
std::vector<argument> values; std::vector<argument> values;
values.reserve(16); values.reserve(16);
for(auto ins : iterator_for(p)) for(auto ins : iterator_for(p))
...@@ -289,7 +289,9 @@ argument generic_eval(const program& p, ...@@ -289,7 +289,9 @@ argument generic_eval(const program& p,
} }
else if(ins->op.name() == "@param") else if(ins->op.name() == "@param")
{ {
results.emplace(ins, trace(ins, [&] { return params.at(any_cast<builtin::param>(ins->op).parameter); })); results.emplace(ins, trace(ins, [&] {
return params.at(any_cast<builtin::param>(ins->op).parameter);
}));
} }
else if(ins->op.name() == "@outline") else if(ins->op.name() == "@outline")
{ {
...@@ -302,10 +304,11 @@ argument generic_eval(const program& p, ...@@ -302,10 +304,11 @@ argument generic_eval(const program& p,
ins->arguments.end(), ins->arguments.end(),
values.begin(), values.begin(),
[&](instruction_ref i) { [&](instruction_ref i) {
assert(results.find(i) != results.end()); assert(results.find(i) != results.end());
return results[i]; return results[i];
}); });
results.emplace(ins, trace(ins, [&] { return ins->op.compute(ctx, ins->result, values); })); results.emplace(ins,
trace(ins, [&] { return ins->op.compute(ctx, ins->result, values); }));
} }
assert(results.find(ins) != results.end()); assert(results.find(ins) != results.end());
} }
...@@ -330,16 +333,16 @@ void program::perf_report(std::ostream& os, std::size_t n, parameter_map params) ...@@ -330,16 +333,16 @@ void program::perf_report(std::ostream& os, std::size_t n, parameter_map params)
} }
std::unordered_map<instruction_ref, double> ins_acc; std::unordered_map<instruction_ref, double> ins_acc;
// Fill the map // Fill the map
generic_eval( generic_eval(*this, this->impl->ctx, params, [&](auto ins, auto) {
*this, this->impl->ctx, params, [&](auto ins, auto) { ins_acc[ins] = 0; return argument{}; }); ins_acc[ins] = 0;
return argument{};
});
// Run and time each instruction // Run and time each instruction
for(std::size_t i = 0; i < n; i++) for(std::size_t i = 0; i < n; i++)
{ {
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>([&]{ ins_acc[ins] += time<milliseconds>([&] { result = f(); });
result = f();
});
return result; return result;
}); });
} }
...@@ -347,8 +350,9 @@ void program::perf_report(std::ostream& os, std::size_t n, parameter_map params) ...@@ -347,8 +350,9 @@ void program::perf_report(std::ostream& os, std::size_t n, parameter_map params)
double overhead_acc = 0; double overhead_acc = 0;
for(std::size_t i = 0; i < n; i++) for(std::size_t i = 0; i < n; i++)
{ {
overhead_acc += time<milliseconds>( overhead_acc += 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 = total_acc / n;
...@@ -360,9 +364,7 @@ void program::perf_report(std::ostream& os, std::size_t n, parameter_map params) ...@@ -360,9 +364,7 @@ void program::perf_report(std::ostream& os, std::size_t n, parameter_map params)
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&&) { print_program(os, *this, [&](auto ins, auto&&) { os << ": " << ins_acc[ins] / n << "ms"; });
os << ": " << ins_acc[ins] / n << "ms";
});
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;
......
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