Unverified Commit e3d95453 authored by Robert Kimball's avatar Robert Kimball Committed by GitHub

add pass profiler (#1211)

parent 26645912
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
*******************************************************************************/ *******************************************************************************/
#include <algorithm> #include <algorithm>
#include <cxxabi.h>
#include <iomanip>
#include <iostream> #include <iostream>
#include <memory> #include <memory>
...@@ -27,6 +29,7 @@ ...@@ -27,6 +29,7 @@
#include "ngraph/pass/pass.hpp" #include "ngraph/pass/pass.hpp"
#include "ngraph/pass/serialize.hpp" #include "ngraph/pass/serialize.hpp"
#include "ngraph/pass/visualize_tree.hpp" #include "ngraph/pass/visualize_tree.hpp"
#include "ngraph/util.hpp"
using namespace std; using namespace std;
using namespace ngraph; using namespace ngraph;
...@@ -55,6 +58,8 @@ void ngraph::pass::Manager::initialize_default_passes() ...@@ -55,6 +58,8 @@ void ngraph::pass::Manager::initialize_default_passes()
void ngraph::pass::Manager::run_passes(shared_ptr<Function> func) void ngraph::pass::Manager::run_passes(shared_ptr<Function> func)
{ {
bool profile_enabled = getenv("NGRAPH_PROFILE_PASS_ENABLE") != nullptr;
// find all functions // find all functions
vector<shared_ptr<Function>> fs; vector<shared_ptr<Function>> fs;
traverse_functions(func, [&](shared_ptr<Function> f) { fs.push_back(f); }); traverse_functions(func, [&](shared_ptr<Function> f) { fs.push_back(f); });
...@@ -63,8 +68,12 @@ void ngraph::pass::Manager::run_passes(shared_ptr<Function> func) ...@@ -63,8 +68,12 @@ void ngraph::pass::Manager::run_passes(shared_ptr<Function> func)
get_state().set_functions(tfs); get_state().set_functions(tfs);
size_t index = 0; size_t index = 0;
stopwatch pass_timer;
stopwatch overall_timer;
overall_timer.start();
for (shared_ptr<PassBase> pass : m_pass_list) for (shared_ptr<PassBase> pass : m_pass_list)
{ {
pass_timer.start();
pass->set_state(get_state()); pass->set_state(get_state());
auto module_pass = dynamic_pointer_cast<ModulePass>(pass); auto module_pass = dynamic_pointer_cast<ModulePass>(pass);
auto function_pass = dynamic_pointer_cast<FunctionPass>(pass); auto function_pass = dynamic_pointer_cast<FunctionPass>(pass);
...@@ -122,6 +131,19 @@ void ngraph::pass::Manager::run_passes(shared_ptr<Function> func) ...@@ -122,6 +131,19 @@ void ngraph::pass::Manager::run_passes(shared_ptr<Function> func)
} }
} }
index++; index++;
pass_timer.stop();
if (profile_enabled)
{
PassBase* p = pass.get();
string name = typeid(*p).name();
int status;
name = abi::__cxa_demangle(name.c_str(), 0, 0, &status);
cout << setw(7) << pass_timer.get_milliseconds() << "ms " << name << "\n";
}
}
if (profile_enabled)
{
cout << "passes done in " << overall_timer.get_milliseconds() << "ms\n";
} }
} }
......
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