From 6c83e0f8a55aaee7c8156f9deca36006a4c21b30 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Tue, 27 Apr 2021 18:52:45 +0300 Subject: [PATCH] Small refactoring in TEMPLATE plugin (#5398) * Small refactoring in TEMPLATE plugin * Fixed compilation on Windows * Fixed code style --- .../src/template_executable_network.hpp | 1 + .../src/template_infer_request.cpp | 11 ---- .../src/template_infer_request.hpp | 13 +++-- docs/template_plugin/src/template_plugin.cpp | 51 +++---------------- .../test_utils/test_utils_api_impl.cpp | 6 +-- inference-engine/include/ie_common.h | 5 ++ inference-engine/include/ie_icnn_network.hpp | 5 -- 7 files changed, 22 insertions(+), 70 deletions(-) diff --git a/docs/template_plugin/src/template_executable_network.hpp b/docs/template_plugin/src/template_executable_network.hpp index d2fb8629000..a7332e9bab1 100644 --- a/docs/template_plugin/src/template_executable_network.hpp +++ b/docs/template_plugin/src/template_executable_network.hpp @@ -14,6 +14,7 @@ namespace TemplatePlugin { +// forward declaration class Plugin; /** diff --git a/docs/template_plugin/src/template_infer_request.cpp b/docs/template_plugin/src/template_infer_request.cpp index 58ea5fe40d7..9218c795520 100644 --- a/docs/template_plugin/src/template_infer_request.cpp +++ b/docs/template_plugin/src/template_infer_request.cpp @@ -8,17 +8,6 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "template/template_config.hpp" #include "template_infer_request.hpp" #include "template_executable_network.hpp" #include "template_plugin.hpp" diff --git a/docs/template_plugin/src/template_infer_request.hpp b/docs/template_plugin/src/template_infer_request.hpp index 41232f20c9c..61187df7985 100644 --- a/docs/template_plugin/src/template_infer_request.hpp +++ b/docs/template_plugin/src/template_infer_request.hpp @@ -7,22 +7,21 @@ #include #include #include +#include #include -#include +#include -#include -#include -#include #include +#include +#include + #include #include -#include "template_config.hpp" - - namespace TemplatePlugin { +// forward declaration class ExecutableNetwork; // ! [infer_request:header] diff --git a/docs/template_plugin/src/template_plugin.cpp b/docs/template_plugin/src/template_plugin.cpp index d9a8af3c8e2..93623b78068 100644 --- a/docs/template_plugin/src/template_plugin.cpp +++ b/docs/template_plugin/src/template_plugin.cpp @@ -81,50 +81,19 @@ InferenceEngine::ExecutableNetworkInternal::Ptr Plugin::LoadExeNetworkImpl(const const ConfigMap &config) { OV_ITT_SCOPED_TASK(itt::domains::TemplatePlugin, "Plugin::LoadExeNetworkImpl"); - auto cfg = Configuration{ config, _cfg }; - InferenceEngine::InputsDataMap networkInputs = network.getInputsInfo(); - InferenceEngine::OutputsDataMap networkOutputs = network.getOutputsInfo(); - - // TODO: check with precisions supported by Template device - - for (auto networkOutput : networkOutputs) { - auto output_precision = networkOutput.second->getPrecision(); - - if (output_precision != InferenceEngine::Precision::FP32 && - output_precision != InferenceEngine::Precision::FP16 && - output_precision != InferenceEngine::Precision::U8) { - IE_THROW() << "Template device supports only U8, FP16 and FP32 output precision."; - } - } - - for (auto networkInput : networkInputs) { - auto input_precision = networkInput.second->getTensorDesc().getPrecision(); - - if (input_precision != InferenceEngine::Precision::FP32 && - input_precision != InferenceEngine::Precision::FP16 && - input_precision != InferenceEngine::Precision::I16 && - input_precision != InferenceEngine::Precision::U8) { - IE_THROW() << "Input image format " << input_precision << " is not supported yet.\n" - << "Supported formats are: FP32, FP16, I16 and U8."; - } - } - - auto function = network.getFunction(); - if (function == nullptr) { - IE_THROW() << "TEMPLATE plugin can compile only IR v10 networks"; - } - - return std::make_shared(function, cfg, std::static_pointer_cast(shared_from_this())); + auto fullConfig = Configuration{ config, _cfg }; + return std::make_shared(network.getFunction(), fullConfig, + std::static_pointer_cast(shared_from_this())); } // ! [plugin:load_exe_network_impl] // ! [plugin:import_network_impl] InferenceEngine::ExecutableNetworkInternal::Ptr -Plugin::ImportNetworkImpl(std::istream& model, const std::map& config) { +Plugin::ImportNetworkImpl(std::istream& modelStream, const std::map& config) { OV_ITT_SCOPED_TASK(itt::domains::TemplatePlugin, "Plugin::ImportNetworkImpl"); - Configuration cfg(config); - return std::make_shared(model, cfg, + auto fullConfig = Configuration{ config, _cfg }; + return std::make_shared(modelStream, fullConfig, std::static_pointer_cast(shared_from_this())); } // ! [plugin:import_network_impl] @@ -133,13 +102,8 @@ Plugin::ImportNetworkImpl(std::istream& model, const std::map originalOps; @@ -207,6 +171,7 @@ InferenceEngine::QueryNetworkResult Plugin::QueryNetwork(const InferenceEngine:: } // 7. Produce the result + InferenceEngine::QueryNetworkResult res; for (auto&& layerName : supported) { res.supportedLayersMap.emplace(layerName, GetName()); } diff --git a/inference-engine/ie_bridges/python/src/openvino/test_utils/test_utils_api_impl.cpp b/inference-engine/ie_bridges/python/src/openvino/test_utils/test_utils_api_impl.cpp index 48cba8526f7..86c74cb3207 100644 --- a/inference-engine/ie_bridges/python/src/openvino/test_utils/test_utils_api_impl.cpp +++ b/inference-engine/ie_bridges/python/src/openvino/test_utils/test_utils_api_impl.cpp @@ -4,11 +4,9 @@ #include "test_utils_api_impl.hpp" +#include #include -#include - -std::pair InferenceEnginePython::CompareNetworks(InferenceEnginePython::IENetwork lhs, - InferenceEnginePython::IENetwork rhs) { +std::pair InferenceEnginePython::CompareNetworks(InferenceEnginePython::IENetwork lhs, InferenceEnginePython::IENetwork rhs) { return compare_functions(lhs.actual->getFunction(), rhs.actual->getFunction(), true, true, false, true); } diff --git a/inference-engine/include/ie_common.h b/inference-engine/include/ie_common.h index d14f26e70e6..efae34f4d3f 100644 --- a/inference-engine/include/ie_common.h +++ b/inference-engine/include/ie_common.h @@ -286,6 +286,11 @@ struct QueryNetworkResult { */ using ConstOutputsDataMap = std::map; +/** + * @brief A collection that contains string as key, and Data smart pointer as value + */ +using OutputsDataMap = std::map; + namespace details { struct INFERENCE_ENGINE_DEPRECATED("Use InferRequest::Exception") INFERENCE_ENGINE_API_CLASS(InferenceEngineException) : public std::runtime_error { diff --git a/inference-engine/include/ie_icnn_network.hpp b/inference-engine/include/ie_icnn_network.hpp index 25ee2715167..432f43c6da3 100644 --- a/inference-engine/include/ie_icnn_network.hpp +++ b/inference-engine/include/ie_icnn_network.hpp @@ -34,11 +34,6 @@ class Function; namespace InferenceEngine { -/** - * @brief A collection that contains string as key, and Data smart pointer as value - */ -using OutputsDataMap = std::map; - /** * @deprecated Use InferenceEngine::CNNNetwork wrapper instead * @interface ICNNNetwork