Added support of external modules in static build (#8518)

* Added support of external modules in static build

* Enable template plugin static run; disabled CPU tests run in dynamic build

* Make FEM library dynamic

* Fixed static build

* clang-format

* Fixed targets

* Python tests fix

* Fixed python API tests skip

* Fixed pattern

* Fixed pattern 2

* Don't run template plugin tests in static build
This commit is contained in:
Ilya Lavrenov
2021-11-12 08:56:57 +03:00
committed by GitHub
parent 0c3cee5e3b
commit e57a455b92
15 changed files with 77 additions and 48 deletions

View File

@@ -25,8 +25,10 @@ jobs:
matrix: matrix:
Dynamic: Dynamic:
CMAKE_BUILD_SHARED_LIBS: 'ON' CMAKE_BUILD_SHARED_LIBS: 'ON'
PYTHON_STATIC_ARGS:
Static: Static:
CMAKE_BUILD_SHARED_LIBS: 'OFF' CMAKE_BUILD_SHARED_LIBS: 'OFF'
PYTHON_STATIC_ARGS: -m "not dynamic_library and not template_plugin"
maxParallel: 2 maxParallel: 2
# About 150% of total time # About 150% of total time
@@ -209,10 +211,9 @@ jobs:
- script: | - script: |
export DATA_PATH=$(MODELS_PATH) export DATA_PATH=$(MODELS_PATH)
export MODELS_PATH=$(MODELS_PATH) export MODELS_PATH=$(MODELS_PATH)
. $(SETUPVARS) -pyver 3.8 && python3 -m pytest -s $(INSTALL_TEST_DIR)/pyngraph --junitxml=TEST-Pyngraph.xml --ignore=$(INSTALL_TEST_DIR)/pyngraph/tests/test_onnx/test_zoo_models.py --ignore=$(INSTALL_TEST_DIR)/pyngraph/tests/test_onnx/test_backend.py . $(SETUPVARS) -pyver 3.8 && python3 -m pytest -s $(INSTALL_TEST_DIR)/pyngraph $(PYTHON_STATIC_ARGS) --junitxml=TEST-Pyngraph.xml --ignore=$(INSTALL_TEST_DIR)/pyngraph/tests/test_onnx/test_zoo_models.py --ignore=$(INSTALL_TEST_DIR)/pyngraph/tests/test_onnx/test_backend.py
displayName: 'nGraph Python Bindings Tests' displayName: 'nGraph Python Bindings Tests'
continueOnError: false continueOnError: false
condition: eq(variables['CMAKE_BUILD_SHARED_LIBS'], 'ON')
- script: | - script: |
export MO_ROOT=$(INSTALL_DIR)/tools/model_optimizer export MO_ROOT=$(INSTALL_DIR)/tools/model_optimizer
@@ -267,11 +268,11 @@ jobs:
- script: . $(SETUPVARS) && $(INSTALL_TEST_DIR)/templateFuncTests --gtest_filter=*smoke* --gtest_output=xml:TEST-templateFuncTests.xml - script: . $(SETUPVARS) && $(INSTALL_TEST_DIR)/templateFuncTests --gtest_filter=*smoke* --gtest_output=xml:TEST-templateFuncTests.xml
displayName: 'TEMPLATE FuncTests' displayName: 'TEMPLATE FuncTests'
continueOnError: false continueOnError: false
condition: eq(variables['CMAKE_BUILD_SHARED_LIBS'], 'ON')
- script: . $(SETUPVARS) && $(INSTALL_TEST_DIR)/cpuFuncTests --gtest_filter=*smoke* --gtest_print_time=1 --gtest_output=xml:TEST-cpuFuncTests.xml - script: . $(SETUPVARS) && $(INSTALL_TEST_DIR)/cpuFuncTests --gtest_filter=*smoke* --gtest_print_time=1 --gtest_output=xml:TEST-cpuFuncTests.xml
displayName: 'CPU FuncTests' displayName: 'CPU FuncTests'
continueOnError: false continueOnError: false
condition: eq(variables['CMAKE_BUILD_SHARED_LIBS'], 'OFF')
- script: | - script: |
export DATA_PATH=$(MODELS_PATH) export DATA_PATH=$(MODELS_PATH)
@@ -284,10 +285,9 @@ jobs:
export DATA_PATH=$(MODELS_PATH) export DATA_PATH=$(MODELS_PATH)
export MODELS_PATH=$(MODELS_PATH) export MODELS_PATH=$(MODELS_PATH)
cd $(REPO_DIR)/inference-engine/ie_bridges/python/tests cd $(REPO_DIR)/inference-engine/ie_bridges/python/tests
. $(SETUPVARS) -pyver 3.8 && python3 -m pytest --junitxml=TEST-PythonAPI.xml . $(SETUPVARS) -pyver 3.8 && python3 -m pytest --junitxml=TEST-PythonAPI.xml $(PYTHON_STATIC_ARGS)
displayName: 'Python API Tests' displayName: 'Python API Tests'
continueOnError: false continueOnError: false
condition: eq(variables['CMAKE_BUILD_SHARED_LIBS'], 'ON')
- script: | - script: |
. $(SETUPVARS) . $(SETUPVARS)

View File

@@ -87,11 +87,7 @@ add_subdirectory(openvino)
add_subdirectory(ngraph) add_subdirectory(ngraph)
add_subdirectory(inference-engine) add_subdirectory(inference-engine)
add_subdirectory(runtime) add_subdirectory(runtime)
# for Template plugin
openvino_developer_export_targets(COMPONENT ngraph TARGETS ngraph_backend interpreter_backend)
include(cmake/extra_modules.cmake) include(cmake/extra_modules.cmake)
if(ENABLE_SAMPLES) if(ENABLE_SAMPLES)
add_subdirectory(samples) add_subdirectory(samples)
endif() endif()

View File

@@ -175,8 +175,9 @@ macro(ie_register_plugins_dynamic)
message(FATAL_ERROR "Please, define MAIN_TARGET") message(FATAL_ERROR "Please, define MAIN_TARGET")
endif() endif()
# Unregister <device_name>.xml files for plugins from current build tree
set(plugins_to_remove ${IE_REGISTER_POSSIBLE_PLUGINS}) set(plugins_to_remove ${IE_REGISTER_POSSIBLE_PLUGINS})
set(plugin_files_local)
set(config_output_file "$<TARGET_FILE_DIR:${IE_REGISTER_MAIN_TARGET}>/plugins.xml") set(config_output_file "$<TARGET_FILE_DIR:${IE_REGISTER_MAIN_TARGET}>/plugins.xml")
foreach(plugin IN LISTS plugins_to_remove) foreach(plugin IN LISTS plugins_to_remove)
@@ -192,6 +193,9 @@ macro(ie_register_plugins_dynamic)
VERBATIM) VERBATIM)
endforeach() endforeach()
# Generate <device_name>.xml files
set(plugin_files_local)
foreach(name IN LISTS PLUGIN_FILES) foreach(name IN LISTS PLUGIN_FILES)
string(REPLACE ":" ";" name "${name}") string(REPLACE ":" ";" name "${name}")
list(LENGTH name length) list(LENGTH name length)
@@ -219,6 +223,8 @@ macro(ie_register_plugins_dynamic)
list(APPEND plugin_files_local "${config_file_name}") list(APPEND plugin_files_local "${config_file_name}")
endforeach() endforeach()
# Combine all <device_name>.xml files into plugins.xml
add_custom_command(TARGET ${IE_REGISTER_MAIN_TARGET} POST_BUILD add_custom_command(TARGET ${IE_REGISTER_MAIN_TARGET} POST_BUILD
COMMAND COMMAND
"${CMAKE_COMMAND}" "${CMAKE_COMMAND}"
@@ -231,15 +237,19 @@ macro(ie_register_plugins_dynamic)
VERBATIM) VERBATIM)
endmacro() endmacro()
macro(ie_register_plugins)
if(BUILD_SHARED_LIBS)
ie_register_plugins_dynamic(${ARGN})
endif()
endmacro()
# #
# ie_register_plugins_static(MAIN_TARGET <main target name> # ie_generate_plugins_hpp()
# POSSIBLE_PLUGINS <list of plugins which can be build by this repo>)
# #
macro(ie_register_plugins_static) macro(ie_generate_plugins_hpp)
set(options) if(BUILD_SHARED_LIBS)
set(oneValueArgs MAIN_TARGET) return()
set(multiValueArgs POSSIBLE_PLUGINS) endif()
cmake_parse_arguments(IE_REGISTER "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(device_mapping) set(device_mapping)
set(device_configs) set(device_configs)
@@ -271,10 +281,10 @@ macro(ie_register_plugins_static)
# link plugin to inference_engine static version # link plugin to inference_engine static version
list(GET name 1 plugin_name) list(GET name 1 plugin_name)
target_link_libraries(${IE_REGISTER_MAIN_TARGET} PRIVATE ${plugin_name}) target_link_libraries(inference_engine PRIVATE ${plugin_name})
endforeach() endforeach()
set(ie_plugins_hpp "${CMAKE_CURRENT_BINARY_DIR}/ie_plugins.hpp") set(ie_plugins_hpp "${CMAKE_BINARY_DIR}/inference-engine/src/inference_engine/ie_plugins.hpp")
set(plugins_hpp_in "${IEDevScripts_DIR}/plugins/plugins.hpp.in") set(plugins_hpp_in "${IEDevScripts_DIR}/plugins/plugins.hpp.in")
add_custom_command(OUTPUT "${ie_plugins_hpp}" add_custom_command(OUTPUT "${ie_plugins_hpp}"
@@ -293,30 +303,25 @@ macro(ie_register_plugins_static)
"Generate ie_plugins.hpp for static build" "Generate ie_plugins.hpp for static build"
VERBATIM) VERBATIM)
# for some reason dependnency on source files does not work
# so, we have to use explicit target and make it dependency for inference_engine
add_custom_target(ie_generate_hpp DEPENDS ${ie_plugins_hpp})
add_dependencies(inference_engine ie_generate_hpp)
# add dependency for object files # add dependency for object files
get_target_property(sources ${IE_REGISTER_MAIN_TARGET} SOURCES) get_target_property(sources inference_engine SOURCES)
foreach(source IN LISTS sources) foreach(source IN LISTS sources)
if("${source}" MATCHES "\\$\\<TARGET_OBJECTS\\:([A-Za-z0-9_]*)\\>") if("${source}" MATCHES "\\$\\<TARGET_OBJECTS\\:([A-Za-z0-9_]*)\\>")
# object library # object library
set(obj_library ${CMAKE_MATCH_1}) set(obj_library ${CMAKE_MATCH_1})
get_target_property(obj_sources ${obj_library} SOURCES) get_target_property(obj_sources ${obj_library} SOURCES)
list(APPEND patched_sources ${obj_sources}) list(APPEND all_sources ${obj_sources})
else() else()
# usual source # usual source
list(APPEND patched_sources ${source}) list(APPEND all_sources ${source})
endif() endif()
endforeach() endforeach()
set_source_files_properties(${patched_sources} PROPERTIES OBJECT_DEPENDS ${ie_plugins_hpp})
endmacro()
# # add dependency on header file generation for all inference_engine source files
# ie_register_plugins(MAIN_TARGET <main target name> set_source_files_properties(${all_sources} PROPERTIES OBJECT_DEPENDS ${ie_plugins_hpp})
# POSSIBLE_PLUGINS <list of plugins which can be build by this repo>)
#
macro(ie_register_plugins)
if(BUILD_SHARED_LIBS)
ie_register_plugins_dynamic(${ARGN})
else()
ie_register_plugins_static(${ARGN})
endif()
endmacro() endmacro()

View File

@@ -8,6 +8,7 @@ function(ie_generate_dev_package_config)
set(all_dev_targets gflags ie_libraries) set(all_dev_targets gflags ie_libraries)
foreach(component IN LISTS openvino_export_components) foreach(component IN LISTS openvino_export_components)
# export all targets with prefix and use them during extra modules build
export(TARGETS ${${component}} NAMESPACE IE:: export(TARGETS ${${component}} NAMESPACE IE::
APPEND FILE "${CMAKE_BINARY_DIR}/${component}_dev_targets.cmake") APPEND FILE "${CMAKE_BINARY_DIR}/${component}_dev_targets.cmake")
list(APPEND all_dev_targets ${${component}}) list(APPEND all_dev_targets ${${component}})
@@ -25,8 +26,6 @@ function(ie_generate_dev_package_config)
@ONLY) @ONLY)
endfunction() endfunction()
ie_generate_dev_package_config()
# #
# Add extra modules # Add extra modules
# #
@@ -54,7 +53,7 @@ function(register_extra_modules)
generate_fake_dev_package() generate_fake_dev_package()
# automatically import plugins from the 'plugins' folder # automatically import plugins from the 'runtime/plugins' folder
file(GLOB local_extra_modules "runtime/plugins/*") file(GLOB local_extra_modules "runtime/plugins/*")
# add template plugin # add template plugin
if(ENABLE_TEMPLATE) if(ENABLE_TEMPLATE)
@@ -90,4 +89,24 @@ function(register_extra_modules)
endforeach() endforeach()
endfunction() endfunction()
#
# Extra modules support
#
# for Template plugin
openvino_developer_export_targets(COMPONENT ngraph TARGETS ngraph_backend interpreter_backend)
# this InferenceEngineDeveloperPackageConfig.cmake is not used
# during extra modules build since it's generated after modules
# are configured
ie_generate_dev_package_config()
# extra modules must be registered after inference_engine library
# and all other IE common libraries (ie_libraries) are creared
# because 'register_extra_modules' creates fake InferenceEngineDeveloperPackageConfig.cmake
# with all imported developer targets
register_extra_modules() register_extra_modules()
# for static libraries case we need to generate final ie_plugins.hpp
# with all the information about plugins
ie_generate_plugins_hpp()

