Hide implementation of SharedObjectLoader to cpp files (#1556)

* Hide implementation of SharedObjectLoader to cpp files

* Fixed GPU tests compilation

* Fixes for Unix; check OpenCL headers with strict flags

* Fixed Windows

* More fixes for Windows

* Fixed Unit tests

* Enabled compilation with libVA for new GPU tests

* Fixes for case when libVA is not available

* Removed useless NOMINMAX

* Useless include

* Fix

* Fixes

* Fixes for Intel compiler

* Fix for Windows + Intel compiler

* Fixed samples compilation with Intel compiler
This commit is contained in:
Ilya Lavrenov 2020-08-03 14:01:56 +03:00 committed by GitHub
parent 03dda94c5d
commit 9f767f7b93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 184 additions and 142 deletions

View File

@ -238,16 +238,17 @@ if(WIN32)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
# 161 unrecognized pragma
# 177 variable was declared but never referenced
# 556 not matched type of assigned function pointer
# 161: unrecognized pragma
# 177: variable was declared but never referenced
# 556: not matched type of assigned function pointer
# 1744: field of class type without a DLL interface used in a class with a DLL interface
# 2586 decorated name length exceeded, name was truncated
# 1879: unimplemented pragma ignored
# 2586: decorated name length exceeded, name was truncated
# 2651: attribute does not apply to any entity
# 3180 unrecognized OpenMP pragma
# 3180: unrecognized OpenMP pragma
# 11075: To get full report use -Qopt-report:4 -Qopt-report-phase ipo
# 15335 was not vectorized: vectorization possible but seems inefficient. Use vector always directive or /Qvec-threshold0 to override
ie_add_compiler_flags(/Qdiag-disable:161,177,556,1744,2586,2651,3180,11075,15335)
# 15335: was not vectorized: vectorization possible but seems inefficient. Use vector always directive or /Qvec-threshold0 to override
ie_add_compiler_flags(/Qdiag-disable:161,177,556,1744,1879,2586,2651,3180,11075,15335)
endif()
# Debug information flags

View File

@ -63,7 +63,7 @@ function(set_ie_threading_interface_for TARGET_NAME)
set(omp_lib_name iomp5)
endif ()
if (NOT(IE_MAIN_SOURCE_DIR))
if (NOT IE_MAIN_SOURCE_DIR)
if (WIN32)
set(lib_rel_path ${IE_LIB_REL_DIR})
set(lib_dbg_path ${IE_LIB_DBG_DIR})

View File

@ -9,8 +9,53 @@
*/
#pragma once
#ifndef _WIN32
# include "os/lin_shared_object_loader.h"
#else
# include "os/win_shared_object_loader.h"
#include <memory>
#include "ie_api.h"
namespace InferenceEngine {
namespace details {
/**
* @brief This class provides an OS shared module abstraction
*/
class INFERENCE_ENGINE_API_CLASS(SharedObjectLoader) {
class Impl;
std::shared_ptr<Impl> _impl;
public:
/**
* @brief A shared pointer to SharedObjectLoader
*/
using Ptr = std::shared_ptr<SharedObjectLoader>;
#ifdef ENABLE_UNICODE_PATH_SUPPORT
/**
* @brief Loads a library with the wide char name specified.
* @param pluginName Full or relative path to the plugin library
*/
explicit SharedObjectLoader(const wchar_t* pluginName);
#endif
/**
* @brief Loads a library with the name specified.
* @param pluginName Full or relative path to the plugin library
*/
explicit SharedObjectLoader(const char * pluginName);
/**
* @brief A destructor
*/
~SharedObjectLoader() noexcept(false);
/**
* @brief Searches for a function symbol in the loaded module
* @param symbolName Name of function to find
* @return A pointer to the function if found
* @throws InferenceEngineException if the function is not found
*/
void* get_symbol(const char* symbolName) const;
};
} // namespace details
} // namespace InferenceEngine

View File

@ -15,6 +15,7 @@
#include "ie_compound_blob.h"
#include "ie_remote_context.hpp"
#include "ie_core.hpp"
#include "gpu/gpu_params.hpp"
#include "gpu/gpu_ocl_wrapper.hpp"
@ -265,6 +266,6 @@ static inline Blob::Ptr make_shared_blob(const TensorDesc& desc, RemoteContext::
return std::dynamic_pointer_cast<Blob>(casted->CreateBlob(desc, params));
}
}; // namespace gpu
} // namespace gpu
}; // namespace InferenceEngine
} // namespace InferenceEngine

