Commit d7033279 authored by umangyadav's avatar umangyadav
Browse files

formatting

parent 884d3eb1
...@@ -26,23 +26,21 @@ struct tracer ...@@ -26,23 +26,21 @@ struct tracer
} }
fs::create_directories(dir_path); fs::create_directories(dir_path);
} }
// file_stream // file_stream
bool fs_enabled() const { return !dump_dir.empty() && !os_enabled(); } bool fs_enabled() const { return !dump_dir.empty() && !os_enabled(); }
// output_stream // output_stream
bool os_enabled() const { return os && !fs_enabled();} bool os_enabled() const { return os && !fs_enabled(); }
bool enabled() const {return fs_enabled() or os_enabled();}; bool enabled() const { return fs_enabled() or os_enabled(); };
/* /*
Dump any string to ostream, used for debug build or debugging purposes. Dump any string to ostream, used for debug build or debugging purposes.
*/ */
void operator()(const std::string& s="") const { void operator()(const std::string& s = "") const { std::cout << s << std::endl; }
std::cout << s << std::endl;
}
/* /*
Based on user's envrionment flags, either dump IR passes' output to a file or ostream i.e. cout or cerr, Based on user's envrionment flags, either dump IR passes' output to a file or ostream i.e. cout
:param pass_file_name : file_name to be used when dumping IR pass to a file, this param is not used when IR is or cerr, :param pass_file_name : file_name to be used when dumping IR pass to a file, this param
dumped to ostream. is not used when IR is dumped to ostream.
*/ */
template <class... Ts, MIGRAPHX_REQUIRES((sizeof...(Ts) > 0))> template <class... Ts, MIGRAPHX_REQUIRES((sizeof...(Ts) > 0))>
void operator()(const std::string& pass_file_name, const Ts&... xs) void operator()(const std::string& pass_file_name, const Ts&... xs)
...@@ -55,7 +53,9 @@ struct tracer ...@@ -55,7 +53,9 @@ struct tracer
swallow{ofs << xs...}; swallow{ofs << xs...};
ofs << std::endl; ofs << std::endl;
ofs.close(); ofs.close();
} else if (os_enabled()) { }
else if(os_enabled())
{
swallow{*os << xs...}; swallow{*os << xs...};
*os << std::endl; *os << std::endl;
} }
...@@ -64,8 +64,8 @@ struct tracer ...@@ -64,8 +64,8 @@ struct tracer
std::string dump_dir = ""; std::string dump_dir = "";
private: private:
uint counter = 0; uint counter = 0;
std::ostream* os = nullptr; std::ostream* os = nullptr;
fs::path dir_path = ""; fs::path dir_path = "";
}; };
......
...@@ -39,9 +39,16 @@ void run_pass(program& prog, const pass& p, tracer& trace) ...@@ -39,9 +39,16 @@ void run_pass(program& prog, const pass& p, tracer& trace)
{ {
auto t_start = std::chrono::high_resolution_clock::now(); auto t_start = std::chrono::high_resolution_clock::now();
p.apply(prog); p.apply(prog);
auto t_end = std::chrono::high_resolution_clock::now(); auto t_end = std::chrono::high_resolution_clock::now();
double elapsed_time_ms = std::chrono::duration<double, std::milli>(t_end-t_start).count(); double elapsed_time_ms = std::chrono::duration<double, std::milli>(t_end - t_start).count();
trace(p.name(), "Pass: ", p.name(), "\n", prog, "Elapsed Wall Time (ms): ", elapsed_time_ms, "\n"); trace(p.name(),
"Pass: ",
p.name(),
"\n",
prog,
"Elapsed Wall Time (ms): ",
elapsed_time_ms,
"\n");
} }
struct module_pm : module_pass_manager struct module_pm : module_pass_manager
...@@ -78,9 +85,17 @@ struct module_pm : module_pass_manager ...@@ -78,9 +85,17 @@ struct module_pm : module_pass_manager
assert(mod->validate() == mod->end()); assert(mod->validate() == mod->end());
auto t_start = std::chrono::high_resolution_clock::now(); auto t_start = std::chrono::high_resolution_clock::now();
p.apply(*this); p.apply(*this);
auto t_end = std::chrono::high_resolution_clock::now(); auto t_end = std::chrono::high_resolution_clock::now();
double elapsed_time_ms = std::chrono::duration<double, std::milli>(t_end-t_start).count(); double elapsed_time_ms = std::chrono::duration<double, std::milli>(t_end - t_start).count();
trace(p.name(), "Module: ", mod->name(), ", Pass: ", p.name(), "\n", *mod, "Elapsed Wall Time (ms): ", elapsed_time_ms); trace(p.name(),
"Module: ",
mod->name(),
", Pass: ",
p.name(),
"\n",
*mod,
"Elapsed Wall Time (ms): ",
elapsed_time_ms);
validate_pass(*mod, p, *t); validate_pass(*mod, p, *t);
} }
}; };
...@@ -101,17 +116,20 @@ void run_passes(program& prog, const std::vector<pass>& passes, tracer trace) ...@@ -101,17 +116,20 @@ void run_passes(program& prog, const std::vector<pass>& passes, tracer trace)
{ {
if(enabled(MIGRAPHX_TRACE_PASSES{}) and not trace.enabled()) if(enabled(MIGRAPHX_TRACE_PASSES{}) and not trace.enabled())
trace = tracer{std::cout}; trace = tracer{std::cout};
std::unordered_map<std::string, tracer> module_tracer_map; std::unordered_map<std::string, tracer> module_tracer_map;
for(const auto& p : passes) for(const auto& p : passes)
{ {
auto mods = prog.get_modules(); auto mods = prog.get_modules();
for(const auto& mod : reverse(mods)) for(const auto& mod : reverse(mods))
{ {
// Set tracer for module passes, if tracer is set to output to file stream then set name of the dump directory. // Set tracer for module passes, if tracer is set to output to file stream then set name
// For file dumps, tracer object internally sets the counter for the individual passes' file dumps. // of the dump directory. For file dumps, tracer object internally sets the counter for
if(module_tracer_map.find(mod->name()) == module_tracer_map.end()) { // the individual passes' file dumps.
module_tracer_map[mod->name()] = trace.fs_enabled() ? tracer{trace.dump_dir + "/" + mod->name()} : trace; if(module_tracer_map.find(mod->name()) == module_tracer_map.end())
{
module_tracer_map[mod->name()] =
trace.fs_enabled() ? tracer{trace.dump_dir + "/" + mod->name()} : trace;
} }
if(mod->bypass()) if(mod->bypass())
continue; continue;
......
...@@ -145,7 +145,7 @@ void program::compile(const target& t, compile_options options, const std::strin ...@@ -145,7 +145,7 @@ void program::compile(const target& t, compile_options options, const std::strin
this->impl->ctx = t.get_context(); this->impl->ctx = t.get_context();
if(enabled(MIGRAPHX_DUMP_PASSES_TO_FILE{})) if(enabled(MIGRAPHX_DUMP_PASSES_TO_FILE{}))
options.trace = tracer{t.name() + "_" + ir_dump_path}; options.trace = tracer{t.name() + "_" + ir_dump_path};
else if(enabled(MIGRAPHX_TRACE_COMPILE{})) else if(enabled(MIGRAPHX_TRACE_COMPILE{}))
options.trace = tracer{std::cout}; options.trace = tracer{std::cout};
options.trace("input_program", *this); options.trace("input_program", *this);
......
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