View File

@@ -218,7 +218,9 @@ void TemplatePlugin::ExecutableNetwork::Export(std::ostream& modelStream) {
// Note: custom ngraph extensions are not supported // Note: custom ngraph extensions are not supported
std::map<std::string, ngraph::OpSet> custom_opsets; std::map<std::string, ngraph::OpSet> custom_opsets;
std::stringstream xmlFile, binFile; std::stringstream xmlFile, binFile;
OPENVINO_SUPPRESS_DEPRECATED_START
ov::pass::Serialize serializer(xmlFile, binFile, custom_opsets); ov::pass::Serialize serializer(xmlFile, binFile, custom_opsets);
OPENVINO_SUPPRESS_DEPRECATED_END
serializer.run_on_function(_function); serializer.run_on_function(_function);
auto m_constants = binFile.str(); auto m_constants = binFile.str();

View File

@@ -63,4 +63,3 @@ elseif(WIN32)
PATTERN speech_libs_and_demos EXCLUDE PATTERN speech_libs_and_demos EXCLUDE
PATTERN .clang-format EXCLUDE) PATTERN .clang-format EXCLUDE)
endif() endif()

View File

@@ -45,9 +45,8 @@ def device():
def pytest_configure(config): def pytest_configure(config):
# register an additional markers # register an additional markers
config.addinivalue_line( config.addinivalue_line("markers", "template_plugin: Skip test on Template plugin")
"markers", "template_plugin" config.addinivalue_line("markers", "dynamic_library: Runs tests only in dynamic libraries case")
)
def create_encoder(input_shape, levels = 4): def create_encoder(input_shape, levels = 4):

