From 2d314d79cba0b9c98fcab63c27338aba56028b2b Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Tue, 7 Mar 2023 13:44:41 +0400 Subject: [PATCH 1/3] Rename template config and move transformations to code snippets --- docs/Extensibility_UG/matcher_pass.md | 4 ++-- docs/Extensibility_UG/model_pass.md | 4 ++-- docs/snippets/CMakeLists.txt | 1 + .../snippets}/template_model_transformation.cpp | 0 .../snippets}/template_model_transformation.hpp | 0 .../snippets}/template_pattern_transformation.cpp | 4 ++-- .../snippets}/template_pattern_transformation.hpp | 0 src/plugins/template/src/async_infer_request.cpp | 2 +- src/plugins/template/src/compiled_model.cpp | 2 +- src/plugins/template/src/compiled_model.hpp | 2 +- .../template/src/{template_config.cpp => config.cpp} | 4 ++-- .../template/src/{template_config.hpp => config.hpp} | 3 +-- src/plugins/template/src/{template_itt.hpp => itt.hpp} | 2 +- src/plugins/template/src/plugin.cpp | 7 ++----- src/plugins/template/src/plugin.hpp | 2 +- src/plugins/template/src/sync_infer_request.cpp | 2 +- 16 files changed, 18 insertions(+), 21 deletions(-) rename {src/plugins/template/src/transformations => docs/snippets}/template_model_transformation.cpp (100%) rename {src/plugins/template/src/transformations => docs/snippets}/template_model_transformation.hpp (100%) rename {src/plugins/template/src/transformations => docs/snippets}/template_pattern_transformation.cpp (97%) rename {src/plugins/template/src/transformations => docs/snippets}/template_pattern_transformation.hpp (100%) rename src/plugins/template/src/{template_config.cpp => config.cpp} (95%) rename src/plugins/template/src/{template_config.hpp => config.hpp} (91%) rename src/plugins/template/src/{template_itt.hpp => itt.hpp} (93%) diff --git a/docs/Extensibility_UG/matcher_pass.md b/docs/Extensibility_UG/matcher_pass.md index f85d0ecaefe5e7..25214b1f497d0d 100644 --- a/docs/Extensibility_UG/matcher_pass.md +++ b/docs/Extensibility_UG/matcher_pass.md @@ -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 diff --git a/docs/Extensibility_UG/model_pass.md b/docs/Extensibility_UG/model_pass.md index d2add64d3a545d..5dc434a9b36754 100644 --- a/docs/Extensibility_UG/model_pass.md +++ b/docs/Extensibility_UG/model_pass.md @@ -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`. diff --git a/docs/snippets/CMakeLists.txt b/docs/snippets/CMakeLists.txt index 7ce9a2c6806942..4c0a58d8da7766 100644 --- a/docs/snippets/CMakeLists.txt +++ b/docs/snippets/CMakeLists.txt @@ -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) diff --git a/src/plugins/template/src/transformations/template_model_transformation.cpp b/docs/snippets/template_model_transformation.cpp similarity index 100% rename from src/plugins/template/src/transformations/template_model_transformation.cpp rename to docs/snippets/template_model_transformation.cpp diff --git a/src/plugins/template/src/transformations/template_model_transformation.hpp b/docs/snippets/template_model_transformation.hpp similarity index 100% rename from src/plugins/template/src/transformations/template_model_transformation.hpp rename to docs/snippets/template_model_transformation.hpp diff --git a/src/plugins/template/src/transformations/template_pattern_transformation.cpp b/docs/snippets/template_pattern_transformation.cpp similarity index 97% rename from src/plugins/template/src/transformations/template_pattern_transformation.cpp rename to docs/snippets/template_pattern_transformation.cpp index 22ca06e91f92b8..40aeec26c82aee 100644 --- a/src/plugins/template/src/transformations/template_pattern_transformation.cpp +++ b/docs/snippets/template_pattern_transformation.cpp @@ -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 diff --git a/src/plugins/template/src/transformations/template_pattern_transformation.hpp b/docs/snippets/template_pattern_transformation.hpp similarity index 100% rename from src/plugins/template/src/transformations/template_pattern_transformation.hpp rename to docs/snippets/template_pattern_transformation.hpp diff --git a/src/plugins/template/src/async_infer_request.cpp b/src/plugins/template/src/async_infer_request.cpp index 29532650b9d9f9..726df3d3173195 100644 --- a/src/plugins/template/src/async_infer_request.cpp +++ b/src/plugins/template/src/async_infer_request.cpp @@ -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( diff --git a/src/plugins/template/src/compiled_model.cpp b/src/plugins/template/src/compiled_model.cpp index 4d420d09304620..13a046d776d09c 100644 --- a/src/plugins/template/src/compiled_model.cpp +++ b/src/plugins/template/src/compiled_model.cpp @@ -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] diff --git a/src/plugins/template/src/compiled_model.hpp b/src/plugins/template/src/compiled_model.hpp index ffc632708e4ae5..47f29b91faba1c 100644 --- a/src/plugins/template/src/compiled_model.hpp +++ b/src/plugins/template/src/compiled_model.hpp @@ -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 { diff --git a/src/plugins/template/src/template_config.cpp b/src/plugins/template/src/config.cpp similarity index 95% rename from src/plugins/template/src/template_config.cpp rename to src/plugins/template/src/config.cpp index d24afae28857a4..27805f6499d86d 100644 --- a/src/plugins/template/src/template_config.cpp +++ b/src/plugins/template/src/config.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "template_config.hpp" +#include "config.hpp" #include #include @@ -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 = diff --git a/src/plugins/template/src/template_config.hpp b/src/plugins/template/src/config.hpp similarity index 91% rename from src/plugins/template/src/template_config.hpp rename to src/plugins/template/src/config.hpp index a0a2bf8b41d26e..d5f3b729ce7eca 100644 --- a/src/plugins/template/src/template_config.hpp +++ b/src/plugins/template/src/config.hpp @@ -14,7 +14,6 @@ namespace ov { namespace template_plugin { // ! [configuration:header] -using ConfigMap = std::map; struct Configuration { Configuration(); @@ -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); diff --git a/src/plugins/template/src/template_itt.hpp b/src/plugins/template/src/itt.hpp similarity index 93% rename from src/plugins/template/src/template_itt.hpp rename to src/plugins/template/src/itt.hpp index b376682439ba82..d8153bcff90ab6 100644 --- a/src/plugins/template/src/template_itt.hpp +++ b/src/plugins/template/src/itt.hpp @@ -4,7 +4,7 @@ /** * @brief Defines openvino domains for tracing - * @file template_itt.hpp + * @file itt.hpp */ #pragma once diff --git a/src/plugins/template/src/plugin.cpp b/src/plugins/template/src/plugin.cpp index d2e6dda5ad6fc5..6821534deeca14 100644 --- a/src/plugins/template/src/plugin.cpp +++ b/src/plugins/template/src/plugin.cpp @@ -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"; @@ -61,12 +60,10 @@ void transform_model(const std::shared_ptr& model) { ov::pass::Manager passManager; // Example: register CommonOptimizations transformation from transformations library passManager.register_pass(); + // Disable some transformations passManager.get_pass_config()->disable(); // This transformation changes output name passManager.get_pass_config()->disable(); - // Example: register plugin specific transformation - passManager.register_pass(); - passManager.register_pass(); // Register any other transformations // .. diff --git a/src/plugins/template/src/plugin.hpp b/src/plugins/template/src/plugin.hpp index b420d5f52b3bd6..6c38c457bdc86a 100644 --- a/src/plugins/template/src/plugin.hpp +++ b/src/plugins/template/src/plugin.hpp @@ -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 { diff --git a/src/plugins/template/src/sync_infer_request.cpp b/src/plugins/template/src/sync_infer_request.cpp index ad951520432c39..ca25d3d25561e3 100644 --- a/src/plugins/template/src/sync_infer_request.cpp +++ b/src/plugins/template/src/sync_infer_request.cpp @@ -10,11 +10,11 @@ #include #include +#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; From 77967981254b183e0e78addbe07b07c09f13a16a Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Tue, 7 Mar 2023 14:32:37 +0400 Subject: [PATCH 2/3] Fixed documentation --- docs/Extensibility_UG/graph_rewrite_pass.md | 2 +- docs/Extensibility_UG/matcher_pass.md | 8 ++++---- docs/Extensibility_UG/ov_transformations.md | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/Extensibility_UG/graph_rewrite_pass.md b/docs/Extensibility_UG/graph_rewrite_pass.md index 11f178be4e3ab2..f6d8be7f99f99d 100644 --- a/docs/Extensibility_UG/graph_rewrite_pass.md +++ b/docs/Extensibility_UG/graph_rewrite_pass.md @@ -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. diff --git a/docs/Extensibility_UG/matcher_pass.md b/docs/Extensibility_UG/matcher_pass.md index 25214b1f497d0d..2552a5e79c7c5c 100644 --- a/docs/Extensibility_UG/matcher_pass.md +++ b/docs/Extensibility_UG/matcher_pass.md @@ -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. @@ -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 diff --git a/docs/Extensibility_UG/ov_transformations.md b/docs/Extensibility_UG/ov_transformations.md index 75f01ecae0e365..43945d48b47b50 100644 --- a/docs/Extensibility_UG/ov_transformations.md +++ b/docs/Extensibility_UG/ov_transformations.md @@ -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 @@ -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 From e4f82d671351332997b590570f1eb7b824345974 Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Tue, 7 Mar 2023 15:19:02 +0400 Subject: [PATCH 3/3] Rename template config --- docs/IE_PLUGIN_DG/Plugin.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/IE_PLUGIN_DG/Plugin.md b/docs/IE_PLUGIN_DG/Plugin.md index c0dea4233434d5..1e62ab63e3662e 100644 --- a/docs/IE_PLUGIN_DG/Plugin.md +++ b/docs/IE_PLUGIN_DG/Plugin.md @@ -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: