Static plugins: preprocessing and AUTO (#8265)

* 1. Removed explicit SHARED from libraries
2. Fixed double definition for ie_layer_validators

* Fixed SEG in unit-test: order of initialization for global vars

* Added an ability to find plugins.xml from static IE

* Fixes in unit-test

* Migrated to new macro for import / export

* Minimized number of custom dllexport

* Don't use IR v7 for static libraries

* Revert for merge

* Don't enable tests with dlopen for static libraries

* Code style

* Added condition for export

* Revert format_reader

* Removed forward decalaration with external linkage

* Fixed IE linkage on Windows

* Reverted back 2 flags

* Minimal RRTI for cpuFuncTests

* Minimal RRTI for cpuFuncTests

* Still need IR v7 reader

* Fixed build

* Fixed compilation

* clang-format fix

* Removed BUILD_AS_IS and used USE_STATIC_IE

* Enable IR v7 reader as static library

* Fixed compilation for GPU plugin

* Trying to build plugins as static library

* Plugins are able provide their own name for CreatePluginEngine function

* Fixed CPU

* Fixed comments

* Fixed ENABLE_IR_V7_READER usage

* Fixed VPU

* clang-format

* Fixes

* Fix

* Load multiple plugins at once

* Fixed interpreter undefined symbols

* Trying to dynamically register static plugins

* Reverted some ngraph changes

* Fixed cpuUnitTests compilation

* Fixed compilation

* Fixed myriad

* Fixed custom_opset tests

* Reverted linker flags

* Support both static and dynamic plugins

* Fixed compilation of myriadFuncTests

* Removed duplication

* Preprocessing library

* Fixes after self-review

* Fixed linkage for preprocessing

* Fixed preprocessing plugin build

* Windows fix #2

* Fixed linkage for preprocessing

* Proprocessing linkage

* Fixes for Windows

* Added optimizing libker flags to executables as well

* Fixed creation of global ov::Core

* AUTO plugin is static

* Fixed case of build+_shared_libs

* Removed some global variables from ngraph

* Fixes

* Fixed link issue on Windows

* Fixed cmake options

* Fix

* Fix

* Fix 2
This commit is contained in:
Ilya Lavrenov 2021-10-30 22:08:44 +03:00 committed by GitHub
parent cc457e003e
commit 661d436325
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 139 additions and 63 deletions

View File

@ -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()

View File

@ -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<std::string, InferenceEngine::CreatePluginEngineFunc *> plugins_hpp = {")
" static const std::map<Key, Value> 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}")

View File

@ -20,7 +20,7 @@ endif()
#
# ie_add_plugin(NAME <targetName>
# DEVICE_NAME <deviceName>
# [PSEUDO]
# [PSEUDO_PLUGIN_FOR]
# [DEFAULT_CONFIG <key:value;...>]
# [SOURCES <sources>]
# [OBJECT_LIBRARIES <object_libs>]
@ -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}"

View File

@ -9,6 +9,14 @@
namespace {
@IE_PLUGINS_DECLARATIONS@
using Config = std::map<std::string, std::string>;
using Value = std::pair<InferenceEngine::CreatePluginEngineFunc *, Config>;
using Key = std::string;
using PluginsStaticRegistry = std::map<Key, Value>;
const std::map<Key, Value> getStaticPluginsRegistry() {
@IE_PLUGINS_MAP_DEFINITION@
return plugins_hpp;
}
} // namespace

View File

@ -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

View File