View File

@@ -75,6 +75,7 @@ def test_query_network(device):
assert next(iter(set(query_res.values()))) == device, "Wrong device for some layers" assert next(iter(set(query_res.values()))) == device, "Wrong device for some layers"
@pytest.mark.dynamic_library
@pytest.mark.skipif(os.environ.get("TEST_DEVICE", "CPU") != "CPU", reason="Device dependent test") @pytest.mark.skipif(os.environ.get("TEST_DEVICE", "CPU") != "CPU", reason="Device dependent test")
def test_register_plugin(): def test_register_plugin():
ie = IECore() ie = IECore()
@@ -86,6 +87,7 @@ def test_register_plugin():
assert isinstance(exec_net, ExecutableNetwork), "Cannot load the network to the registered plugin with name 'BLA'" assert isinstance(exec_net, ExecutableNetwork), "Cannot load the network to the registered plugin with name 'BLA'"
@pytest.mark.dynamic_library
@pytest.mark.skipif(os.environ.get("TEST_DEVICE", "CPU") != "CPU", reason="Device dependent test") @pytest.mark.skipif(os.environ.get("TEST_DEVICE", "CPU") != "CPU", reason="Device dependent test")
def test_register_plugins(): def test_register_plugins():
ie = IECore() ie = IECore()

