Skip to content

Commit

Permalink
Rename template config and move transformations to code snippets (ope…
Browse files Browse the repository at this point in the history
…nvinotoolkit#16133)

* Rename template config and move transformations to code snippets

* Fixed documentation

* Rename template config
  • Loading branch information
ilyachur authored and andrei-cv committed Mar 21, 2023
1 parent 1e2062c commit 5507211
Show file tree
Hide file tree
Showing 19 changed files with 27 additions and 30 deletions.
2 changes: 1 addition & 1 deletion docs/Extensibility_UG/graph_rewrite_pass.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
`ov::pass::GraphRewrite` serves for running multiple matcher passes on `ov::Model` in a single graph traversal.
Example:

@snippet src/transformations/template_pattern_transformation.cpp matcher_pass:graph_rewrite
@snippet template_pattern_transformation.cpp matcher_pass:graph_rewrite

In addition, GraphRewrite handles nodes that were registered by MatcherPasses during their execution. This nodes will be added to the beginning of the sequence with nodes for pattern matching.

Expand Down
12 changes: 6 additions & 6 deletions docs/Extensibility_UG/matcher_pass.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
`ov::pass::MatcherPass` is used for pattern-based transformations.

Template for MatcherPass transformation class
@snippet src/transformations/template_pattern_transformation.hpp graph_rewrite:template_transformation_hpp
@snippet template_pattern_transformation.hpp graph_rewrite:template_transformation_hpp

@snippet src/transformations/template_pattern_transformation.cpp graph_rewrite:template_transformation_cpp
@snippet template_pattern_transformation.cpp graph_rewrite:template_transformation_cpp

To use `ov::pass::MatcherPass`, you need to complete these steps:
1. Create a pattern
Expand Down Expand Up @@ -43,7 +43,7 @@ That means that matcher passes registered in `ov::pass::GraphRewrite` will be ap

The example below shows how single MatcherPass can fuse sequence of operations using the `register_new_node` method.

@snippet src/transformations/template_pattern_transformation.cpp matcher_pass:relu_fusion
@snippet template_pattern_transformation.cpp matcher_pass:relu_fusion

> **NOTE**: If you register multiple nodes, please add them in topological order. We do not topologically sort these nodes as it is a time-consuming operation.
Expand All @@ -60,11 +60,11 @@ register_matcher(m, callback);
MatcherPass has multiple ways to be executed:
* Run on a single node - it can be useful if you want to run MatcherPass inside another transformation.
@snippet src/transformations/template_pattern_transformation.cpp matcher_pass:run_on_node
@snippet template_pattern_transformation.cpp matcher_pass:run_on_node
* Run on `ov::Model` using GraphRewrite - this approach gives ability to run MatcherPass on whole `ov::Model`. Moreover, multiple MatcherPass transformation can be registered in a single GraphRewite to be executed in a single graph traversal.
@snippet src/transformations/template_pattern_transformation.cpp matcher_pass:graph_rewrite
@snippet template_pattern_transformation.cpp matcher_pass:graph_rewrite
* Run on `ov::Model` using `ov::pass::Manager` - this approach helps you to register MatcherPass for execution on `ov::Model` as another transformation types.
@snippet src/transformations/template_pattern_transformation.cpp matcher_pass:manager
@snippet template_pattern_transformation.cpp matcher_pass:manager
## Pattern Matching <a name="pattern_matching"></a>
Expand Down
4 changes: 2 additions & 2 deletions docs/Extensibility_UG/model_pass.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

Template for ModelPass transformation class

@snippet src/transformations/template_model_transformation.hpp model_pass:template_transformation_hpp
@snippet template_model_transformation.hpp model_pass:template_transformation_hpp

@snippet src/transformations/template_model_transformation.cpp model_pass:template_transformation_cpp
@snippet template_model_transformation.cpp model_pass:template_transformation_cpp

Using `ov::pass::ModelPass`, you need to override the `run_on_model` method where you will write the transformation code.
Return value is `true` if the original model has changed during transformation (new operation was added, or operations replacement was made, or node attributes were changed); otherwise, it is `false`.
Expand Down
6 changes: 3 additions & 3 deletions docs/Extensibility_UG/ov_transformations.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Manual constant folding is more preferable than `ov::pass::ConstantFolding()` be

Below you can find an example of manual constant folding:

@snippet src/transformations/template_pattern_transformation.cpp manual_constant_folding
@snippet template_pattern_transformation.cpp manual_constant_folding

## Common mistakes in transformations <a name="common_mistakes"></a>

Expand All @@ -145,11 +145,11 @@ In addition, `ov::pass::Manager` has extended debug capabilities (find more info

The example below shows basic usage of `ov::pass::Manager`

@snippet src/transformations/template_pattern_transformation.cpp matcher_pass:manager3
@snippet template_pattern_transformation.cpp matcher_pass:manager3

Another example shows how multiple matcher passes can be united into single GraphRewrite.

@snippet src/transformations/template_pattern_transformation.cpp matcher_pass:manager2
@snippet template_pattern_transformation.cpp matcher_pass:manager2

## How to debug transformations <a name="how-to-debug-transformations"></a>

Expand Down
2 changes: 1 addition & 1 deletion docs/IE_PLUGIN_DG/Plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The provided plugin class also has several fields:
* `_waitExecutor` - a task executor that waits for a response from a device about device tasks completion.
* `_cfg` of type `Configuration`:

@snippet template/src/template_config.hpp configuration:header
@snippet template/src/config.hpp configuration:header

As an example, a plugin configuration has three value parameters:

Expand Down
1 change: 1 addition & 0 deletions docs/snippets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ target_include_directories(${TARGET_NAME} PRIVATE "${OpenVINO_SOURCE_DIR}/src/in
"${OpenVINO_SOURCE_DIR}/src/common/low_precision_transformations/include"
"${OpenVINO_SOURCE_DIR}/src/frontends/common/include"
"${OpenVINO_SOURCE_DIR}/src/core/template_extension/new/")
ov_mark_target_as_cc(${TARGET_NAME})

if(TARGET OpenCL::OpenCL)
target_link_libraries(${TARGET_NAME} PRIVATE OpenCL::OpenCL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// SPDX-License-Identifier: Apache-2.0
//

#include "transformations/template_pattern_transformation.hpp"
#include "template_pattern_transformation.hpp"

#include "openvino/cc/pass/itt.hpp"
#include "openvino/core/rt_info.hpp"
#include "openvino/opsets/opset3.hpp"
#include "openvino/pass/manager.hpp"
#include "openvino/pass/pattern/op/wrap_type.hpp"
#include "transformations/template_model_transformation.hpp"
#include "template_model_transformation.hpp"

// ! [graph_rewrite:template_transformation_cpp]
// template_pattern_transformation.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/template/src/async_infer_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#include "async_infer_request.hpp"

#include "itt.hpp"
#include "openvino/runtime/iinfer_request.hpp"
#include "sync_infer_request.hpp"
#include "template_itt.hpp"

// ! [async_infer_request:ctor]
ov::template_plugin::AsyncInferRequest::AsyncInferRequest(
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/template/src/compiled_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#include "async_infer_request.hpp"
#include "ie_ngraph_utils.hpp"
#include "ie_plugin_config.hpp"
#include "itt.hpp"
#include "openvino/runtime/properties.hpp"
#include "plugin.hpp"
#include "template/config.hpp"
#include "template_itt.hpp"
#include "transformations/utils/utils.hpp"

// ! [executable_network:ctor_cnnnetwork]
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/template/src/compiled_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

#pragma once

#include "config.hpp"
#include "openvino/runtime/icompiled_model.hpp"
#include "openvino/runtime/iinfer_request.hpp"
#include "openvino/runtime/isync_infer_request.hpp"
#include "openvino/runtime/tensor.hpp"
#include "template_config.hpp"

namespace ov {
namespace template_plugin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//

#include "template_config.hpp"
#include "config.hpp"

#include <cpp_interfaces/interface/ie_internal_plugin_config.hpp>
#include <ie_plugin_config.hpp>
Expand All @@ -13,7 +13,7 @@ using namespace ov::template_plugin;

Configuration::Configuration() {}

Configuration::Configuration(const ConfigMap& config, const Configuration& defaultCfg, bool throwOnUnsupported) {
Configuration::Configuration(const ov::AnyMap& config, const Configuration& defaultCfg, bool throwOnUnsupported) {
*this = defaultCfg;
// If plugin needs to use ov::threading::StreamsExecutor it should be able to process its configuration
auto streamExecutorConfigKeys =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace ov {
namespace template_plugin {

// ! [configuration:header]
using ConfigMap = std::map<std::string, ov::Any>;

struct Configuration {
Configuration();
Expand All @@ -23,7 +22,7 @@ struct Configuration {
Configuration& operator=(const Configuration&) = default;
Configuration& operator=(Configuration&&) = default;

explicit Configuration(const ConfigMap& config,
explicit Configuration(const ov::AnyMap& config,
const Configuration& defaultCfg = {},
const bool throwOnUnsupported = true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* @brief Defines openvino domains for tracing
* @file template_itt.hpp
* @file itt.hpp
*/

#pragma once
Expand Down
7 changes: 2 additions & 5 deletions src/plugins/template/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@

#include "cpp_interfaces/interface/ie_iplugin_internal.hpp"
#include "ie_plugin_config.hpp"
#include "itt.hpp"
#include "openvino/pass/manager.hpp"
#include "openvino/runtime/properties.hpp"
#include "template/config.hpp"
#include "template_itt.hpp"
#include "transformations/common_optimizations/common_optimizations.hpp"
#include "transformations/common_optimizations/convert_compression_only_to_legacy.hpp"
#include "transformations/control_flow/unroll_if.hpp"
#include "transformations/disable_decompression_convert_constant_folding.hpp"
#include "transformations/op_conversions/convert_reduce_to_pooling.hpp"
#include "transformations/template_pattern_transformation.hpp"

namespace {
static constexpr const char* wait_executor_name = "TemplateWaitExecutor";
Expand Down Expand Up @@ -61,12 +60,10 @@ void transform_model(const std::shared_ptr<ov::Model>& model) {
ov::pass::Manager passManager;
// Example: register CommonOptimizations transformation from transformations library
passManager.register_pass<ov::pass::CommonOptimizations>();
// Disable some transformations
passManager.get_pass_config()->disable<ov::pass::UnrollIf>();
// This transformation changes output name
passManager.get_pass_config()->disable<ov::pass::ConvertReduceSumToPooling>();
// Example: register plugin specific transformation
passManager.register_pass<ov::pass::DecomposeDivideMatcher>();
passManager.register_pass<ov::pass::ReluReluFusionMatcher>();
// Register any other transformations
// ..

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/template/src/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

#include "backend.hpp"
#include "compiled_model.hpp"
#include "config.hpp"
#include "openvino/runtime/icompiled_model.hpp"
#include "openvino/runtime/iplugin.hpp"
#include "openvino/runtime/threading/itask_executor.hpp"
#include "template_config.hpp"

//! [plugin:header]
namespace ov {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/template/src/sync_infer_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#include <string>
#include <utility>

#include "itt.hpp"
#include "ngraph/runtime/host_tensor.hpp"
#include "openvino/core/except.hpp"
#include "openvino/runtime/profiling_info.hpp"
#include "plugin.hpp"
#include "template_itt.hpp"

using Time = std::chrono::high_resolution_clock;

Expand Down

0 comments on commit 5507211

Please sign in to comment.