Commit 5f8d7005 authored by Ashok Emani's avatar Ashok Emani Committed by Scott Cyphers

add env pass filtering to core (#3905)

parent 90c70dde
......@@ -44,6 +44,11 @@ public:
template <typename T, class... Args>
void register_pass(Args&&... args)
{
auto pass = get_pass_name(typeid(T).name());
if (m_pass_config.is_pass_configured(pass) && !m_pass_config.get_pass_enable(pass))
{
return;
}
push_pass<T>(std::forward<Args>(args)...);
if (m_per_pass_validation)
{
......@@ -60,6 +65,19 @@ public:
void set_pass_serialization(bool new_state) { m_serialize = new_state; }
void set_per_pass_validation(bool new_state) { m_per_pass_validation = new_state; }
private:
std::string get_pass_name(const std::string& name)
{
#ifdef _WIN32
// MSVC produce a human-readable type name like class ngraph::pass::LikeReplacement
// by typeid(T).name(). Later ofstream doesn't accept it as a valid file name.
//
auto pos = name.find_last_of(":");
return name.substr(pos + 1);
#elif defined(__linux) || defined(__APPLE__)
return name;
#endif
}
template <typename T, class... Args>
void push_pass(Args&&... args)
{
......@@ -69,16 +87,7 @@ private:
m_pass_list.push_back(pass_base);
if (m_visualize || m_serialize)
{
#ifdef _WIN32
// MSVC produce a human-readable type name like class ngraph::pass::LikeReplacement
// by typeid(T).name(). Later ofstream doesn't accept it as a valid file name.
//
std::string str = typeid(T).name();
auto pos = str.find_last_of(":");
m_pass_names.push_back(str.substr(pos + 1));
#elif defined(__linux) || defined(__APPLE__)
m_pass_names.push_back(typeid(T).name());
#endif
m_pass_names.push_back(get_pass_name(typeid(T).name()));
}
}
......
......@@ -80,6 +80,11 @@ pass::PassConfig::PassConfig()
}
}
bool pass::PassConfig::is_pass_configured(const string& name) const
{
return (m_pass_enables.find(name) != m_pass_enables.end());
}
void pass::PassConfig::set_pass_enable(const string& name, bool enable)
{
m_pass_enables[name] = enable;
......
......@@ -32,6 +32,7 @@ class ngraph::pass::PassConfig
public:
PassConfig();
const std::map<std::string, bool>& get_enables() const { return m_pass_enables; }
bool is_pass_configured(const std::string& name) const;
void set_pass_enable(const std::string& name, bool enable);
bool get_pass_enable(const std::string& name) const;
const std::map<std::string, bool>& get_pass_attributes() const { return m_pass_attributes; }
......
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