@ -445,13 +445,14 @@ public:
}
}
#ifdef OPENVINO_STATIC_LIBRARY
/**
* @brief Register plugins for devices which are located in .xml configuration file.
* @note The function supports UNICODE path
* @param xmlConfigFile An .xml configuraion with device / plugin information
*/
void RegisterPluginsInRegistry(
const std::map<std::string, InferenceEngine::CreatePluginEngineFunc*>& static_registry) {
void RegisterPluginsInRegistry(const decltype(::getStaticPluginsRegistry())& static_registry) {
std::lock_guard<std::mutex> lock(pluginsMutex);
for (const auto& plugin : static_registry) {
@ -459,12 +460,15 @@ public:
if (deviceName.find('.') != std::string::npos) {
IE_THROW() << "Device name must not contain dot '.' symbol";
}
// TODO: add properties support to enable AUTO device
PluginDescriptor desc = {{}, {}, {}, plugin.second};
const auto& create_func = plugin.second.first;
const auto& config = plugin.second.second;
PluginDescriptor desc = {{}, config, {}, create_func};
pluginRegistry[deviceName] = desc;
}
}
#endif
//
// ICore public API
//
@ -1135,7 +1139,7 @@ Core::Core(const std::string& xmlConfigFile) {
_impl = std::make_shared<Impl>();
#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<Impl>();
#ifdef OPENVINO_STATIC_LIBRARY
_impl->RegisterPluginsInRegistry(::plugins_hpp);
_impl->RegisterPluginsInRegistry(::getStaticPluginsRegistry());
#else
register_plugins(parseXmlConfig(xmlConfigFile));
#endif

View File

@ -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)

View File

@ -107,6 +107,7 @@ target_include_directories(${TARGET_NAME}_obj SYSTEM PRIVATE $<TARGET_PROPERTY:o
$<TARGET_PROPERTY:inference_engine_plugin_api,INTERFACE_INCLUDE_DIRECTORIES>)
target_include_directories(${TARGET_NAME}_obj PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}"
$<TARGET_PROPERTY:openvino::util,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:openvino::itt,INTERFACE_INCLUDE_DIRECTORIES>)
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}
$<TARGET_OBJECTS:${TARGET_NAME}_obj>)
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}"

View File

@ -9,6 +9,8 @@
#include <memory>
#include "openvino/runtime/common.hpp"
#include "openvino/util/file_util.hpp"
#include "openvino/util/shared_object.hpp"
#include <ie_blob.h>
#include <file_utils.h>
@ -27,14 +29,12 @@ public:
* @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 @@ public:
*/
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 @@ protected:
OPENVINO_PLUGIN_API void CreatePreProcessData(std::shared_ptr<IPreProcessData>& 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<void> _so = nullptr;
std::shared_ptr<IPreProcessData> _ptr = nullptr;
/**
* @brief This class defines the name of the fabric for creating an IHeteroInferencePlugin object in DLL
*/
template<>
class SOCreatorTrait<IPreProcessData> {
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<IPreProcessData>& data);
_so = ov::util::load_shared_object(preprocLibraryPath.c_str());
reinterpret_cast<CreateF *>(ov::util::get_symbol(_so, "CreatePreProcessData"))(_ptr);
#endif
}
void setRoiBlob(const Blob::Ptr &blob) {
OV_PREPROC_PLUGIN_CALL_STATEMENT(_ptr->setRoiBlob(blob));
}
Blob::Ptr getRoiBlob() const {
OV_PREPROC_PLUGIN_CALL_STATEMENT(return _ptr->getRoiBlob());
}
void execute(Blob::Ptr &preprocessedBlob, const PreProcessInfo& info, bool serial, int batchSize = -1) {
OV_PREPROC_PLUGIN_CALL_STATEMENT(_ptr->execute(preprocessedBlob, info, serial, batchSize));
}
void isApplicable(const Blob::Ptr &src, const Blob::Ptr &dst) {
OV_PREPROC_PLUGIN_CALL_STATEMENT(return _ptr->isApplicable(src, dst));
}
};
} // namespace details
#undef OV_PREPROC_PLUGIN_CALL_STATEMENT
/**
* @brief A C++ helper to work with objects created by the plugin.
* Implements different interfaces.
*/
using PreProcessDataPtr = InferenceEngine::details::SOPointer<IPreProcessData>;
using PreProcessDataPtr = std::shared_ptr<PreProcessDataPlugin>;
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);
if (!FileUtils::fileExist(preprocLibraryPath)) {
IE_THROW() << "Please, make sure that pre-processing library "
<< ov::util::from_file_path(::FileUtils::makePluginLibraryName({}, libraryName)) << " is in "
<< getIELibraryPath();
}
return {preprocLibraryPath};
return std::make_shared<PreProcessDataPlugin>();
}
} // namespace InferenceEngine

View File

@ -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