Skip to content

Commit 661d436

Browse files
Static plugins: preprocessing and AUTO (openvinotoolkit#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
1 parent cc457e0 commit 661d436

File tree

10 files changed

+139
-63
lines changed

10 files changed

+139
-63
lines changed

cmake/developer_package/compile_flags/os_flags.cmake

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,11 @@ else()
332332
if(APPLE)
333333
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-dead_strip")
334334
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-dead_strip")
335+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-dead_strip")
335336
elseif(LINUX)
336337
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections -Wl,--exclude-libs,ALL")
337338
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--gc-sections -Wl,--exclude-libs,ALL")
339+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -Wl,--exclude-libs,ALL")
338340
endif()
339341
endif()
340342

@@ -354,10 +356,7 @@ function(link_system_libraries TARGET_NAME)
354356
)
355357
endif()
356358

357-
target_link_libraries(${TARGET_NAME}
358-
${MODE}
359-
${arg}
360-
)
359+
target_link_libraries(${TARGET_NAME} ${MODE} ${arg})
361360
endif()
362361
endforeach()
363362
endfunction()

cmake/developer_package/plugins/create_plugins_hpp.cmake

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33
#
44

5-
foreach(var IE_DEVICE_NAMES IE_PLUGINS_HPP_HEADER IE_PLUGINS_HPP_HEADER_IN)
5+
foreach(var IE_DEVICE_MAPPING IE_PLUGINS_HPP_HEADER IE_PLUGINS_HPP_HEADER_IN)
66
if(NOT DEFINED ${var})
77
message(FATAL_ERROR "${var} is required, but not defined")
88
endif()
@@ -12,18 +12,40 @@ endforeach()
1212

1313
set(IE_PLUGINS_DECLARATIONS "")
1414
set(IE_PLUGINS_MAP_DEFINITION
15-
"std::map<std::string, InferenceEngine::CreatePluginEngineFunc *> plugins_hpp = {")
15+
" static const std::map<Key, Value> plugins_hpp = {")
1616