View File

@@ -104,9 +104,11 @@ protected:
inline InferenceEngine::Core createIECoreWithTemplate() { inline InferenceEngine::Core createIECoreWithTemplate() {
PluginCache::get().reset(); PluginCache::get().reset();
InferenceEngine::Core ie; InferenceEngine::Core ie;
#ifndef OPENVINO_STATIC_LIBRARY
std::string pluginName = "templatePlugin"; std::string pluginName = "templatePlugin";
pluginName += IE_BUILD_POSTFIX; pluginName += IE_BUILD_POSTFIX;
ie.RegisterPlugin(pluginName, "TEMPLATE"); ie.RegisterPlugin(pluginName, CommonTestUtils::DEVICE_TEMPLATE);
#endif // !OPENVINO_STATIC_LIBRARY
return ie; return ie;
} }

View File

@@ -69,9 +69,11 @@ protected:
inline ov::runtime::Core createCoreWithTemplate() { inline ov::runtime::Core createCoreWithTemplate() {
ov::test::utils::PluginCache::get().reset(); ov::test::utils::PluginCache::get().reset();
ov::runtime::Core core; ov::runtime::Core core;
#ifndef OPENVINO_STATIC_LIBRARY
std::string pluginName = "templatePlugin"; std::string pluginName = "templatePlugin";
pluginName += IE_BUILD_POSTFIX; pluginName += IE_BUILD_POSTFIX;
core.register_plugin(pluginName, CommonTestUtils::DEVICE_TEMPLATE); core.register_plugin(pluginName, CommonTestUtils::DEVICE_TEMPLATE);
#endif // !OPENVINO_STATIC_LIBRARY
return core; return core;
} }

