Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module library type for IE plugins, extensions #3656

Merged
merged 9 commits into from
Dec 23, 2020
12 changes: 6 additions & 6 deletions cmake/developer_package/plugins/plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
ilya-lavrenov marked this conversation as resolved.
Show resolved Hide resolved
set(LIB_SUFFIX "${IE_BUILD_POSTFIX}${CMAKE_SHARED_MODULE_SUFFIX}")

set("${library_name}" "${LIB_PREFIX}${target_name}${LIB_SUFFIX}" PARENT_SCOPE)
endfunction()
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down
40 changes: 20 additions & 20 deletions cmake/developer_package/plugins/register_plugin_cmake.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions cmake/developer_package/plugins/unregister_plugin_cmake.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

if(NOT EXISTS "${IE_CONFIG_OUTPUT_FILE}")
return()
return()
endif()

# remove plugin file
Expand All @@ -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()

Expand Down
8 changes: 4 additions & 4 deletions docs/IE_DG/inference_engine_intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
ilyachur marked this conversation as resolved.
Show resolved Hide resolved
| 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.

Expand Down
2 changes: 1 addition & 1 deletion docs/template_extension/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
3 changes: 1 addition & 2 deletions inference-engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,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()

Expand Down
2 changes: 1 addition & 1 deletion inference-engine/src/inference_engine/ie_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class Core::Impl : public ICore {
// 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;
Expand Down
6 changes: 3 additions & 3 deletions inference-engine/src/inference_engine/ie_network_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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>();
Expand Down
28 changes: 14 additions & 14 deletions inference-engine/src/plugin_api/file_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions inference-engine/src/preprocessing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions inference-engine/src/preprocessing/ie_preprocess_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions inference-engine/src/readers/ir_reader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions inference-engine/src/readers/ir_reader_v7/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions inference-engine/src/readers/onnx_reader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CoreThreadingTests : public ::testing::Test {
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) {
Expand Down Expand Up @@ -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>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading