From 2b81b947dc64c5a9b995f092a35d5d5e988b3cc9 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Wed, 12 Aug 2020 12:00:30 +0300 Subject: [PATCH] Define a macro to define plugin creation function (#1727) --- docs/IE_PLUGIN_DG/Plugin.md | 2 +- docs/template_plugin/src/template_plugin.cpp | 12 ++---------- inference-engine/src/cldnn_engine/cldnn_engine.cpp | 15 ++------------- .../src/gna_plugin/gna_plugin_entry_points.cpp | 10 +--------- inference-engine/src/hetero_plugin/hetero_plugin.cpp | 14 ++------------ inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp | 14 ++------------ inference-engine/src/multi_device/multi_device.cpp | 16 ++-------------- .../cpp_interfaces/interface/ie_iplugin_internal.hpp | 20 ++++++++++++++++++++ .../cpp_interfaces/interface/ie_plugin.hpp | 9 --------- .../src/vpu/myriad_plugin/api/myriad_api.cpp | 14 ++------------ 10 files changed, 34 insertions(+), 92 deletions(-) diff --git a/docs/IE_PLUGIN_DG/Plugin.md b/docs/IE_PLUGIN_DG/Plugin.md index 3c51085..7df6439 100644 --- a/docs/IE_PLUGIN_DG/Plugin.md +++ b/docs/IE_PLUGIN_DG/Plugin.md @@ -191,7 +191,7 @@ information must be stored and checked during the import. Create Instance of Plugin Class ------------------------ -Inference Engine plugin library must export only one function creating a plugin instance: +Inference Engine plugin library must export only one function creating a plugin instance using IE_DEFINE_PLUGIN_CREATE_FUNCTION macro: @snippet src/template_plugin.cpp plugin:create_plugin_engine diff --git a/docs/template_plugin/src/template_plugin.cpp b/docs/template_plugin/src/template_plugin.cpp index b062004..21ae573 100644 --- a/docs/template_plugin/src/template_plugin.cpp +++ b/docs/template_plugin/src/template_plugin.cpp @@ -254,14 +254,6 @@ InferenceEngine::Parameter Plugin::GetMetric(const std::string& name, const std: // ! [plugin:get_metric] // ! [plugin:create_plugin_engine] -INFERENCE_PLUGIN_API(StatusCode) CreatePluginEngine(IInferencePlugin *&plugin, ResponseDesc *resp) noexcept { - try { - plugin = make_ie_compatible_plugin({2, 1, CI_BUILD_NUMBER, "templatePlugin"}, - std::make_shared()); - return OK; - } - catch (std::exception &ex) { - return DescriptionBuffer(GENERAL_ERROR, resp) << ex.what(); - } -} +static const Version version = {{2, 1}, CI_BUILD_NUMBER, "templatePlugin"}; +IE_DEFINE_PLUGIN_CREATE_FUNCTION(Plugin, version) // ! [plugin:create_plugin_engine] diff --git a/inference-engine/src/cldnn_engine/cldnn_engine.cpp b/inference-engine/src/cldnn_engine/cldnn_engine.cpp index 81b5ccf..050c948 100644 --- a/inference-engine/src/cldnn_engine/cldnn_engine.cpp +++ b/inference-engine/src/cldnn_engine/cldnn_engine.cpp @@ -566,16 +566,5 @@ Parameter clDNNEngine::GetMetric(const std::string& name, const std::map()); - return OK; - } - catch (std::exception & ex) { - return DescriptionBuffer(GENERAL_ERROR, resp) << ex.what(); - } -} - +static const Version version = { {2, 1}, CI_BUILD_NUMBER, "clDNNPlugin" }; +IE_DEFINE_PLUGIN_CREATE_FUNCTION(CLDNNPlugin::clDNNEngine, version) diff --git a/inference-engine/src/gna_plugin/gna_plugin_entry_points.cpp b/inference-engine/src/gna_plugin/gna_plugin_entry_points.cpp index 60c5afd..f405963 100644 --- a/inference-engine/src/gna_plugin/gna_plugin_entry_points.cpp +++ b/inference-engine/src/gna_plugin/gna_plugin_entry_points.cpp @@ -20,12 +20,4 @@ static const Version gnaPluginDescription = { "GNAPlugin" }; -INFERENCE_PLUGIN_API(StatusCode) CreatePluginEngine(IInferencePlugin *&plugin, ResponseDesc *resp) noexcept { - try { - plugin = make_ie_compatible_plugin(gnaPluginDescription, make_shared()); - return OK; - } - catch (std::exception &ex) { - return DescriptionBuffer(GENERAL_ERROR, resp) << ex.what(); - } -} +IE_DEFINE_PLUGIN_CREATE_FUNCTION(GNAPluginInternal, gnaPluginDescription) diff --git a/inference-engine/src/hetero_plugin/hetero_plugin.cpp b/inference-engine/src/hetero_plugin/hetero_plugin.cpp index 4cbce19..c726339 100644 --- a/inference-engine/src/hetero_plugin/hetero_plugin.cpp +++ b/inference-engine/src/hetero_plugin/hetero_plugin.cpp @@ -290,15 +290,5 @@ Parameter Engine::GetConfig(const std::string& name, const std::map()); - return OK; - } - catch (std::exception &ex) { - return DescriptionBuffer(GENERAL_ERROR, resp) << ex.what(); - } -} +static const Version version = {{2, 1}, CI_BUILD_NUMBER, "heteroPlugin"}; +IE_DEFINE_PLUGIN_CREATE_FUNCTION(Engine, version) diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp index 4396883..66c9b28 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp @@ -332,15 +332,5 @@ void Engine::QueryNetwork(const ICNNNetwork& network, const std::map()); - return OK; - } - catch (std::exception &ex) { - return DescriptionBuffer(GENERAL_ERROR, resp) << ex.what(); - } -} +static const Version version = {{2, 1}, CI_BUILD_NUMBER, "MKLDNNPlugin"}; +IE_DEFINE_PLUGIN_CREATE_FUNCTION(Engine, version) diff --git a/inference-engine/src/multi_device/multi_device.cpp b/inference-engine/src/multi_device/multi_device.cpp index fbbc29e..face87a 100644 --- a/inference-engine/src/multi_device/multi_device.cpp +++ b/inference-engine/src/multi_device/multi_device.cpp @@ -425,20 +425,8 @@ void MultiDeviceInferencePlugin::SetConfig(const std::map()); - return OK; - } - catch (std::exception &ex) { - return DescriptionBuffer(GENERAL_ERROR, resp) << ex.what(); - } -} +static const Version version = {{2, 1}, CI_BUILD_NUMBER, "MultiDevicePlugin"}; +IE_DEFINE_PLUGIN_CREATE_FUNCTION(MultiDeviceInferencePlugin, version) MultiDeviceInferencePlugin::MultiDeviceInferencePlugin() { _pluginName = "MULTI"; diff --git a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iplugin_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iplugin_internal.hpp index 3fcbde3..cf9ccf9 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iplugin_internal.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iplugin_internal.hpp @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -227,3 +228,22 @@ public: }; } // namespace InferenceEngine + +/** + * @def IE_DEFINE_PLUGIN_CREATE_FUNCTION(PluginType, version) + * @brief Defines the exported `CreatePluginEngine` function which is used to create a plugin instance + * @ingroup ie_dev_api_plugin_api + */ +#define IE_DEFINE_PLUGIN_CREATE_FUNCTION(PluginType, version, ...) \ + INFERENCE_PLUGIN_API(InferenceEngine::StatusCode) CreatePluginEngine( \ + InferenceEngine::IInferencePlugin *&plugin, \ + InferenceEngine::ResponseDesc *resp) noexcept { \ + try { \ + InferenceEngine::Version _version = version; \ + plugin = make_ie_compatible_plugin(_version, std::make_shared(__VA_ARGS__)); \ + return OK; \ + } \ + catch (std::exception &ex) { \ + return InferenceEngine::DescriptionBuffer(GENERAL_ERROR, resp) << ex.what(); \ + } \ + } diff --git a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_plugin.hpp b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_plugin.hpp index 324d2ef..982cb90 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_plugin.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_plugin.hpp @@ -187,13 +187,4 @@ public: ~IInferencePlugin() override; }; -/** - * @brief Creates the default instance of the interface (per plugin) - * - * @param plugin Pointer to the plugin - * @param resp Pointer to the response message that holds a description of an error if any occurred - * @return Status code of the operation. InferenceEngine::OK if succeeded - */ -INFERENCE_PLUGIN_API(StatusCode) CreatePluginEngine(IInferencePlugin*& plugin, ResponseDesc* resp) noexcept; - } // namespace InferenceEngine diff --git a/inference-engine/src/vpu/myriad_plugin/api/myriad_api.cpp b/inference-engine/src/vpu/myriad_plugin/api/myriad_api.cpp index e92c6f7..8c722db 100644 --- a/inference-engine/src/vpu/myriad_plugin/api/myriad_api.cpp +++ b/inference-engine/src/vpu/myriad_plugin/api/myriad_api.cpp @@ -10,15 +10,5 @@ using namespace InferenceEngine; using namespace vpu::MyriadPlugin; -IE_SUPPRESS_DEPRECATED_START - -INFERENCE_PLUGIN_API(StatusCode) CreatePluginEngine(IInferencePlugin *&plugin, ResponseDesc *resp) noexcept { - try { - auto mvnc = std::make_shared(); - plugin = make_ie_compatible_plugin({{2, 1}, CI_BUILD_NUMBER, "myriadPlugin"}, std::make_shared(mvnc)); - return OK; - } - catch (std::exception &ex) { - return DescriptionBuffer(GENERAL_ERROR, resp) << ex.what(); - } -} +static const Version version = {{2, 1}, CI_BUILD_NUMBER, "myriadPlugin"}; +IE_DEFINE_PLUGIN_CREATE_FUNCTION(Engine, version, std::make_shared()) -- 2.7.4