diff --git a/cmake/developer_package/compile_flags/os_flags.cmake b/cmake/developer_package/compile_flags/os_flags.cmake index d2c51130a9567d..0f9dabee701a2c 100644 --- a/cmake/developer_package/compile_flags/os_flags.cmake +++ b/cmake/developer_package/compile_flags/os_flags.cmake @@ -332,9 +332,11 @@ else() if(APPLE) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-dead_strip") set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-dead_strip") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-dead_strip") elseif(LINUX) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections -Wl,--exclude-libs,ALL") set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--gc-sections -Wl,--exclude-libs,ALL") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -Wl,--exclude-libs,ALL") endif() endif() @@ -354,10 +356,7 @@ function(link_system_libraries TARGET_NAME) ) endif() - target_link_libraries(${TARGET_NAME} - ${MODE} - ${arg} - ) + target_link_libraries(${TARGET_NAME} ${MODE} ${arg}) endif() endforeach() endfunction() diff --git a/cmake/developer_package/plugins/create_plugins_hpp.cmake b/cmake/developer_package/plugins/create_plugins_hpp.cmake index bd5c1d5ca2e0b5..0e2abfd591d215 100644 --- a/cmake/developer_package/plugins/create_plugins_hpp.cmake +++ b/cmake/developer_package/plugins/create_plugins_hpp.cmake @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # -foreach(var IE_DEVICE_NAMES IE_PLUGINS_HPP_HEADER IE_PLUGINS_HPP_HEADER_IN) +foreach(var IE_DEVICE_MAPPING IE_PLUGINS_HPP_HEADER IE_PLUGINS_HPP_HEADER_IN) if(NOT DEFINED ${var}) message(FATAL_ERROR "${var} is required, but not defined") endif() @@ -12,18 +12,40 @@ endforeach() set(IE_PLUGINS_DECLARATIONS "") set(IE_PLUGINS_MAP_DEFINITION - "std::map plugins_hpp = {") + " static const std::map plugins_hpp = {") -foreach(dev_name IN LISTS IE_DEVICE_NAMES) - set(_IE_CREATE_PLUGIN_FUNC "CreatePluginEngine${dev_name}") +foreach(dev_map IN LISTS IE_DEVICE_MAPPING) + string(REPLACE ":" ";" dev_map "${dev_map}") + list(GET dev_map 0 mapped_dev_name) + list(GET dev_map 1 actual_dev_name) + + # common + set(_IE_CREATE_PLUGIN_FUNC "CreatePluginEngine${actual_dev_name}") + + # declarations set(IE_PLUGINS_DECLARATIONS "${IE_PLUGINS_DECLARATIONS} IE_DEFINE_PLUGIN_CREATE_FUNCTION_DECLARATION(${_IE_CREATE_PLUGIN_FUNC})") + + # definitions + set(dev_config "{") + if(${mapped_dev_name}_CONFIG) + foreach(props IN LISTS ${mapped_dev_name}_CONFIG) + string(REPLACE ":" ";" props "${props}") + + list(GET props 0 key) + list(GET props 1 value) + + set(dev_config "${dev_config} { \"${key}\", \"${value}\" }, ") + endforeach() + endif() + set(dev_config "${dev_config}}") + set(IE_PLUGINS_MAP_DEFINITION "${IE_PLUGINS_MAP_DEFINITION} - { \"${dev_name}\", ${_IE_CREATE_PLUGIN_FUNC} },") + { \"${mapped_dev_name}\", Value { ${_IE_CREATE_PLUGIN_FUNC}, ${dev_config} } },") endforeach() set(IE_PLUGINS_MAP_DEFINITION "${IE_PLUGINS_MAP_DEFINITION} -};\n") + };\n") message("${IE_PLUGINS_DECLARATIONS}") diff --git a/cmake/developer_package/plugins/plugins.cmake b/cmake/developer_package/plugins/plugins.cmake index a2c0d2076cdc78..834874a39dd805 100644 --- a/cmake/developer_package/plugins/plugins.cmake +++ b/cmake/developer_package/plugins/plugins.cmake @@ -20,7 +20,7 @@ endif() # # ie_add_plugin(NAME # DEVICE_NAME -# [PSEUDO] +# [PSEUDO_PLUGIN_FOR] # [DEFAULT_CONFIG ] # [SOURCES ] # [OBJECT_LIBRARIES ] @@ -29,8 +29,8 @@ endif() # ) # function(ie_add_plugin) - set(options SKIP_INSTALL ADD_CLANG_FORMAT PSEUDO_PLUGIN) - set(oneValueArgs NAME DEVICE_NAME VERSION_DEFINES_FOR) + set(options SKIP_INSTALL ADD_CLANG_FORMAT) + set(oneValueArgs NAME DEVICE_NAME VERSION_DEFINES_FOR PSEUDO_PLUGIN_FOR) set(multiValueArgs DEFAULT_CONFIG SOURCES OBJECT_LIBRARIES CPPLINT_FILTERS) cmake_parse_arguments(IE_PLUGIN "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) @@ -44,7 +44,7 @@ function(ie_add_plugin) # create and configure target - if(NOT IE_PLUGIN_PSEUDO_PLUGIN) + if(NOT IE_PLUGIN_PSEUDO_PLUGIN_FOR) if(IE_PLUGIN_VERSION_DEFINES_FOR) addVersionDefines(${IE_PLUGIN_VERSION_DEFINES_FOR} CI_BUILD_NUMBER) endif() @@ -148,6 +148,7 @@ function(ie_add_plugin) list(APPEND PLUGIN_FILES "${IE_PLUGIN_DEVICE_NAME}:${IE_PLUGIN_NAME}") set(PLUGIN_FILES "${PLUGIN_FILES}" CACHE INTERNAL "" FORCE) set(${IE_PLUGIN_DEVICE_NAME}_CONFIG "${IE_PLUGIN_DEFAULT_CONFIG}" CACHE INTERNAL "" FORCE) + set(${IE_PLUGIN_DEVICE_NAME}_PSEUDO_PLUGIN_FOR "${IE_PLUGIN_PSEUDO_PLUGIN_FOR}" CACHE INTERNAL "" FORCE) endfunction() # @@ -230,7 +231,8 @@ macro(ie_register_plugins_static) set(multiValueArgs POSSIBLE_PLUGINS) cmake_parse_arguments(IE_REGISTER "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - set(device_names) + set(device_mapping) + set(device_configs) foreach(name IN LISTS PLUGIN_FILES) string(REPLACE ":" ";" name "${name}") list(LENGTH name length) @@ -238,9 +240,20 @@ macro(ie_register_plugins_static) message(FATAL_ERROR "Unexpected error, please, contact developer of this script") endif() + # create device mapping: preudo device => actual device list(GET name 0 device_name) - list(APPEND device_names ${device_name}) + if(${device_name}_PSEUDO_PLUGIN_FOR) + list(APPEND device_mapping "${device_name}:${${device_name}_PSEUDO_PLUGIN_FOR}") + else() + list(APPEND device_mapping "${device_name}:${device_name}") + endif() + + # add default plugin config options + if(${device_name}_CONFIG) + list(APPEND device_configs -D "${device_name}_CONFIG=${${device_name}_CONFIG}") + endif() + # link plugin to inference_engine static version list(GET name 1 plugin_name) target_link_libraries(${IE_REGISTER_MAIN_TARGET} PRIVATE ${plugin_name}) endforeach() @@ -251,9 +264,10 @@ macro(ie_register_plugins_static) add_custom_command(OUTPUT "${ie_plugins_hpp}" COMMAND "${CMAKE_COMMAND}" - -D "IE_DEVICE_NAMES=${device_names}" + -D "IE_DEVICE_MAPPING=${device_mapping}" -D "IE_PLUGINS_HPP_HEADER_IN=${plugins_hpp_in}" -D "IE_PLUGINS_HPP_HEADER=${ie_plugins_hpp}" + ${device_configs} -P "${IEDevScripts_DIR}/plugins/create_plugins_hpp.cmake" DEPENDS "${plugins_hpp_in}" diff --git a/cmake/developer_package/plugins/plugins.hpp.in b/cmake/developer_package/plugins/plugins.hpp.in index 2ddf338e43384d..03bb62bb7f0049 100644 --- a/cmake/developer_package/plugins/plugins.hpp.in +++ b/cmake/developer_package/plugins/plugins.hpp.in @@ -9,6 +9,14 @@ namespace { @IE_PLUGINS_DECLARATIONS@ +using Config = std::map; +using Value = std::pair; +using Key = std::string; +using PluginsStaticRegistry = std::map; + +const std::map getStaticPluginsRegistry() { @IE_PLUGINS_MAP_DEFINITION@ + return plugins_hpp; +} } // namespace diff --git a/inference-engine/src/CMakeLists.txt b/inference-engine/src/CMakeLists.txt index 0465aab7404743..7db652e7a2e1fe 100644 --- a/inference-engine/src/CMakeLists.txt +++ b/inference-engine/src/CMakeLists.txt @@ -7,10 +7,16 @@ if(CMAKE_COMPILER_IS_GNUCXX) ie_add_compiler_flags(-Wmissing-declarations) endif() -add_subdirectory(preprocessing) +add_subdirectory(transformations) add_subdirectory(legacy_api) +add_subdirectory(low_precision_transformations) + +add_subdirectory(offline_transformations) + +add_subdirectory(snippets) + if(ENABLE_MKL_DNN) add_subdirectory(mkldnn_plugin) endif() @@ -37,15 +43,9 @@ endif() add_subdirectory(inference_engine) -add_subdirectory(transformations) - add_subdirectory(readers) -add_subdirectory(low_precision_transformations) - -add_subdirectory(offline_transformations) - -add_subdirectory(snippets) +add_subdirectory(preprocessing) # add a custom target to build all Inference Engine Core libraries diff --git a/inference-engine/src/inference_engine/src/ie_core.cpp b/inference-engine/src/inference_engine/src/ie_core.cpp index c292a08bd5c082..7ab6253490484c 100644 --- a/inference-engine/src/inference_engine/src/ie_core.cpp +++ b/inference-engine/src/inference_engine/src/ie_core.cpp @@ -445,13 +445,14 @@ class CoreImpl : public ie::ICore, public std::enable_shared_from_this& static_registry) { + void RegisterPluginsInRegistry(const decltype(::getStaticPluginsRegistry())& static_registry) { std::lock_guard lock(pluginsMutex); for (const auto& plugin : static_registry) { @@ -459,12 +460,15 @@ class CoreImpl : public ie::ICore, public std::enable_shared_from_this(); #ifdef OPENVINO_STATIC_LIBRARY - _impl->RegisterPluginsInRegistry(::plugins_hpp); + _impl->RegisterPluginsInRegistry(::getStaticPluginsRegistry()); #else RegisterPlugins(ov::runtime::parseXmlConfig(xmlConfigFile)); #endif @@ -1398,7 +1402,7 @@ Core::Core(const std::string& xmlConfigFile) { _impl = std::make_shared(); #ifdef OPENVINO_STATIC_LIBRARY - _impl->RegisterPluginsInRegistry(::plugins_hpp); + _impl->RegisterPluginsInRegistry(::getStaticPluginsRegistry()); #else register_plugins(parseXmlConfig(xmlConfigFile)); #endif diff --git a/inference-engine/src/multi_device/CMakeLists.txt b/inference-engine/src/multi_device/CMakeLists.txt index 7e536a0bdfe67d..c293c81e298808 100644 --- a/inference-engine/src/multi_device/CMakeLists.txt +++ b/inference-engine/src/multi_device/CMakeLists.txt @@ -12,10 +12,9 @@ ie_add_plugin(NAME ${TARGET_NAME} SOURCES ${SOURCES} ${HEADERS} VERSION_DEFINES_FOR multi_device_plugin.cpp) -# TODO: add fix for this case since DEFAULT_CONFIG is not used now ie_add_plugin(NAME ${TARGET_NAME} DEVICE_NAME "AUTO" - PSEUDO_PLUGIN + PSEUDO_PLUGIN_FOR "MULTI" DEFAULT_CONFIG "MULTI_WORK_MODE_AS_AUTO:YES") target_link_libraries(${TARGET_NAME} PRIVATE inference_engine ngraph inference_engine_transformations) diff --git a/inference-engine/src/preprocessing/CMakeLists.txt b/inference-engine/src/preprocessing/CMakeLists.txt index 1d100fe145755a..e3c52c8236d21b 100644 --- a/inference-engine/src/preprocessing/CMakeLists.txt +++ b/inference-engine/src/preprocessing/CMakeLists.txt @@ -107,6 +107,7 @@ target_include_directories(${TARGET_NAME}_obj SYSTEM PRIVATE $) target_include_directories(${TARGET_NAME}_obj PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" + $ $) set_ie_threading_interface_for(${TARGET_NAME}_obj) @@ -121,7 +122,7 @@ else() set(library_type STATIC) endif() -add_library(${TARGET_NAME} MODULE +add_library(${TARGET_NAME} ${library_type} $) ie_add_vs_version_file(NAME ${TARGET_NAME} @@ -134,6 +135,8 @@ target_link_libraries(${TARGET_NAME} PRIVATE fluid openvino::itt openvino::util) if(BUILD_SHARED_LIBS) # for static linkage the dependencies are in opposite order target_link_libraries(${TARGET_NAME} PRIVATE inference_engine) +else() + target_link_libraries(inference_engine PRIVATE ${TARGET_NAME}) endif() target_include_directories(${TARGET_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}" diff --git a/inference-engine/src/preprocessing/ie_preprocess_data.hpp b/inference-engine/src/preprocessing/ie_preprocess_data.hpp index 08bb0a48796d68..347c239f943cf6 100644 --- a/inference-engine/src/preprocessing/ie_preprocess_data.hpp +++ b/inference-engine/src/preprocessing/ie_preprocess_data.hpp @@ -9,6 +9,8 @@ #include #include "openvino/runtime/common.hpp" +#include "openvino/util/file_util.hpp" +#include "openvino/util/shared_object.hpp" #include #include @@ -27,14 +29,12 @@ class IPreProcessData : public std::enable_shared_from_this { * @brief Sets ROI blob to be resized and placed to the default input blob during pre-processing. * @param blob ROI blob. */ - //FIXME: rename to setUserBlob virtual void setRoiBlob(const Blob::Ptr &blob) = 0; /** * @brief Gets pointer to the ROI blob used for a given input. * @return Blob pointer. */ - //FIXME: rename to getUserBlob virtual Blob::Ptr getRoiBlob() const = 0; /** @@ -46,7 +46,6 @@ class IPreProcessData : public std::enable_shared_from_this { */ virtual void execute(Blob::Ptr &preprocessedBlob, const PreProcessInfo& info, bool serial, int batchSize = -1) = 0; - //FIXME: rename to verifyAplicable virtual void isApplicable(const Blob::Ptr &src, const Blob::Ptr &dst) = 0; protected: @@ -55,38 +54,64 @@ class IPreProcessData : public std::enable_shared_from_this { OPENVINO_PLUGIN_API void CreatePreProcessData(std::shared_ptr& data); -namespace details { +#define OV_PREPROC_PLUGIN_CALL_STATEMENT(...) \ + if (!_ptr) \ + IE_THROW() << "Wrapper used in the OV_PREPROC_PLUGIN_CALL_STATEMENT was not initialized."; \ + try { \ + __VA_ARGS__; \ + } catch (...) { \ + ::InferenceEngine::details::Rethrow(); \ + } + +class PreProcessDataPlugin { + std::shared_ptr _so = nullptr; + std::shared_ptr _ptr = nullptr; -/** - * @brief This class defines the name of the fabric for creating an IHeteroInferencePlugin object in DLL - */ -template<> -class SOCreatorTrait { public: - /** - * @brief A name of the fabric for creating IInferencePlugin object in DLL - */ - static constexpr auto name = "CreatePreProcessData"; -}; + PreProcessDataPlugin() { +#ifdef OPENVINO_STATIC_LIBRARY + CreatePreProcessData(_ptr); + if (!_ptr) + IE_THROW() << "Failed to create IPreProcessData for G-API based preprocessing"; +#else + ov::util::FilePath libraryName = ov::util::to_file_path(std::string("inference_engine_preproc") + std::string(IE_BUILD_POSTFIX)); + ov::util::FilePath preprocLibraryPath = FileUtils::makePluginLibraryName(getInferenceEngineLibraryPath(), libraryName); + + if (!FileUtils::fileExist(preprocLibraryPath)) { + IE_THROW() << "Please, make sure that pre-processing library " + << ov::util::from_file_path(::FileUtils::makePluginLibraryName({}, libraryName)) << " is in " + << getIELibraryPath(); + } + + using CreateF = void(std::shared_ptr& data); + _so = ov::util::load_shared_object(preprocLibraryPath.c_str()); + reinterpret_cast(ov::util::get_symbol(_so, "CreatePreProcessData"))(_ptr); +#endif + } -} // namespace details + void setRoiBlob(const Blob::Ptr &blob) { + OV_PREPROC_PLUGIN_CALL_STATEMENT(_ptr->setRoiBlob(blob)); + } -/** - * @brief A C++ helper to work with objects created by the plugin. - * Implements different interfaces. - */ -using PreProcessDataPtr = InferenceEngine::details::SOPointer; + Blob::Ptr getRoiBlob() const { + OV_PREPROC_PLUGIN_CALL_STATEMENT(return _ptr->getRoiBlob()); + } -inline PreProcessDataPtr CreatePreprocDataHelper() { - ov::util::FilePath libraryName = ov::util::to_file_path(std::string("inference_engine_preproc") + std::string(IE_BUILD_POSTFIX)); - ov::util::FilePath preprocLibraryPath = FileUtils::makePluginLibraryName(getInferenceEngineLibraryPath(), libraryName); + void execute(Blob::Ptr &preprocessedBlob, const PreProcessInfo& info, bool serial, int batchSize = -1) { + OV_PREPROC_PLUGIN_CALL_STATEMENT(_ptr->execute(preprocessedBlob, info, serial, batchSize)); + } - if (!FileUtils::fileExist(preprocLibraryPath)) { - IE_THROW() << "Please, make sure that pre-processing library " - << ov::util::from_file_path(::FileUtils::makePluginLibraryName({}, libraryName)) << " is in " - << getIELibraryPath(); + void isApplicable(const Blob::Ptr &src, const Blob::Ptr &dst) { + OV_PREPROC_PLUGIN_CALL_STATEMENT(return _ptr->isApplicable(src, dst)); } - return {preprocLibraryPath}; +}; + +#undef OV_PREPROC_PLUGIN_CALL_STATEMENT + +using PreProcessDataPtr = std::shared_ptr; + +inline PreProcessDataPtr CreatePreprocDataHelper() { + return std::make_shared(); } } // namespace InferenceEngine diff --git a/inference-engine/src/readers/ir_reader_v7/CMakeLists.txt b/inference-engine/src/readers/ir_reader_v7/CMakeLists.txt index b465372432deec..846b831825be81 100644 --- a/inference-engine/src/readers/ir_reader_v7/CMakeLists.txt +++ b/inference-engine/src/readers/ir_reader_v7/CMakeLists.txt @@ -35,7 +35,7 @@ target_compile_definitions(${TARGET_NAME} PRIVATE IMPLEMENT_INFERENCE_ENGINE_PLU target_include_directories(${TARGET_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/") target_link_libraries(${TARGET_NAME} PRIVATE inference_engine_reader_api inference_engine_plugin_api - inference_engine_legacy inference_engine pugixml::static openvino::itt) + inference_engine_legacy pugixml::static openvino::itt) ie_add_api_validator_post_build_step(TARGET ${TARGET_NAME}) @@ -47,6 +47,8 @@ endif() if(NOT BUILD_SHARED_LIBS) target_link_libraries(inference_engine PRIVATE ${TARGET_NAME}) +else() + target_link_libraries(${TARGET_NAME} PRIVATE inference_engine) endif() # code style