View File

@@ -35,7 +35,7 @@ ov_install_static_lib(${TARGET_NAME}_static ngraph)
# Shared library - need to recompile object files to export necessary symbols # Shared library - need to recompile object files to export necessary symbols
add_library(${TARGET_NAME} ${LIBRARY_SRC} ${LIBRARY_HEADERS} ${LIBRARY_PUBLIC_HEADERS}) add_library(${TARGET_NAME} SHARED ${LIBRARY_SRC} ${LIBRARY_HEADERS} ${LIBRARY_PUBLIC_HEADERS})
add_library(ngraph::${TARGET_NAME} ALIAS ${TARGET_NAME}) add_library(ngraph::${TARGET_NAME} ALIAS ${TARGET_NAME})
add_library(openvino::frontend::manager ALIAS ${TARGET_NAME}) add_library(openvino::frontend::manager ALIAS ${TARGET_NAME})

View File

@@ -9,7 +9,7 @@
// Increment each time when FrontEnd/InputModel/Place interface is changed // Increment each time when FrontEnd/InputModel/Place interface is changed
#define OV_FRONTEND_API_VERSION 1 #define OV_FRONTEND_API_VERSION 1
#if defined(USE_STATIC_FRONTEND_MANAGER) || defined(OPENVINO_STATIC_LIBRARY) #if defined(USE_STATIC_FRONTEND_MANAGER) // || defined(OPENVINO_STATIC_LIBRARY)
# define FRONTEND_API # define FRONTEND_API
#else #else
// Defined if cmake is building the frontend_manager DLL (instead of using it) // Defined if cmake is building the frontend_manager DLL (instead of using it)

