module library type for IE plugins, extensions (#3656)

* CMAKE: Added MODULE linker flags

* Fixed plugins.xml s

* Use module instead of shared library

* Fixes

* tab 2 spaces

* Renamed get_shared_library_name to ie_plugin_get_file_name
This commit is contained in:
Ilya Lavrenov 2020-12-23 18:25:42 +03:00 committed by GitHub
parent 5b26a7fcb1
commit 036f574756
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 81 additions and 83 deletions

View File

@ -6,9 +6,9 @@ include(CMakeParseArguments)
set(PLUGIN_FILES "" CACHE INTERNAL "")
function(get_shared_library_name target_name library_name)
set(LIB_PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}")
set(LIB_SUFFIX "${IE_BUILD_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}")
function(ie_plugin_get_file_name target_name library_name)
set(LIB_PREFIX "${CMAKE_SHARED_MODULE_PREFIX}")
set(LIB_SUFFIX "${IE_BUILD_POSTFIX}${CMAKE_SHARED_MODULE_SUFFIX}")
set("${library_name}" "${LIB_PREFIX}${target_name}${LIB_SUFFIX}" PARENT_SCOPE)
endfunction()
@ -52,7 +52,7 @@ function(ie_add_plugin)
add_cpplint_target(${obj_lib}_cpplint FOR_TARGETS ${obj_lib})
endforeach()
add_library(${IE_PLUGIN_NAME} SHARED ${input_files})
add_library(${IE_PLUGIN_NAME} MODULE ${input_files})
target_compile_definitions(${IE_PLUGIN_NAME} PRIVATE IMPLEMENT_INFERENCE_ENGINE_PLUGIN)
ie_add_vs_version_file(NAME ${TARGET_NAME}
@ -152,7 +152,7 @@ macro(ie_register_plugins)
# create plugin file
set(config_file_name "${CMAKE_BINARY_DIR}/plugins/${name}.xml")
get_shared_library_name(${name} library_name)
ie_plugin_get_file_name(${name} library_name)
add_custom_command(TARGET ${IE_REGISTER_MAIN_TARGET} POST_BUILD
COMMAND
@ -170,7 +170,7 @@ macro(ie_register_plugins)
add_custom_command(TARGET ${IE_REGISTER_MAIN_TARGET} POST_BUILD
COMMAND
"${CMAKE_COMMAND}"
-D "CMAKE_SHARED_LIBRARY_PREFIX=${CMAKE_SHARED_LIBRARY_PREFIX}"
-D "CMAKE_SHARED_MODULE_PREFIX=${CMAKE_SHARED_MODULE_PREFIX}"
-D "IE_CONFIG_OUTPUT_FILE=${config_output_file}"
-D "IE_CONFIGS_DIR=${CMAKE_BINARY_DIR}/plugins"
-P "${IEDevScripts_DIR}/plugins/register_plugin_cmake.cmake"

View File

@ -16,30 +16,30 @@ endif()
file(GLOB plugin_files "${IE_CONFIGS_DIR}/*.xml")
function(check_plugin_exists plugin_name outvar)
set(${outvar} OFF PARENT_SCOPE)
set(${outvar} OFF PARENT_SCOPE)
# check if config file already has this plugin
file(STRINGS "${IE_CONFIG_OUTPUT_FILE}" content REGEX "plugin .*=\"")
# check if config file already has this plugin
file(STRINGS "${IE_CONFIG_OUTPUT_FILE}" content REGEX "plugin .*=\"")
foreach(line IN LISTS content)
string(REGEX MATCH "location=\"([^\"]*)\"" location "${line}")
get_filename_component(location "${CMAKE_MATCH_1}" NAME_WE)
foreach(line IN LISTS content)
string(REGEX MATCH "location=\"([^\"]*)\"" location "${line}")
get_filename_component(location "${CMAKE_MATCH_1}" NAME_WE)
if("${CMAKE_SHARED_LIBRARY_PREFIX}${plugin_name}" MATCHES "${location}")
# plugin has already registered
set(${outvar} ON PARENT_SCOPE)
endif()
endforeach()
if("${CMAKE_SHARED_MODULE_PREFIX}${plugin_name}" MATCHES "${location}")
# plugin has already registered
set(${outvar} ON PARENT_SCOPE)
endif()
endforeach()
endfunction()
set(plugin_files_to_add)
foreach(plugin_file IN LISTS plugin_files)
get_filename_component(plugin_name "${plugin_file}" NAME_WE)
check_plugin_exists("${plugin_name}" exists)
get_filename_component(plugin_name "${plugin_file}" NAME_WE)
check_plugin_exists("${plugin_name}" exists)
if(NOT exists)
list(APPEND plugin_files_to_add "${plugin_file}")
endif()
if(NOT exists)
list(APPEND plugin_files_to_add "${plugin_file}")
endif()
endforeach()
# add plugin
@ -48,11 +48,11 @@ file(STRINGS "${IE_CONFIG_OUTPUT_FILE}" content)
foreach(line IN LISTS content)
if("${line}" MATCHES "</plugins>")
foreach(plugin_file IN LISTS plugin_files_to_add)
file(READ "${plugin_file}" content)
set(newContent "${newContent}
foreach(plugin_file IN LISTS plugin_files_to_add)
file(READ "${plugin_file}" content)
set(newContent "${newContent}
${content}")
endforeach()
endforeach()
endif()
if(newContent)

View File

@ -3,7 +3,7 @@
#
if(NOT EXISTS "${IE_CONFIG_OUTPUT_FILE}")
return()
return()
endif()
# remove plugin file
@ -16,19 +16,19 @@ file(STRINGS "${IE_CONFIG_OUTPUT_FILE}" content)
set(skip_plugin OFF)
foreach(line IN LISTS content)
if("${line}" MATCHES "${IE_PLUGIN_NAME}")
set(skip_plugin ON)
set(skip_plugin ON)
endif()
if(NOT skip_plugin)
if(newContent)
set(newContent "${newContent}\n${line}")
else()
set(newContent "${line}")
endif()
if(newContent)
set(newContent "${newContent}\n${line}")
else()
set(newContent "${line}")
endif()
endif()
if("${line}" MATCHES "</plugin>")
set(skip_plugin OFF)
set(skip_plugin OFF)
endif()
endforeach()

View File

@ -62,13 +62,13 @@ The table below shows the plugin libraries and additional dependencies for Linux
| Plugin | Library name for Linux | Dependency libraries for Linux | Library name for Windows | Dependency libraries for Windows | Library name for macOS | Dependency libraries for macOS |
|--------|-----------------------------|-------------------------------------------------------------|--------------------------|--------------------------------------------------------------------------------------------------------|------------------------------|---------------------------------------------|
| CPU | `libMKLDNNPlugin.so` | `libinference_engine_lp_transformations.so` | `MKLDNNPlugin.dll` | `inference_engine_lp_transformations.dll` | `libMKLDNNPlugin.dylib` | `inference_engine_lp_transformations.dylib` |
| CPU | `libMKLDNNPlugin.so` | `libinference_engine_lp_transformations.so` | `MKLDNNPlugin.dll` | `inference_engine_lp_transformations.dll` | `libMKLDNNPlugin.so` | `inference_engine_lp_transformations.dylib` |
| GPU | `libclDNNPlugin.so` | `libinference_engine_lp_transformations.so`, `libOpenCL.so` | `clDNNPlugin.dll` | `OpenCL.dll`, `inference_engine_lp_transformations.dll` | Is not supported | - |
| MYRIAD | `libmyriadPlugin.so` | `libusb.so`, | `myriadPlugin.dll` | `usb.dll` | `libmyriadPlugin.dylib` | `libusb.dylib` |
| MYRIAD | `libmyriadPlugin.so` | `libusb.so`, | `myriadPlugin.dll` | `usb.dll` | `libmyriadPlugin.so` | `libusb.dylib` |
| HDDL | `libHDDLPlugin.so` | `libbsl.so`, `libhddlapi.so`, `libmvnc-hddl.so` | `HDDLPlugin.dll` | `bsl.dll`, `hddlapi.dll`, `json-c.dll`, `libcrypto-1_1-x64.dll`, `libssl-1_1-x64.dll`, `mvnc-hddl.dll` | Is not supported | - |
| GNA | `libGNAPlugin.so` | `libgna.so`, | `GNAPlugin.dll` | `gna.dll` | Is not supported | - |
| HETERO | `libHeteroPlugin.so` | Same as for selected plugins | `HeteroPlugin.dll` | Same as for selected plugins | `libHeteroPlugin.dylib` | Same as for selected plugins |
| MULTI | `libMultiDevicePlugin.so` | Same as for selected plugins | `MultiDevicePlugin.dll` | Same as for selected plugins | `libMultiDevicePlugin.dylib` | Same as for selected plugins |
| HETERO | `libHeteroPlugin.so` | Same as for selected plugins | `HeteroPlugin.dll` | Same as for selected plugins | `libHeteroPlugin.so` | Same as for selected plugins |
| MULTI | `libMultiDevicePlugin.so` | Same as for selected plugins | `MultiDevicePlugin.dll` | Same as for selected plugins | `libMultiDevicePlugin.so` | Same as for selected plugins |
> **NOTE**: All plugin libraries also depend on core Inference Engine libraries.

View File

@ -12,7 +12,7 @@ find_package(InferenceEngine REQUIRED)
file(GLOB_RECURSE SRC *.cpp)
add_library(${TARGET_NAME} SHARED ${SRC})
add_library(${TARGET_NAME} MODULE ${SRC})
target_compile_definitions(${TARGET_NAME} PRIVATE IMPLEMENT_INFERENCE_EXTENSION_API)
target_link_libraries(${TARGET_NAME} PRIVATE IE::inference_engine ${NGRAPH_LIBRARIES})

View File

@ -24,14 +24,13 @@ function(ie_developer_export_targets)
endfunction()
function(ie_developer_export)
set(all_dev_targets gflags inference_engine_ir_reader inference_engine_ir_v7_reader)
set(all_dev_targets gflags ie_libraries)
foreach(component IN LISTS openvino_export_components)
export(TARGETS ${${component}} NAMESPACE IE::
APPEND FILE "${CMAKE_BINARY_DIR}/${component}_dev_targets.cmake")
list(APPEND all_dev_targets ${${component}})
endforeach()
# Custom target to build only Inference Engine Developer Package targets
add_custom_target(ie_dev_targets ALL DEPENDS ${all_dev_targets})
endfunction()

View File

@ -422,7 +422,7 @@ public:
// append IR library path for default IE plugins
FileUtils::FilePath pluginPath;
{
pluginPath = FileUtils::makeSharedLibraryName({}, FileUtils::toFilePath(pluginName.c_str()));
pluginPath = FileUtils::makePluginLibraryName({}, FileUtils::toFilePath(pluginName.c_str()));
FileUtils::FilePath absFilePath = FileUtils::makePath(getInferenceEngineLibraryPath(), pluginPath);
if (FileUtils::fileExist(absFilePath)) pluginPath = absFilePath;

View File

@ -46,11 +46,11 @@ class Reader: public IReader {
InferenceEngine::details::SOPointer<IReader> getReaderPtr() {
std::call_once(readFlag, [&] () {
FileUtils::FilePath libraryName = FileUtils::toFilePath(location);
FileUtils::FilePath readersLibraryPath = FileUtils::makeSharedLibraryName(getInferenceEngineLibraryPath(), libraryName);
FileUtils::FilePath readersLibraryPath = FileUtils::makePluginLibraryName(getInferenceEngineLibraryPath(), libraryName);
if (!FileUtils::fileExist(readersLibraryPath)) {
THROW_IE_EXCEPTION << "Please, make sure that Inference Engine ONNX reader library "
<< FileUtils::fromFilePath(::FileUtils::makeSharedLibraryName({}, libraryName)) << " is in "
<< FileUtils::fromFilePath(::FileUtils::makePluginLibraryName({}, libraryName)) << " is in "
<< getIELibraryPath();
}
ptr = InferenceEngine::details::SOPointer<IReader>(readersLibraryPath);
@ -107,7 +107,7 @@ void registerReaders() {
// TODO: Read readers info from XML
auto create_if_exists = [] (const std::string name, const std::string library_name) {
FileUtils::FilePath libraryName = FileUtils::toFilePath(library_name);
FileUtils::FilePath readersLibraryPath = FileUtils::makeSharedLibraryName(getInferenceEngineLibraryPath(), libraryName);
FileUtils::FilePath readersLibraryPath = FileUtils::makePluginLibraryName(getInferenceEngineLibraryPath(), libraryName);
if (!FileUtils::fileExist(readersLibraryPath))
return std::shared_ptr<Reader>();

View File

@ -45,39 +45,39 @@ const char FileSeparator = '\\';
template<> struct FileTraits<char> {
constexpr static const auto FileSeparator = ::FileUtils::FileSeparator;
static std::string SharedLibraryPrefix() { return { }; }
static std::string SharedLibraryExt() { return { "dll" }; }
static std::string PluginLibraryPrefix() { return { }; }
static std::string PluginLibraryExt() { return { "dll" }; }
};
template<> struct FileTraits<wchar_t> {
constexpr static const auto FileSeparator = L'\\';
static std::wstring SharedLibraryPrefix() { return { }; }
static std::wstring SharedLibraryExt() { return { L"dll" }; }
static std::wstring PluginLibraryPrefix() { return { }; }
static std::wstring PluginLibraryExt() { return { L"dll" }; }
};
#elif defined __APPLE__
/// @brief File path separator
const char FileSeparator = '/';
template<> struct FileTraits<char> {
constexpr static const auto FileSeparator = ::FileUtils::FileSeparator;
static std::string SharedLibraryPrefix() { return { "lib" }; }
static std::string SharedLibraryExt() { return { "dylib" }; }
static std::string PluginLibraryPrefix() { return { "lib" }; }
static std::string PluginLibraryExt() { return { "so" }; }
};
template<> struct FileTraits<wchar_t> {
constexpr static const auto FileSeparator = L'/';
static std::wstring SharedLibraryPrefix() { return { L"lib" }; }
static std::wstring SharedLibraryExt() { return { L"dylib" }; }
static std::wstring PluginLibraryPrefix() { return { L"lib" }; }
static std::wstring PluginLibraryExt() { return { L"so" }; }
};
#else
/// @brief File path separator
const char FileSeparator = '/';
template<> struct FileTraits<char> {
constexpr static const auto FileSeparator = ::FileUtils::FileSeparator;
static std::string SharedLibraryPrefix() { return { "lib" }; }
static std::string SharedLibraryExt() { return { "so" }; }
static std::string PluginLibraryPrefix() { return { "lib" }; }
static std::string PluginLibraryExt() { return { "so" }; }
};
template<> struct FileTraits<wchar_t> {
constexpr static const auto FileSeparator = L'/';
static std::wstring SharedLibraryPrefix() { return { L"lib" }; }
static std::wstring SharedLibraryExt() { return { L"so" }; }
static std::wstring PluginLibraryPrefix() { return { L"lib" }; }
static std::wstring PluginLibraryExt() { return { L"so" }; }
};
#endif
@ -172,11 +172,11 @@ inline std::basic_string<C> fileExt(const std::basic_string<C> &filename) {
}
template <typename C, typename = InferenceEngine::details::enableIfSupportedChar<C>>
inline std::basic_string<C> makeSharedLibraryName(const std::basic_string<C> &path, const std::basic_string<C> &input) {
inline std::basic_string<C> makePluginLibraryName(const std::basic_string<C> &path, const std::basic_string<C> &input) {
std::basic_string<C> separator(1, FileTraits<C>::FileSeparator);
if (path.empty())
separator = {};
return path + separator + FileTraits<C>::SharedLibraryPrefix() + input + DotSymbol<C>::value + FileTraits<C>::SharedLibraryExt();
return path + separator + FileTraits<C>::PluginLibraryPrefix() + input + DotSymbol<C>::value + FileTraits<C>::PluginLibraryExt();
}
#ifdef ENABLE_UNICODE_PATH_SUPPORT

View File

@ -122,9 +122,9 @@ target_include_directories(${TARGET_NAME}_obj PRIVATE "${CMAKE_CURRENT_SOURCE_DI
set_ie_threading_interface_for(${TARGET_NAME}_obj)
# Create shared library file from object library
# Create module library file from object library
add_library(${TARGET_NAME} SHARED
add_library(${TARGET_NAME} MODULE
$<TARGET_OBJECTS:${TARGET_NAME}_obj>)
ie_add_vs_version_file(NAME ${TARGET_NAME}

View File

@ -87,11 +87,11 @@ using PreProcessDataPtr = InferenceEngine::details::SOPointer<IPreProcessData>;
inline PreProcessDataPtr CreatePreprocDataHelper() {
FileUtils::FilePath libraryName = FileUtils::toFilePath(std::string("inference_engine_preproc") + std::string(IE_BUILD_POSTFIX));
FileUtils::FilePath preprocLibraryPath = FileUtils::makeSharedLibraryName(getInferenceEngineLibraryPath(), libraryName);
FileUtils::FilePath preprocLibraryPath = FileUtils::makePluginLibraryName(getInferenceEngineLibraryPath(), libraryName);
if (!FileUtils::fileExist(preprocLibraryPath)) {
THROW_IE_EXCEPTION << "Please, make sure that pre-processing library "
<< FileUtils::fromFilePath(::FileUtils::makeSharedLibraryName({}, libraryName)) << " is in "
<< FileUtils::fromFilePath(::FileUtils::makePluginLibraryName({}, libraryName)) << " is in "
<< getIELibraryPath();
}
return PreProcessDataPtr(preprocLibraryPath);

View File

@ -12,9 +12,9 @@ file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
source_group("src" FILES ${LIBRARY_SRC})
# Create shared library
# Create module library
add_library(${TARGET_NAME} SHARED ${LIBRARY_SRC})
add_library(${TARGET_NAME} MODULE ${LIBRARY_SRC})
ie_faster_build(${TARGET_NAME}
UNITY

View File

@ -14,9 +14,9 @@ list(APPEND LIBRARY_SRC ${IE_MAIN_SOURCE_DIR}/src/readers/ir_reader/ie_ir_reader
source_group("src" FILES ${LIBRARY_SRC})
# Create shared library
# Create module library
add_library(${TARGET_NAME} SHARED ${LIBRARY_SRC})
add_library(${TARGET_NAME} MODULE ${LIBRARY_SRC})
ie_faster_build(${TARGET_NAME}
UNITY

View File

@ -12,9 +12,9 @@ file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
source_group("src" FILES ${LIBRARY_SRC})
# Create shared library
# Create module library
add_library(${TARGET_NAME} SHARED ${LIBRARY_SRC})
add_library(${TARGET_NAME} MODULE ${LIBRARY_SRC})
ie_add_vs_version_file(NAME ${TARGET_NAME}
FILEDESCRIPTION "Inference Engine ONNX reader plugin")

View File

@ -47,7 +47,7 @@ public:
void safeAddExtension(InferenceEngine::Core & ie) {
try {
auto extension = InferenceEngine::make_so_pointer<InferenceEngine::IExtension>(
FileUtils::makeSharedLibraryName<char>({},
FileUtils::makePluginLibraryName<char>({},
std::string("template_extension") + IE_BUILD_POSTFIX));
ie.AddExtension(extension);
} catch (const InferenceEngine::details::InferenceEngineException & ex) {
@ -93,11 +93,11 @@ TEST_F(CoreThreadingTests, RegisterPlugins) {
std::ofstream file(pluginsXML);
file << "<ie><plugins><plugin location=\"";
file << FileUtils::FileTraits<char>::SharedLibraryPrefix();
file << FileUtils::FileTraits<char>::PluginLibraryPrefix();
file << "mock_engine";
file << IE_BUILD_POSTFIX;
file << FileUtils::DotSymbol<char>::value;
file << FileUtils::FileTraits<char>::SharedLibraryExt();
file << FileUtils::FileTraits<char>::PluginLibraryExt();
file << "\" name=\"";
file << indexStr;
file << "\"></plugin></plugins></ie>";

View File

@ -269,7 +269,7 @@ TEST(Extension, XmlModelWithCustomAbs) {
static std::string get_extension_path() {
return FileUtils::makeSharedLibraryName<char>({},
return FileUtils::makePluginLibraryName<char>({},
std::string("template_extension") + IE_BUILD_POSTFIX);
}

View File

@ -21,7 +21,7 @@
#endif
static std::string get_extension_path() {
return FileUtils::makeSharedLibraryName<char>(
return FileUtils::makePluginLibraryName<char>(
{}, std::string("template_extension") + IE_BUILD_POSTFIX);
}

View File

@ -17,7 +17,7 @@ IE_SUPPRESS_DEPRECATED_START
class SharedObjectLoaderTests: public ::testing::Test {
protected:
std::string get_mock_engine_name() {
return FileUtils::makeSharedLibraryName<char>(getIELibraryPath(),
return FileUtils::makePluginLibraryName<char>(getIELibraryPath(),
std::string("mock_engine") + IE_BUILD_POSTFIX);
}

View File

@ -113,7 +113,7 @@ TEST_F(SymbolLoaderTests, throwCreateNullPtr) {
}
TEST_F(SymbolLoaderTests, instantiateSymbol) {
std::string name = FileUtils::makeSharedLibraryName<char>(getIELibraryPath(),
std::string name = FileUtils::makePluginLibraryName<char>(getIELibraryPath(),
std::string("mock_engine") + IE_BUILD_POSTFIX);
std::shared_ptr<SharedObjectLoader> sharedLoader(new SharedObjectLoader(name.c_str()));
SymbolLoader<SharedObjectLoader> loader(sharedLoader);

View File

@ -235,7 +235,7 @@ TEST(IEClassBasicTest, smoke_createNonExistingConfigThrows) {
ASSERT_THROW(Core ie("nonExistPlugins.xml"), InferenceEngineException);
}
#if defined __linux__ && !defined(__APPLE__)
#ifdef __linux__
TEST(IEClassBasicTest, smoke_createMockEngineConfigNoThrows) {
SKIP_IF_CURRENT_TEST_IS_DISABLED()

View File

@ -66,7 +66,7 @@ public:
void safeAddExtension(InferenceEngine::Core & ie) {
try {
auto extension = InferenceEngine::make_so_pointer<InferenceEngine::IExtension>(
FileUtils::makeSharedLibraryName<char>({}, "template_extension"));
FileUtils::makePluginLibraryName<char>({}, "template_extension"));
ie.AddExtension(extension);
} catch (const InferenceEngine::details::InferenceEngineException & ex) {
ASSERT_STR_CONTAINS(ex.what(), "name: experimental");

View File

@ -27,7 +27,7 @@ const char DEVICE_HETERO[] = "HETERO";
#else
#if defined __APPLE__
const char pre[] = "lib";
const char ext[] = ".dylib";
const char ext[] = ".so";
#else
const char pre[] = "lib";
const char ext[] = ".so";

View File

@ -22,8 +22,8 @@ endif()
source_group("src" FILES ${LIBRARY_SRC})
source_group("include" FILES ${LIBRARY_HEADERS})
# Create library file from sources.
add_library(${TARGET_NAME} SHARED
# Create module library file from sources.
add_library(${TARGET_NAME} MODULE
${LIBRARY_SRC}
${LIBRARY_HEADERS})

View File

@ -20,7 +20,7 @@ using namespace InferenceEngine;
using ExtensionTests = ::testing::Test;
std::string getExtensionPath() {
return FileUtils::makeSharedLibraryName<char>({},
return FileUtils::makePluginLibraryName<char>({},
std::string("template_extension") + IE_BUILD_POSTFIX);
}

View File

@ -143,7 +143,6 @@ target_link_libraries(${TARGET_NAME} PRIVATE
# dynamic libraries
inference_engine_transformations
inference_engine_ir_v7_reader
inference_engine_lp_transformations)
if(TARGET libGNAStubs)