View File

@ -22,9 +22,14 @@
#define IE_THREAD_TBB_AUTO 3
#if (IE_THREAD == IE_THREAD_TBB || IE_THREAD == IE_THREAD_TBB_AUTO)
#define TBB_PREVIEW_LOCAL_OBSERVER 1
#ifndef NOMINMAX
# define NOMINMAX
#endif
#ifndef TBB_PREVIEW_LOCAL_OBSERVER
# define TBB_PREVIEW_LOCAL_OBSERVER 1
#endif
#ifndef TBB_PREVIEW_NUMA_SUPPORT
#define TBB_PREVIEW_NUMA_SUPPORT 1
# define TBB_PREVIEW_NUMA_SUPPORT 1
#endif
#include "tbb/blocked_range.h"
#include "tbb/blocked_range2d.h"
@ -44,7 +49,7 @@ inline int parallel_get_num_threads() {
inline int parallel_get_thread_num() {
return tbb::this_task_arena::current_thread_index();
}
inline void parallel_set_num_threads(int n) {
inline void parallel_set_num_threads(int) {
return;
}
inline int parallel_get_env_threads() {
@ -104,7 +109,7 @@ inline int parallel_get_num_threads() {
inline int parallel_get_thread_num() {
return 0;
}
inline void parallel_set_num_threads(int n) {
inline void parallel_set_num_threads(int) {
return;
}
#endif

View File

@ -72,6 +72,10 @@ if (WIN32)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX") #treating warnings as errors
endif ()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qdiag-disable:177")
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251 /wd4275 /wd4267 /wd4819") #disable some warnings
endif()

View File

@ -35,9 +35,6 @@
#include <ie_util_internal.hpp>
#include <graph_transformer.h>
#undef min
#undef max
#include "cldnn_engine.h"
#include "cldnn_executable_network.h"
#include "cldnn_custom_layer.h"

View File

@ -26,7 +26,6 @@
#include <utility>
#include <sys/types.h>
#include <exec_graph_info.hpp>
#include "cldnn_executable_network.h"
#include "threading/ie_cpu_streams_executor.hpp"

View File

@ -4,6 +4,10 @@
#pragma once
#ifndef NOMINMAX
# define NOMINMAX
#endif
#include <vector>
#include <map>
#include <set>

View File

@ -7,7 +7,6 @@
#include <map>
#include <functional>
#include <utility>
#include <api/detection_output.hpp> // todo: find a way to remove this
#include <description_buffer.hpp>
#include "cldnn_infer_request.h"
#include "cldnn_remote_context.h"

View File

@ -14,6 +14,11 @@
#include <api/memory.hpp>
#include <api/engine.hpp>
#include "cldnn_common_utils.h"
#ifndef NOMINMAX
# define NOMINMAX
#endif
#ifdef WIN32
#include <gpu/gpu_context_api_dx.hpp>
#else

View File

@ -31,7 +31,6 @@ set(IE_BASE_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/network_serializer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/system_allocator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/system_allocator.hpp)
list(REMOVE_ITEM LIBRARY_SRC ${IE_BASE_SOURCE_FILES})
if (LINUX)
file (GLOB LIBRARY_SRC
@ -42,6 +41,10 @@ if (LINUX)
${CMAKE_CURRENT_SOURCE_DIR}/os/lin/*.hpp)
endif()
if(UNIX)
list(APPEND IE_BASE_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/os/lin/lin_shared_object_loader.cpp)
endif()
if (WIN32)
file (GLOB LIBRARY_SRC
${LIBRARY_SRC}
@ -49,8 +52,11 @@ if (WIN32)
file (GLOB LIBRARY_HEADERS
${LIBRARY_HEADERS}
${CMAKE_CURRENT_SOURCE_DIR}/os/win/*.hpp)
list(APPEND IE_BASE_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/os/win/win_shared_object_loader.cpp)
endif()
list(REMOVE_ITEM LIBRARY_SRC ${IE_BASE_SOURCE_FILES})
file (GLOB LIBRARY_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/*.h
${CMAKE_CURRENT_SOURCE_DIR}/*.hpp
@ -141,11 +147,6 @@ endif()
set_ie_threading_interface_for(${TARGET_NAME}_obj)
if(WIN32)
# To disable min/max macro in windows.h
target_compile_definitions(${TARGET_NAME}_obj PRIVATE -DNOMINMAX)
endif()
add_cpplint_target(${TARGET_NAME}_cpplint FOR_TARGETS ${TARGET_NAME}_obj)
# Create shared library file from object library

View File

@ -19,6 +19,9 @@
#ifndef _WIN32
# include <limits.h>
# include <unistd.h>
# include <dlfcn.h>
#else
# include <Windows.h>
#endif
#include "details/ie_so_pointer.hpp"

View File

@ -2,41 +2,21 @@
// SPDX-License-Identifier: Apache-2.0
//
/**
* @brief POSIX compatible loader for a shared object
*
* @file lin_shared_object_loader.h
*/
#pragma once
#include <dlfcn.h>
#include "ie_api.h"
#include "details/ie_exception.hpp"
#include "details/os/os_filesystem.hpp"
#include "details/ie_so_loader.h"
namespace InferenceEngine {
namespace details {
/**
* @brief This class provides an OS shared module abstraction
*/
class SharedObjectLoader {
class SharedObjectLoader::Impl {
private:
void* shared_object = nullptr;
public:
/**
* @brief A shared pointer to SharedObjectLoader
*/
using Ptr = std::shared_ptr<InferenceEngine::details::SharedObjectLoader>;
/**
* @brief Loads a library with the name specified. The library is loaded according to
* the POSIX rules for dlopen
* @param pluginName Full or relative path to the library
*/
explicit SharedObjectLoader(const char* pluginName) {
explicit Impl(const char* pluginName) {
shared_object = dlopen(pluginName, RTLD_LAZY);
if (shared_object == nullptr)
@ -44,17 +24,11 @@ public:
}
#ifdef ENABLE_UNICODE_PATH_SUPPORT
/**
* @brief Loads a library with the name specified. The library is loaded according to
* the POSIX rules for dlopen
* @param pluginName Full or relative path to the library
*/
explicit SharedObjectLoader(const wchar_t* pluginName) : SharedObjectLoader(wStringtoMBCSstringChar(pluginName).c_str()) {
explicit Impl(const wchar_t* pluginName) : Impl(wStringtoMBCSstringChar(pluginName).c_str()) {
}
#endif // ENABLE_UNICODE_PATH_SUPPORT
~SharedObjectLoader() noexcept(false) {
~Impl() noexcept(false) {
if (0 != dlclose(shared_object)) {
THROW_IE_EXCEPTION << "dlclose failed: " << dlerror();
}
@ -76,5 +50,22 @@ public:
}
};
#ifdef ENABLE_UNICODE_PATH_SUPPORT
SharedObjectLoader::SharedObjectLoader(const wchar_t* pluginName) {
_impl.reset(new Impl(pluginName));
}
#endif
SharedObjectLoader::SharedObjectLoader(const char * pluginName) {
_impl.reset(new Impl(pluginName));
}
SharedObjectLoader::~SharedObjectLoader() noexcept(false) {
}
void* SharedObjectLoader::get_symbol(const char* symbolName) const {
return _impl->get_symbol(symbolName);
}
} // namespace details
} // namespace InferenceEngine

View File

@ -2,26 +2,9 @@
// SPDX-License-Identifier: Apache-2.0
//
/**
* @brief WINAPI compatible loader for a shared object
*
* @file win_shared_object_loader.h
*/
#pragma once
#include "ie_api.h"
#include "details/ie_exception.hpp"
#include "details/os/os_filesystem.hpp"
// Avoidance of Windows.h to include winsock library.
#ifndef _WINSOCKAPI_
# define _WINSOCKAPI_
#endif
// Avoidance of Windows.h to define min/max.
#ifndef NOMINMAX
# define NOMINMAX
#endif
#include "details/ie_so_loader.h"
#include <direct.h>
#include <windows.h>
@ -29,10 +12,7 @@
namespace InferenceEngine {
namespace details {
/**
* @brief This class provides an OS shared module abstraction
*/
class SharedObjectLoader {
class SharedObjectLoader::Impl {
private:
HMODULE shared_object;
@ -49,18 +29,8 @@ private:
}
public:
/**
* @brief A shared pointer to SharedObjectLoader
*/
using Ptr = std::shared_ptr<SharedObjectLoader>;
#ifdef ENABLE_UNICODE_PATH_SUPPORT
/**
* @brief Loads a library with the name specified. The library is loaded according to the
* WinAPI LoadLibrary rules
* @param pluginName Full or relative path to the plugin library
*/
explicit SharedObjectLoader(LPCWSTR pluginName) {
explicit Impl(const wchar_t* pluginName) {
ExcludeCurrentDirectory();
shared_object = LoadLibraryW(pluginName);
@ -72,7 +42,7 @@ public:
}
#endif
explicit SharedObjectLoader(LPCSTR pluginName) {
explicit Impl(const char* pluginName) {
ExcludeCurrentDirectory();
shared_object = LoadLibraryA(pluginName);
@ -83,16 +53,10 @@ public:
}
}
~SharedObjectLoader() {
~Impl() {
FreeLibrary(shared_object);
}
/**
* @brief Searches for a function symbol in the loaded module
* @param symbolName Name of function to find
* @return A pointer to the function if found
* @throws InferenceEngineException if the function is not found
*/
void* get_symbol(const char* symbolName) const {
if (!shared_object) {
THROW_IE_EXCEPTION << "Cannot get '" << symbolName << "' content from unknown library!";
@ -105,5 +69,22 @@ public:
}
};
#ifdef ENABLE_UNICODE_PATH_SUPPORT
SharedObjectLoader::SharedObjectLoader(const wchar_t* pluginName) {
_impl = std::make_shared<Impl>(pluginName);
}
#endif
SharedObjectLoader::~SharedObjectLoader() noexcept(false) {
}
SharedObjectLoader::SharedObjectLoader(const char * pluginName) {
_impl = std::make_shared<Impl>(pluginName);
}
void* SharedObjectLoader::get_symbol(const char* symbolName) const {
return _impl->get_symbol(symbolName);
}
} // namespace details
} // namespace InferenceEngine

View File

@ -127,7 +127,7 @@ void InferenceEngine::details::CNNLayerCreator::on_adapter(const std::string& na
} else if (auto a = ::ngraph::as_type<::ngraph::AttributeAdapter<::ngraph::PartialShape>>(&adapter)) {
std::string dims;
auto shape = static_cast<::ngraph::PartialShape&>(*a);
for (size_t i = 0; i < shape.rank().get_length(); i++) {
for (int64_t i = 0; i < shape.rank().get_length(); i++) {
if (!dims.empty()) dims += ",";
dims += std::to_string(shape[i].get_length());
}

View File

@ -63,7 +63,7 @@ Paddings getPaddingsInternal(const Layer& layer) {
bool is_deconv = (layer.type == "Deconvolution");
for (size_t i = 0; i < layer._kernel.size(); i++) {
float PA = 0;
int PA = 0;
int kernel = getKernel(layer, i);
int stride = layer._stride.size() > i ? layer._stride[i] : 1;

View File

@ -2,9 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
//
// avoiding clash of the "max" macro with std::max
#define NOMINMAX
#include "config.h"
#include <string>

View File

@ -23,7 +23,7 @@
#include <ie_parallel.hpp>
#if (IE_THREAD == IE_THREAD_TBB || IE_THREAD == IE_THREAD_TBB_AUTO)
#include <tbb/concurrent_queue.h>
# include <tbb/concurrent_queue.h>
#endif
namespace MultiDevicePlugin {

View File

@ -10,15 +10,16 @@
*/
#include "ie_parallel.hpp"
#if IE_THREAD == IE_THREAD_TBB || IE_THREAD == IE_THREAD_TBB_AUTO
#include <tbb/enumerable_thread_specific.h>
# include <tbb/enumerable_thread_specific.h>
#else
#include <unordered_map>
#include <memory>
#include <thread>
#include <mutex>
#include <utility>
#include <functional>
# include <unordered_map>
# include <memory>
# include <thread>
# include <mutex>
# include <utility>
# include <functional>
#endif
namespace InferenceEngine {

View File

@ -139,11 +139,6 @@ target_include_directories(${TARGET_NAME}_obj SYSTEM PRIVATE "${IE_MAIN_SOURCE_D
target_include_directories(${TARGET_NAME}_obj PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}"
$<TARGET_PROPERTY:openvino::itt,INTERFACE_INCLUDE_DIRECTORIES>)
if(WIN32)
# To disable min/max macro in windows.h
target_compile_definitions(${TARGET_NAME}_obj PRIVATE NOMINMAX)
endif()
set_ie_threading_interface_for(${TARGET_NAME}_obj)
# Create shared library file from object library

View File

@ -58,27 +58,21 @@ function(ie_headers_compilation_with_custom_flags)
set(IE_TEST_CXX_STANDARD ${CMAKE_CXX_STANDARD})
endif()
if(NOT CLDNN__IOCL_ICD_INCDIRS)
list(APPEND IE_TEST_HEADERS_TO_SKIP "gpu/gpu_ocl_wrapper.hpp"
"gpu/gpu_context_api_ocl.hpp"
"gpu/gpu_context_api_va.hpp"
"gpu/gpu_context_api_dx.hpp")
endif()
if(NOT WIN32)
list(APPEND IE_TEST_HEADERS_TO_SKIP "gpu/gpu_context_api_dx.hpp")
endif()
if(NOT LIBVA_FOUND)
list(APPEND IE_TEST_HEADERS_TO_SKIP "gpu/gpu_context_api_va.hpp")
endif()
set(content "\n")
foreach(header_file IN LISTS header_files)
# OpenCL is not available
if(header_file STREQUAL "ie_parallel.hpp" OR
header_file STREQUAL "gpu/gpu_ocl_wrapper.hpp" OR
header_file STREQUAL "gpu/gpu_context_api_ocl.hpp" OR
header_file STREQUAL "gpu/gpu_context_api_dx.hpp" OR
header_file STREQUAL "gpu/gpu_context_api_va.hpp")
continue()
endif()
# Skip Windows header on Unix
if(UNIX AND header_file STREQUAL "details/os/win_shared_object_loader.h")
continue()
endif()
# Skip Unix heaeder on Windows
if(WIN32 AND header_file STREQUAL "details/os/lin_shared_object_loader.h")
continue()
endif()
# skip user-passed headers
set(skip_current_file OFF)
foreach(skip_file IN LISTS IE_TEST_HEADERS_TO_SKIP)
@ -104,7 +98,15 @@ function(ie_headers_compilation_with_custom_flags)
add_library(${target_name} OBJECT ${source_file})
target_include_directories(${target_name} PRIVATE $<TARGET_PROPERTY:inference_engine,INTERFACE_INCLUDE_DIRECTORIES>)
target_compile_definitions(${target_name} PRIVATE $<TARGET_PROPERTY:inference_engine,INTERFACE_COMPILE_DEFINITIONS>)
# To include TBB headers as system
set_ie_threading_interface_for(${target_name})
# OpenCL headers if any
if(CLDNN__IOCL_ICD_INCDIRS)
target_include_directories(${target_name} SYSTEM PRIVATE ${CLDNN__IOCL_ICD_INCDIRS})
endif()
set_target_properties(${target_name} PROPERTIES
CXX_STANDARD ${IE_TEST_CXX_STANDARD}
CXX_STANDARD_REQUIRED OFF)
@ -133,7 +135,10 @@ if(UNIX)
endif()
else()
ie_headers_compilation_with_custom_flags(TEST_SUFFIX WindowsAreErrors
FLAGS "/we4996 /W4 /WX")
HEADERS_TO_SKIP "gpu/gpu_ocl_wrapper.hpp"
"gpu/gpu_context_api_ocl.hpp"
"gpu/gpu_context_api_dx.hpp"
FLAGS "/we4996 /W4 /WX")
ie_headers_compilation_with_custom_flags(TEST_SUFFIX Unicode
DEFINITIONS UNICODE _UNICODE)
endif()

View File

@ -22,3 +22,9 @@ addIeTargetTest(
LABELS
GPU
)
if(LIBVA_FOUND)
target_compile_definitions(${TARGET_NAME} PRIVATE ENABLE_LIBVA)
target_include_directories(${TARGET_NAME} PRIVATE ${LIBVA_INCLUDE_DIRS})
target_link_libraries(${TARGET_NAME} PRIVATE ${LIBVA_LINK_LIBRARIES})
endif()

View File

@ -7,7 +7,6 @@
#include <vector>
#include <memory>
#include <inference_engine.hpp>
#include <ie_compound_blob.h>
#include <cldnn/cldnn_config.hpp>

View File

@ -7,6 +7,9 @@
#include <vector>
#include <memory>
#ifndef NOMINMAX
# define NOMINMAX
#endif
#ifdef _WIN32
# include <gpu/gpu_context_api_dx.hpp>

View File

@ -31,7 +31,7 @@ pkg_search_module(LIBVA QUIET libva)
# TODO: pkg_search_module finds libva not in sysroot
if(ANDROID)
set(LIBVA_FOUND OFF)
set(LIBVA_FOUND OFF CACHE BOOL "" FORCE)
endif()
if(LIBVA_FOUND)