17-
foreach(dev_name IN LISTS IE_DEVICE_NAMES)
18-
set(_IE_CREATE_PLUGIN_FUNC "CreatePluginEngine${dev_name}")
17+
foreach(dev_map IN LISTS IE_DEVICE_MAPPING)
18+
string(REPLACE ":" ";" dev_map "${dev_map}")
19+
list(GET dev_map 0 mapped_dev_name)
20+
list(GET dev_map 1 actual_dev_name)
21+
22+
# common
23+
set(_IE_CREATE_PLUGIN_FUNC "CreatePluginEngine${actual_dev_name}")
24+
25+
# declarations
1926
set(IE_PLUGINS_DECLARATIONS "${IE_PLUGINS_DECLARATIONS}
2027
IE_DEFINE_PLUGIN_CREATE_FUNCTION_DECLARATION(${_IE_CREATE_PLUGIN_FUNC})")
28+
29+
# definitions
30+
set(dev_config "{")
31+
if(${mapped_dev_name}_CONFIG)
32+
foreach(props IN LISTS ${mapped_dev_name}_CONFIG)
33+
string(REPLACE ":" ";" props "${props}")
34+
35+
list(GET props 0 key)
36+
list(GET props 1 value)
37+
38+
set(dev_config "${dev_config} { \"${key}\", \"${value}\" }, ")
39+
endforeach()
40+
endif()
41+
set(dev_config "${dev_config}}")
42+
2143
set(IE_PLUGINS_MAP_DEFINITION "${IE_PLUGINS_MAP_DEFINITION}
22-
{ \"${dev_name}\", ${_IE_CREATE_PLUGIN_FUNC} },")
44+
{ \"${mapped_dev_name}\", Value { ${_IE_CREATE_PLUGIN_FUNC}, ${dev_config} } },")
2345
endforeach()
2446

2547
set(IE_PLUGINS_MAP_DEFINITION "${IE_PLUGINS_MAP_DEFINITION}
26-
};\n")
48+
};\n")
2749

2850

2951
message("${IE_PLUGINS_DECLARATIONS}")

cmake/developer_package/plugins/plugins.cmake

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ endif()
2020
#
2121
# ie_add_plugin(NAME <targetName>
2222
# DEVICE_NAME <deviceName>
23-
# [PSEUDO]
23+
# [PSEUDO_PLUGIN_FOR]
2424
# [DEFAULT_CONFIG <key:value;...>]
2525
# [SOURCES <sources>]
2626
# [OBJECT_LIBRARIES <object_libs>]
@@ -29,8 +29,8 @@ endif()
2929
# )
3030
#
3131
function(ie_add_plugin)
32-
set(options SKIP_INSTALL ADD_CLANG_FORMAT PSEUDO_PLUGIN)
33-
set(oneValueArgs NAME DEVICE_NAME VERSION_DEFINES_FOR)
32+
set(options SKIP_INSTALL ADD_CLANG_FORMAT)
33+
set(oneValueArgs NAME DEVICE_NAME VERSION_DEFINES_FOR PSEUDO_PLUGIN_FOR)
3434
set(multiValueArgs DEFAULT_CONFIG SOURCES OBJECT_LIBRARIES CPPLINT_FILTERS)
3535
cmake_parse_arguments(IE_PLUGIN "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
3636

@@ -44,7 +44,7 @@ function(ie_add_plugin)
4444

4545
# create and configure target
4646

47-
if(NOT IE_PLUGIN_PSEUDO_PLUGIN)
47+
if(NOT IE_PLUGIN_PSEUDO_PLUGIN_FOR)
4848
if(IE_PLUGIN_VERSION_DEFINES_FOR)
4949
addVersionDefines(${IE_PLUGIN_VERSION_DEFINES_FOR} CI_BUILD_NUMBER)
5050
endif()
@@ -148,6 +148,7 @@ function(ie_add_plugin)
148148
list(APPEND PLUGIN_FILES "${IE_PLUGIN_DEVICE_NAME}:${IE_PLUGIN_NAME}")
149149
set(PLUGIN_FILES "${PLUGIN_FILES}" CACHE INTERNAL "" FORCE)
150150
set(${IE_PLUGIN_DEVICE_NAME}_CONFIG "${IE_PLUGIN_DEFAULT_CONFIG}" CACHE INTERNAL "" FORCE)
151+
set(${IE_PLUGIN_DEVICE_NAME}_PSEUDO_PLUGIN_FOR "${IE_PLUGIN_PSEUDO_PLUGIN_FOR}" CACHE INTERNAL "" FORCE)
151152
endfunction()
152153

153154
#
@@ -230,17 +231,29 @@ macro(ie_register_plugins_static)
230231
set(multiValueArgs POSSIBLE_PLUGINS)
231232
cmake_parse_arguments(IE_REGISTER "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
232233

233-
set(device_names)
234+
set(device_mapping)
235+
set(device_configs)
234236
foreach(name IN LISTS PLUGIN_FILES)
235237
string(REPLACE ":" ";" name "${name}")
236238
list(LENGTH name length)
237239
if(NOT ${length} EQUAL 2)
238240
message(FATAL_ERROR "Unexpected error, please, contact developer of this script")
239241
endif()
240242

243+
# create device mapping: preudo device => actual device
241244
list(GET name 0 device_name)
242-
list(APPEND device_names ${device_name})
245+
if(${device_name}_PSEUDO_PLUGIN_FOR)
246+
list(APPEND device_mapping "${device_name}:${${device_name}_PSEUDO_PLUGIN_FOR}")
247+
else()
248+
list(APPEND device_mapping "${device_name}:${device_name}")
249+
endif()
250+
251+
# add default plugin config options
252+
if(${device_name}_CONFIG)
253+
list(APPEND device_configs -D "${device_name}_CONFIG=${${device_name}_CONFIG}")
254+
endif()
243255

256+
# link plugin to inference_engine static version
244257
list(GET name 1 plugin_name)
245258
target_link_libraries(${IE_REGISTER_MAIN_TARGET} PRIVATE ${plugin_name})
246259
endforeach()
@@ -251,9 +264,10 @@ macro(ie_register_plugins_static)
251264
add_custom_command(OUTPUT "${ie_plugins_hpp}"
252265
COMMAND
253266
"${CMAKE_COMMAND}"
254-
-D "IE_DEVICE_NAMES=${device_names}"
267+
-D "IE_DEVICE_MAPPING=${device_mapping}"
255268
-D "IE_PLUGINS_HPP_HEADER_IN=${plugins_hpp_in}"
256269
-D "IE_PLUGINS_HPP_HEADER=${ie_plugins_hpp}"
270+
${device_configs}
257271
-P "${IEDevScripts_DIR}/plugins/create_plugins_hpp.cmake"
258272
DEPENDS
259273
"${plugins_hpp_in}"

cmake/developer_package/plugins/plugins.hpp.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
namespace {
1010
@IE_PLUGINS_DECLARATIONS@
1111

12+
using Config = std::map<std::string, std::string>;
13+
using Value = std::pair<InferenceEngine::CreatePluginEngineFunc *, Config>;
14+
using Key = std::string;
15+
using PluginsStaticRegistry = std::map<Key, Value>;
16+
17+
const std::map<Key, Value> getStaticPluginsRegistry() {
1218
@IE_PLUGINS_MAP_DEFINITION@
19+
return plugins_hpp;
20+
}
1321

1422
} // namespace

inference-engine/src/CMakeLists.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ if(CMAKE_COMPILER_IS_GNUCXX)
77
ie_add_compiler_flags(-Wmissing-declarations)
88
endif()
99

10-
add_subdirectory(preprocessing)
10+
add_subdirectory(transformations)
1111

1212
add_subdirectory(legacy_api)
1313

14+
add_subdirectory(low_precision_transformations)
15+
16+
add_subdirectory(offline_transformations)
17+
18+
add_subdirectory(snippets)
19+
1420
if(ENABLE_MKL_DNN)
1521
add_subdirectory(mkldnn_plugin)
1622
endif()
@@ -37,15 +43,9 @@ endif()
3743

3844
add_subdirectory(inference_engine)
3945

40-
add_subdirectory(transformations)
41-
4246
add_subdirectory(readers)
4347

44-
add_subdirectory(low_precision_transformations)
45-
46-
add_subdirectory(offline_transformations)
47-
48-
add_subdirectory(snippets)
48+
add_subdirectory(preprocessing)
4949

5050
# add a custom target to build all Inference Engine Core libraries
5151

inference-engine/src/inference_engine/src/ie_core.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -445,26 +445,30 @@ class CoreImpl : public ie::ICore, public std::enable_shared_from_this<ie::ICore
445445
}
446446
}
447447

448+
#ifdef OPENVINO_STATIC_LIBRARY
449+
448450
/**
449451
* @brief Register plugins for devices which are located in .xml configuration file.
450452
* @note The function supports UNICODE path
451453
* @param xmlConfigFile An .xml configuraion with device / plugin information
452454
*/
453-
void RegisterPluginsInRegistry(
454-
const std::map<std::string, InferenceEngine::CreatePluginEngineFunc*>& static_registry) {
455+
void RegisterPluginsInRegistry(const decltype(::getStaticPluginsRegistry())& static_registry) {
455456
std::lock_guard<std::mutex> lock(pluginsMutex);
456457

457458
for (const auto& plugin : static_registry) {
458459
const auto& deviceName = plugin.first;
459460
if (deviceName.find('.') != std::string::npos) {
460461
IE_THROW() << "Device name must not contain dot '.' symbol";
461462
}
462-
// TODO: add properties support to enable AUTO device
463-
PluginDescriptor desc = {{}, {}, {}, plugin.second};
463+
const auto& create_func = plugin.second.first;
464+
const auto& config = plugin.second.second;
465+
PluginDescriptor desc = {{}, config, {}, create_func};
464466
pluginRegistry[deviceName] = desc;
465467
}
466468
}
467469

470+
#endif
471+
468472
//
469473
// ICore public API
470474
//
@@ -1135,7 +1139,7 @@ Core::Core(const std::string& xmlConfigFile) {
11351139
_impl = std::make_shared<Impl>();
11361140

11371141
#ifdef OPENVINO_STATIC_LIBRARY
1138-
_impl->RegisterPluginsInRegistry(::plugins_hpp);
1142+
_impl->RegisterPluginsInRegistry(::getStaticPluginsRegistry());
11391143
#else
11401144
RegisterPlugins(ov::runtime::parseXmlConfig(xmlConfigFile));
11411145
#endif
@@ -1398,7 +1402,7 @@ Core::Core(const std::string& xmlConfigFile) {
13981402
_impl = std::make_shared<Impl>();
13991403

14001404
#ifdef OPENVINO_STATIC_LIBRARY
1401-
_impl->RegisterPluginsInRegistry(::plugins_hpp);
1405+
_impl->RegisterPluginsInRegistry(::getStaticPluginsRegistry());
14021406
#else
14031407
register_plugins(parseXmlConfig(xmlConfigFile));
14041408
#endif

inference-engine/src/multi_device/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ ie_add_plugin(NAME ${TARGET_NAME}
1212
SOURCES ${SOURCES} ${HEADERS}
1313
VERSION_DEFINES_FOR multi_device_plugin.cpp)
1414

15-
# TODO: add fix for this case since DEFAULT_CONFIG is not used now
1615
ie_add_plugin(NAME ${TARGET_NAME}
1716
DEVICE_NAME "AUTO"
18-
PSEUDO_PLUGIN
17+
PSEUDO_PLUGIN_FOR "MULTI"
1918
DEFAULT_CONFIG "MULTI_WORK_MODE_AS_AUTO:YES")
2019

2120
target_link_libraries(${TARGET_NAME} PRIVATE inference_engine ngraph inference_engine_transformations)

inference-engine/src/preprocessing/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ target_include_directories(${TARGET_NAME}_obj SYSTEM PRIVATE $<TARGET_PROPERTY:o
107107
$<TARGET_PROPERTY:inference_engine_plugin_api,INTERFACE_INCLUDE_DIRECTORIES>)
108108

109109
target_include_directories(${TARGET_NAME}_obj PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}"
110+
$<TARGET_PROPERTY:openvino::util,INTERFACE_INCLUDE_DIRECTORIES>
110111
$<TARGET_PROPERTY:openvino::itt,INTERFACE_INCLUDE_DIRECTORIES>)
111112

112113
set_ie_threading_interface_for(${TARGET_NAME}_obj)
@@ -121,7 +122,7 @@ else()
121122
set(library_type STATIC)
122123
endif()
123124

124-
add_library(${TARGET_NAME} MODULE
125+
add_library(${TARGET_NAME} ${library_type}
125126
$<TARGET_OBJECTS:${TARGET_NAME}_obj>)
126127

127128
ie_add_vs_version_file(NAME ${TARGET_NAME}
@@ -134,6 +135,8 @@ target_link_libraries(${TARGET_NAME} PRIVATE fluid openvino::itt openvino::util)
134135
if(BUILD_SHARED_LIBS)
135136
# for static linkage the dependencies are in opposite order
136137
target_link_libraries(${TARGET_NAME} PRIVATE inference_engine)
138+
else()
139+
target_link_libraries(inference_engine PRIVATE ${TARGET_NAME})
137140
endif()
138141

139142
target_include_directories(${TARGET_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}"

0 commit comments

Comments
 (0)