diff --git a/ngraph/core/src/itt.hpp b/ngraph/core/src/itt.hpp index 8670efc3cd4..2c20ae5ae2b 100644 --- a/ngraph/core/src/itt.hpp +++ b/ngraph/core/src/itt.hpp @@ -41,7 +41,8 @@ OV_ITT_DOMAIN(SIMPLE_ngraph_pass); " is disabled!") #define NGRAPH_PASS_CALLBACK(matcher) #else -#define NGRAPH_OP_SCOPE(region) OV_ITT_SCOPED_TASK(ngraph::itt::domains::ngraph_op, #region) +#define NGRAPH_OP_SCOPE(region) \ + OV_ITT_SCOPED_TASK(ngraph::itt::domains::ngraph_op, OV_PP_TOSTRING(region)) #define NGRAPH_PASS_CALLBACK(matcher) #endif diff --git a/ngraph/core/src/pass/graph_rewrite.cpp b/ngraph/core/src/pass/graph_rewrite.cpp index f8804532bfd..75798fcec8e 100644 --- a/ngraph/core/src/pass/graph_rewrite.cpp +++ b/ngraph/core/src/pass/graph_rewrite.cpp @@ -15,6 +15,7 @@ #include "ngraph/log.hpp" #include "ngraph/op/util/sub_graph_base.hpp" #include "ngraph/pass/graph_rewrite.hpp" +#include "perf_counters.hpp" using namespace std; using namespace ngraph; @@ -55,6 +56,21 @@ NGRAPH_RTTI_DEFINITION(ngraph::pass::GraphRewrite, "ngraph::pass::GraphRewrite", NGRAPH_RTTI_DEFINITION(ngraph::pass::MatcherPass, "ngraph::pass::MatcherPass", 0); +namespace ngraph +{ + namespace pass + { + namespace + { + PerfCounters& perf_counters() + { + static PerfCounters counters; + return counters; + } + } // namespace + } // namespace pass +} // namespace ngraph + bool pass::GraphRewrite::run_on_function(shared_ptr f) { OV_ITT_SCOPED_TASK(itt::domains::nGraph, "pass::GraphRewrite::run_on_function"); @@ -394,7 +410,7 @@ void ngraph::pass::MatcherPass::register_matcher(const std::shared_ptr node) { - OV_ITT_SCOPED_TASK(itt::domains::nGraph, "ngraph::pass::MatcherPass::apply"); + OV_ITT_SCOPED_TASK(itt::domains::nGraph, pass::perf_counters()[get_type_info()]); m_new_nodes.clear(); if (m_handler) return m_handler(node); diff --git a/ngraph/core/src/pass/manager.cpp b/ngraph/core/src/pass/manager.cpp index a3c37635527..aefcb51d77d 100644 --- a/ngraph/core/src/pass/manager.cpp +++ b/ngraph/core/src/pass/manager.cpp @@ -20,6 +20,7 @@ #include "ngraph/pass/pass.hpp" #include "ngraph/pass/visualize_tree.hpp" #include "ngraph/util.hpp" +#include "perf_counters.hpp" using namespace std; using namespace ngraph; @@ -30,32 +31,6 @@ namespace ngraph { namespace { - class PerfCounters - { - PerfCounters(PerfCounters const&) = delete; - PerfCounters& operator=(PerfCounters const&) = delete; - - public: - PerfCounters() = default; - - openvino::itt::handle_t operator[](::ngraph::Node::type_info_t const& type_inf) - { - std::lock_guard guard(m_mutex); - auto it = m_counters.find(&type_inf); - if (it != m_counters.end()) - return it->second; - return m_counters[&type_inf] = openvino::itt::handle(type_inf.name); - } - - private: - using key = ::ngraph::Node::type_info_t const*; - using value = openvino::itt::handle_t; - using counters_map = std::unordered_map; - - std::mutex m_mutex; - counters_map m_counters; - }; - PerfCounters& perf_counters() { static PerfCounters counters; diff --git a/ngraph/core/src/pass/perf_counters.cpp b/ngraph/core/src/pass/perf_counters.cpp new file mode 100644 index 00000000000..9fb3a81c226 --- /dev/null +++ b/ngraph/core/src/pass/perf_counters.cpp @@ -0,0 +1,20 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// +#include "perf_counters.hpp" + +namespace ngraph +{ + namespace pass + { + openvino::itt::handle_t + PerfCounters::operator[](::ngraph::Node::type_info_t const& type_inf) + { + std::lock_guard guard(m_mutex); + auto it = m_counters.find(&type_inf); + if (it != m_counters.end()) + return it->second; + return m_counters[&type_inf] = openvino::itt::handle(type_inf.name); + } + } +} diff --git a/ngraph/core/src/pass/perf_counters.hpp b/ngraph/core/src/pass/perf_counters.hpp new file mode 100644 index 00000000000..5d1cef265c0 --- /dev/null +++ b/ngraph/core/src/pass/perf_counters.hpp @@ -0,0 +1,34 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// +#pragma once +#include +#include + +#include +#include + +namespace ngraph +{ + namespace pass + { + class PerfCounters + { + PerfCounters(PerfCounters const&) = delete; + PerfCounters& operator=(PerfCounters const&) = delete; + + public: + PerfCounters() = default; + + openvino::itt::handle_t operator[](::ngraph::Node::type_info_t const& type_inf); + + private: + using key = ::ngraph::Node::type_info_t const*; + using value = openvino::itt::handle_t; + using counters_map = std::unordered_map; + + std::mutex m_mutex; + counters_map m_counters; + }; + } +}