Unverified Commit eed4279e authored by Nick Korovaiko's avatar Nick Korovaiko Committed by GitHub

facility to name matchers to make debugging easier (#1110)

parent bdfcf5b4
...@@ -32,11 +32,11 @@ bool ngraph::pass::GraphRewrite::run_matchers_on_nodes_list( ...@@ -32,11 +32,11 @@ bool ngraph::pass::GraphRewrite::run_matchers_on_nodes_list(
{ {
for (auto matcher : matchers) for (auto matcher : matchers)
{ {
NGRAPH_DEBUG << "Running matcher " << matcher << " on " << node << " , " NGRAPH_DEBUG << "Running matcher " << matcher->get_name() << "("
<< node->get_name() << " , is_output = " << node->is_output(); << matcher->get_pattern()->get_name() << ") on " << node->get_name();
if (matcher->match(node)) if (matcher->match(node))
{ {
NGRAPH_DEBUG << "Matcher " << matcher << " matched " << node << " , " NGRAPH_DEBUG << "Matcher " << matcher << matcher->get_name() << " matched "
<< node->get_name(); << node->get_name();
rewritten = true; rewritten = true;
if (matcher->process_match()) if (matcher->process_match())
...@@ -64,12 +64,10 @@ bool ngraph::pass::RecurrentGraphRewrite::run_on_function(std::shared_ptr<ngraph ...@@ -64,12 +64,10 @@ bool ngraph::pass::RecurrentGraphRewrite::run_on_function(std::shared_ptr<ngraph
{ {
for (auto matcher : m_matchers) for (auto matcher : m_matchers)
{ {
NGRAPH_DEBUG << "Running matcher " << matcher << " on " << node << " , " NGRAPH_DEBUG << "Running matcher " << matcher << " on " << node->get_name();
<< node->get_name() << " , is_output = " << node->is_output();
if (matcher->match(node)) if (matcher->match(node))
{ {
NGRAPH_DEBUG << "Matcher " << matcher << " matched " << node << " , " NGRAPH_DEBUG << "Matcher " << matcher << " matched " << node->get_name();
<< node->get_name();
if (matcher->process_match()) if (matcher->process_match())
{ {
changed = true; changed = true;
......
...@@ -66,12 +66,15 @@ namespace ngraph ...@@ -66,12 +66,15 @@ namespace ngraph
/// \param pattern_node is a pattern sub graph that will be matched against input graphs /// \param pattern_node is a pattern sub graph that will be matched against input graphs
/// \param callback is a callback function that will be called on a successful match /// \param callback is a callback function that will be called on a successful match
Matcher(const std::shared_ptr<Node> pattern_node = nullptr, Matcher(const std::shared_ptr<Node> pattern_node = nullptr,
graph_rewrite_callback callback = nullptr) graph_rewrite_callback callback = nullptr,
const std::string& name = "Unnamed")
: m_pattern_node(pattern_node) : m_pattern_node(pattern_node)
, m_callback(callback) , m_callback(callback)
, m_depth(0) , m_depth(0)
, m_name(name)
{ {
} }
virtual ~Matcher() {} virtual ~Matcher() {}
/// \brief Matches a pattern to \p graph_node /// \brief Matches a pattern to \p graph_node
/// ///
...@@ -108,6 +111,7 @@ namespace ngraph ...@@ -108,6 +111,7 @@ namespace ngraph
bool process_match(graph_rewrite_callback callback = nullptr); bool process_match(graph_rewrite_callback callback = nullptr);
void reset() {} void reset() {}
std::string get_name() { return m_name; }
std::shared_ptr<Node> get_pattern() { return m_pattern_node; } std::shared_ptr<Node> get_pattern() { return m_pattern_node; }
std::shared_ptr<Node> get_match_root(); std::shared_ptr<Node> get_match_root();
PatternMap get_pattern_map() { return PatternMap{m_pattern_map}; } PatternMap get_pattern_map() { return PatternMap{m_pattern_map}; }
...@@ -149,6 +153,7 @@ namespace ngraph ...@@ -149,6 +153,7 @@ namespace ngraph
graph_rewrite_callback m_callback; graph_rewrite_callback m_callback;
size_t m_depth; size_t m_depth;
std::string m_name;
}; };
class RecurrentMatcher class RecurrentMatcher
......
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