View File

@@ -48,12 +48,12 @@ static void get_paddings(const NodeContext& node,
// TODO: need to support NHWC input #55483 // TODO: need to support NHWC input #55483
switch (paddings.size()) { switch (paddings.size()) {
case 2: case 2:
pad_begin = Shape{static_cast<uint64_t>(paddings[0]), static_cast<uint64_t>(paddings[1])}; pad_begin = Shape{static_cast<size_t>(paddings[0]), static_cast<size_t>(paddings[1])};
pad_end = pad_begin; pad_end = pad_begin;
break; break;
case 4: case 4:
pad_begin = Shape{static_cast<uint64_t>(paddings[0]), static_cast<uint64_t>(paddings[2])}; pad_begin = Shape{static_cast<size_t>(paddings[0]), static_cast<size_t>(paddings[2])};
pad_end = Shape{static_cast<uint64_t>(paddings[1]), static_cast<uint64_t>(paddings[3])}; pad_end = Shape{static_cast<size_t>(paddings[1]), static_cast<size_t>(paddings[3])};
break; break;
default: default:
throw std::runtime_error("Unsupported pooling paddings " + std::to_string(paddings.size())); throw std::runtime_error("Unsupported pooling paddings " + std::to_string(paddings.size()));
@@ -131,7 +131,7 @@ NamedOutputs pool2d(const NodeContext& node) {
auto strides = node.get_attribute<std::vector<int32_t>>("strides"); auto strides = node.get_attribute<std::vector<int32_t>>("strides");
auto paddings = node.get_attribute<std::vector<int32_t>>("paddings"); auto paddings = node.get_attribute<std::vector<int32_t>>("paddings");
uint64_t kernel_h, kernel_w; size_t kernel_h, kernel_w;
if (kernel_shape.size() == 1) { if (kernel_shape.size() == 1) {
// Not tested: implemented according to spec, but can't generate real // Not tested: implemented according to spec, but can't generate real
// model to test // model to test

View File

@@ -78,6 +78,7 @@ def pytest_configure(config):
config.addinivalue_line("markers", "skip_on_hetero: Skip test on HETERO") config.addinivalue_line("markers", "skip_on_hetero: Skip test on HETERO")
config.addinivalue_line("markers", "skip_on_template: Skip test on TEMPLATE") config.addinivalue_line("markers", "skip_on_template: Skip test on TEMPLATE")
config.addinivalue_line("markers", "onnx_coverage: Collect ONNX operator coverage") config.addinivalue_line("markers", "onnx_coverage: Collect ONNX operator coverage")
config.addinivalue_line("markers", "dynamic_library: Runs tests only in dynamic libraries case")
def pytest_collection_modifyitems(config, items): def pytest_collection_modifyitems(config, items):

View File

@@ -242,6 +242,7 @@ def test_query_network(device):
assert next(iter(set(query_res.values()))) == device, "Wrong device for some layers" assert next(iter(set(query_res.values()))) == device, "Wrong device for some layers"
@pytest.mark.dynamic_library
@pytest.mark.skipif(os.environ.get("TEST_DEVICE", "CPU") != "CPU", reason="Device independent test") @pytest.mark.skipif(os.environ.get("TEST_DEVICE", "CPU") != "CPU", reason="Device independent test")
def test_register_plugin(): def test_register_plugin():
ie = Core() ie = Core()
@@ -252,6 +253,7 @@ def test_register_plugin():
"Cannot load the network to the registered plugin with name 'BLA'" "Cannot load the network to the registered plugin with name 'BLA'"
@pytest.mark.dynamic_library
@pytest.mark.skipif(os.environ.get("TEST_DEVICE", "CPU") != "CPU", reason="Device independent test") @pytest.mark.skipif(os.environ.get("TEST_DEVICE", "CPU") != "CPU", reason="Device independent test")
def test_register_plugins(): def test_register_plugins():
ie = Core() ie = Core()