Skip to content

Commit

Permalink
Moved CC macros to public API (openvinotoolkit#5929)
Browse files Browse the repository at this point in the history
* Moved CC macros for transformations to public API (to reuse their in plugin transformations)

* Added CC to template plugin

* Moved itt.h from nGraph to openvino/cc

* Fixed build
  • Loading branch information
ilyachur authored and yekruglov committed Jun 7, 2021
1 parent 1254e72 commit cc992b3
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 37 deletions.
2 changes: 2 additions & 0 deletions docs/template_plugin/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ ie_add_plugin(NAME ${TARGET_NAME}
SKIP_INSTALL # ATTENTION: uncomment to install component
VERSION_DEFINES_FOR template_plugin.cpp
ADD_CLANG_FORMAT)
# Enable support of CC for the plugin
ie_mark_target_as_cc(${TARGET_NAME})

target_include_directories(${TARGET_NAME} PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

#include "template_function_transformation.hpp"

#include <openvino/cc/ngraph/itt.hpp>

using namespace ngraph;

// ! [function_pass:template_transformation_cpp]
// template_function_transformation.cpp
NGRAPH_RTTI_DEFINITION(ngraph::pass::MyFunctionTransformation, "MyFunctionTransformation", 0);

bool pass::MyFunctionTransformation::run_on_function(std::shared_ptr<ngraph::Function> f) {
RUN_ON_FUNCTION_SCOPE(MyFunctionTransformation);
// Example transformation code
NodeVector nodes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <ngraph/pass/manager.hpp>
#include <ngraph/pattern/op/wrap_type.hpp>
#include <ngraph/rt_info.hpp>
#include <openvino/cc/ngraph/itt.hpp>

#include "transformations/template_function_transformation.hpp"

Expand All @@ -18,6 +19,7 @@ using namespace ngraph;
NGRAPH_RTTI_DEFINITION(ngraph::pass::DecomposeDivideMatcher, "DecomposeDivideMatcher", 0);

ngraph::pass::DecomposeDivideMatcher::DecomposeDivideMatcher() {
MATCHER_SCOPE(DecomposeDivideMatcher);
// Pattern example
auto input0 = pattern::any_input();
auto input1 = pattern::any_input();
Expand Down Expand Up @@ -59,6 +61,7 @@ ngraph::pass::DecomposeDivideMatcher::DecomposeDivideMatcher() {
NGRAPH_RTTI_DEFINITION(ngraph::pass::ReluReluFusionMatcher, "ReluReluFusionMatcher", 0);

ngraph::pass::ReluReluFusionMatcher::ReluReluFusionMatcher() {
MATCHER_SCOPE(ReluReluFusionMatcher);
auto m_relu1 = ngraph::pattern::wrap_type<ngraph::opset3::Relu>(pattern::consumers_count(1));
auto m_relu2 = ngraph::pattern::wrap_type<ngraph::opset3::Relu>({m_relu1});

Expand Down
22 changes: 3 additions & 19 deletions inference-engine/src/snippets/src/itt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

#pragma once

#include <openvino/cc/selective_build.h>
#include <openvino/itt.hpp>
#include <openvino/cc/ngraph/itt.hpp>

namespace ngraph {
namespace pass {
Expand All @@ -22,7 +21,6 @@ namespace domains {
} // namespace pass
} // namespace ngraph

OV_CC_DOMAINS(ngraph_pass);
OV_CC_DOMAINS(internal_op);

/*
Expand All @@ -31,29 +29,15 @@ OV_CC_DOMAINS(internal_op);
* INTERNAL_OP_SCOPE macro allows to disable parts of internal nGraph operations if they are not used
*/
#if defined(SELECTIVE_BUILD_ANALYZER)
#define RUN_ON_FUNCTION_SCOPE(region) OV_SCOPE(ngraph_pass, OV_PP_CAT(region, _run_on_function))
#define MATCHER_SCOPE(region) \
const std::string matcher_name(OV_PP_TOSTRING(region))

#define INTERNAL_OP_SCOPE(region) OV_SCOPE(internal_op, region)

#elif defined(SELECTIVE_BUILD)

#define MATCHER_SCOPE_(scope, region) \
if (OV_CC_SCOPE_IS_ENABLED(OV_PP_CAT3(scope, _, region)) == 0) \
throw ngraph::ngraph_error(std::string(OV_PP_TOSTRING(OV_PP_CAT3(scope, _, region))) + \
" is disabled!")

#define MATCHER_SCOPE(region) \
const std::string matcher_name(OV_PP_TOSTRING(region)); \
if (OV_CC_SCOPE_IS_ENABLED(OV_PP_CAT3(ngraph_pass, _, region)) == 0) \
return
#define INTERNAL_OP_SCOPE(region) MATCHER_SCOPE_(internal_op, region)
#define RUN_ON_FUNCTION_SCOPE(region) MATCHER_SCOPE_(ngraph_pass, OV_PP_CAT(region, _run_on_function))

#else
#define MATCHER_SCOPE(region) \
const std::string matcher_name(OV_PP_TOSTRING(region))

#define INTERNAL_OP_SCOPE(region)
#define RUN_ON_FUNCTION_SCOPE(region)

#endif
20 changes: 3 additions & 17 deletions inference-engine/src/transformations/src/itt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <openvino/cc/selective_build.h>
#include <openvino/itt.hpp>
#include <openvino/cc/ngraph/itt.hpp>

namespace ngraph {
namespace pass {
Expand All @@ -22,7 +23,6 @@ namespace domains {
} // namespace pass
} // namespace ngraph

OV_CC_DOMAINS(ngraph_pass);
OV_CC_DOMAINS(internal_op);

/*
Expand All @@ -31,29 +31,15 @@ OV_CC_DOMAINS(internal_op);
* INTERNAL_OP_SCOPE macro allows to disable parts of internal nGraph operations if they are not used
*/
#if defined(SELECTIVE_BUILD_ANALYZER)
#define RUN_ON_FUNCTION_SCOPE(region) OV_SCOPE(ngraph_pass, OV_PP_CAT(region, _run_on_function))
#define MATCHER_SCOPE(region) \
const std::string matcher_name(OV_PP_TOSTRING(region))

#define INTERNAL_OP_SCOPE(region) OV_SCOPE(internal_op, region)

#elif defined(SELECTIVE_BUILD)

#define MATCHER_SCOPE_(scope, region) \
if (OV_CC_SCOPE_IS_ENABLED(OV_PP_CAT3(scope, _, region)) == 0) \
throw ngraph::ngraph_error(std::string(OV_PP_TOSTRING(OV_PP_CAT3(scope, _, region))) + \
" is disabled!")

#define MATCHER_SCOPE(region) \
const std::string matcher_name(OV_PP_TOSTRING(region)); \
if (OV_CC_SCOPE_IS_ENABLED(OV_PP_CAT3(ngraph_pass, _, region)) == 0) \
return
#define INTERNAL_OP_SCOPE(region) MATCHER_SCOPE_(internal_op, region)
#define RUN_ON_FUNCTION_SCOPE(region) MATCHER_SCOPE_(ngraph_pass, OV_PP_CAT(region, _run_on_function))

#else
#define MATCHER_SCOPE(region) \
const std::string matcher_name(OV_PP_TOSTRING(region))

#define INTERNAL_OP_SCOPE(region)
#define RUN_ON_FUNCTION_SCOPE(region)

#endif
2 changes: 1 addition & 1 deletion openvino/conditional_compilation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ elseif(SELECTIVE_BUILD STREQUAL "ON")
ov_force_include(${TARGET_NAME} INTERFACE ${GENERATED_HEADER})
endif()

file(GLOB_RECURSE hdrs "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
file(GLOB_RECURSE hdrs ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h ${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp)
add_cpplint_target(${TARGET_NAME}_cpplint FOR_SOURCES ${hdrs})
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <openvino/cc/selective_build.h>
#include <openvino/itt.hpp>

OV_CC_DOMAINS(ngraph_pass);

/*
* RUN_ON_FUNCTION_SCOPE macro allows to disable the run_on_function pass
* MATCHER_SCOPE macro allows to disable the MatcherPass if matcher isn't applied
*/
#if defined(SELECTIVE_BUILD_ANALYZER)

#define RUN_ON_FUNCTION_SCOPE(region) OV_SCOPE(ngraph_pass, OV_PP_CAT(region, _run_on_function))
#define MATCHER_SCOPE(region) const std::string matcher_name(OV_PP_TOSTRING(region))

#elif defined(SELECTIVE_BUILD)

#define MATCHER_SCOPE_(scope, region) \
if (OV_CC_SCOPE_IS_ENABLED(OV_PP_CAT3(scope, _, region)) == 0) \
throw ngraph::ngraph_error(std::string(OV_PP_TOSTRING(OV_PP_CAT3(scope, _, region))) + \
" is disabled!")

#define MATCHER_SCOPE(region) \
const std::string matcher_name(OV_PP_TOSTRING(region)); \
if (OV_CC_SCOPE_IS_ENABLED(OV_PP_CAT3(ngraph_pass, _, region)) == 0) \
return
#define RUN_ON_FUNCTION_SCOPE(region) \
MATCHER_SCOPE_(ngraph_pass, OV_PP_CAT(region, _run_on_function))

#else

#define MATCHER_SCOPE(region) const std::string matcher_name(OV_PP_TOSTRING(region))
#define RUN_ON_FUNCTION_SCOPE(region)
#endif

0 comments on commit cc992b3

Please sign in to comment.