fixes for UWP (#2255)
* UWP fixes * Commented code for compilation with UWP * Current state: compiled for DESKTOP_APP * Fixes * Added toolchain * Enabled ONNX imported for Windows Store * Updated toolchain * Fixes * Disable ONNX in case of UWP * Fix for Windows Driver * Applied style check * Dynamic loading of GetDLLDirectory symbols * Clean-up in the toolchain * Updated mkldnn plugin cmake
This commit is contained in:
parent
cd391389ce
commit
147a508a51
@ -73,7 +73,7 @@ function(build_ngraph)
|
||||
ngraph_set(NGRAPH_UNIT_TEST_ENABLE FALSE)
|
||||
endif()
|
||||
|
||||
if(NOT ANDROID)
|
||||
if(NOT (ANDROID OR WINDOWS_STORE))
|
||||
ngraph_set(NGRAPH_ONNX_IMPORT_ENABLE TRUE)
|
||||
else()
|
||||
ngraph_set(NGRAPH_ONNX_IMPORT_ENABLE FALSE)
|
||||
|
@ -6,20 +6,20 @@ set_temp_directory(TEMP "${IE_MAIN_SOURCE_DIR}")
|
||||
|
||||
include(dependency_solver)
|
||||
|
||||
if(CMAKE_CROSSCOMPILING)
|
||||
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
|
||||
set(HOST_X86_64 ON)
|
||||
endif()
|
||||
if(CMAKE_CROSSCOMPILING AND NGRAPH_ONNX_IMPORT_ENABLE)
|
||||
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
|
||||
set(HOST_X86_64 ON)
|
||||
endif()
|
||||
|
||||
set(protoc_version "3.7.1")
|
||||
if(CMAKE_HOST_SYSTEM_NAME MATCHES Linux)
|
||||
RESOLVE_DEPENDENCY(SYSTEM_PROTOC_ROOT
|
||||
ARCHIVE_LIN "protoc-${protoc_version}-linux-x86_64.tar.gz"
|
||||
TARGET_PATH "${TEMP}/protoc-${protoc_version}-linux-x86_64")
|
||||
debug_message(STATUS "host protoc-${protoc_version} root path = " ${SYSTEM_PROTOC_ROOT})
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported host system (${CMAKE_HOST_SYSTEM_NAME}) and arch (${CMAKE_HOST_SYSTEM_PROCESSOR}) for cross-compilation")
|
||||
endif()
|
||||
set(protoc_version "3.7.1")
|
||||
if(CMAKE_HOST_SYSTEM_NAME MATCHES Linux)
|
||||
RESOLVE_DEPENDENCY(SYSTEM_PROTOC_ROOT
|
||||
ARCHIVE_LIN "protoc-${protoc_version}-linux-x86_64.tar.gz"
|
||||
TARGET_PATH "${TEMP}/protoc-${protoc_version}-linux-x86_64")
|
||||
debug_message(STATUS "host protoc-${protoc_version} root path = " ${SYSTEM_PROTOC_ROOT})
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported host system (${CMAKE_HOST_SYSTEM_NAME}) and arch (${CMAKE_HOST_SYSTEM_PROCESSOR}) for cross-compilation")
|
||||
endif()
|
||||
|
||||
reset_deps_cache(SYSTEM_PROTOC)
|
||||
|
||||
|
@ -17,7 +17,7 @@ ie_option (ENABLE_TESTS "unit, behavior and functional tests" OFF)
|
||||
|
||||
ie_option (ENABLE_MKL_DNN "MKL-DNN plugin for inference engine" ${ENABLE_MKL_DNN_DEFAULT})
|
||||
|
||||
ie_dependent_option (ENABLE_CLDNN "clDnn based plugin for inference engine" ON "WIN32 OR X86_64;NOT APPLE;NOT MINGW" OFF)
|
||||
ie_dependent_option (ENABLE_CLDNN "clDnn based plugin for inference engine" ON "WIN32 OR X86_64;NOT APPLE;NOT MINGW;NOT WINDOWS_STORE; NOT WINDOWS_PHONE" OFF)
|
||||
|
||||
# FIXME: there are compiler failures with LTO and Cross-Compile toolchains. Disabling for now, but
|
||||
# this must be addressed in a proper way
|
||||
|
22
cmake/uwp.toolchain.cmake
Normal file
22
cmake/uwp.toolchain.cmake
Normal file
@ -0,0 +1,22 @@
|
||||
# Copyright (C) 2018-2020 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
set(CMAKE_SYSTEM_NAME WindowsStore)
|
||||
set(CMAKE_SYSTEM_VERSION 10.0)
|
||||
|
||||
if (NOT DEFINED CMAKE_SYSTEM_PROCESSOR)
|
||||
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR})
|
||||
endif()
|
||||
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/src/uwp.hpp"
|
||||
"#ifdef WINAPI_FAMILY\n"
|
||||
"#undef WINAPI_FAMILY\n"
|
||||
"#define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP\n"
|
||||
"#endif\n")
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FI\"${CMAKE_CURRENT_BINARY_DIR}/src/uwp.hpp\"")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /FI\"${CMAKE_CURRENT_BINARY_DIR}/src/uwp.hpp\"")
|
||||
|
||||
# UWP setting for package isolation
|
||||
# set(CMAKE_VS_GLOBALS "AppContainerApplication=true")
|
@ -60,7 +60,7 @@ if (ENABLE_GNA)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
ie_option (ENABLE_VPU "vpu targeted plugins for inference engine" ON)
|
||||
ie_dependent_option (ENABLE_VPU "vpu targeted plugins for inference engine" ON "NOT WINDOWS_PHONE;NOT WINDOWS_STORE" OFF)
|
||||
|
||||
ie_dependent_option (ENABLE_MYRIAD "myriad targeted plugin for inference engine" ON "ENABLE_VPU" OFF)
|
||||
|
||||
|
@ -218,7 +218,7 @@ macro(ie_add_sample)
|
||||
|
||||
set(folder_name cpp_samples)
|
||||
if(IE_SAMPLE_NAME MATCHES ".*_c$")
|
||||
set(c_sample ON)
|
||||
set(c_sample ON)
|
||||
set(folder_name c_samples)
|
||||
endif()
|
||||
|
||||
@ -232,7 +232,6 @@ macro(ie_add_sample)
|
||||
|
||||
target_link_libraries(${IE_SAMPLE_NAME} PRIVATE ${OpenCV_LIBRARIES} ${InferenceEngine_LIBRARIES}
|
||||
${IE_SAMPLE_DEPENDENCIES})
|
||||
|
||||
if(NOT c_sample)
|
||||
target_link_libraries(${IE_SAMPLE_NAME} PRIVATE gflags)
|
||||
endif()
|
||||
|
@ -19,6 +19,9 @@
|
||||
# include <unistd.h>
|
||||
# include <dlfcn.h>
|
||||
#else
|
||||
# if defined(WINAPI_FAMILY) && !WINAPI_PARTITION_DESKTOP
|
||||
# error "Only WINAPI_PARTITION_DESKTOP is supported, because of GetModuleHandleEx[A|W]"
|
||||
# endif
|
||||
# include <Windows.h>
|
||||
#endif
|
||||
|
||||
@ -51,48 +54,52 @@ std::basic_string<C> getPathName(const std::basic_string<C>& s) {
|
||||
|
||||
static std::string getIELibraryPathA() {
|
||||
#ifdef _WIN32
|
||||
char ie_library_path[4096];
|
||||
CHAR ie_library_path[MAX_PATH];
|
||||
HMODULE hm = NULL;
|
||||
if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||
(LPCSTR)getIELibraryPath, &hm)) {
|
||||
if (!GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||
reinterpret_cast<LPSTR>(getIELibraryPath), &hm)) {
|
||||
THROW_IE_EXCEPTION << "GetModuleHandle returned " << GetLastError();
|
||||
}
|
||||
GetModuleFileName(hm, (LPSTR)ie_library_path, sizeof(ie_library_path));
|
||||
GetModuleFileNameA(hm, (LPSTR)ie_library_path, sizeof(ie_library_path));
|
||||
return getPathName(std::string(ie_library_path));
|
||||
#else
|
||||
#ifdef USE_STATIC_IE
|
||||
#ifdef __APPLE__
|
||||
#elif defined(__APPLE__) || defined(__linux__)
|
||||
# ifdef USE_STATIC_IE
|
||||
# ifdef __APPLE__
|
||||
Dl_info info;
|
||||
dladdr(reinterpret_cast<void*>(getIELibraryPath), &info);
|
||||
std::string path = getPathName(std::string(info.dli_fname)).c_str();
|
||||
#else
|
||||
# else
|
||||
char result[PATH_MAX];
|
||||
ssize_t count = readlink("/proc/self/exe", result, PATH_MAX);
|
||||
std::string path = getPathName(std::string(result, (count > 0) ? count : 0));
|
||||
#endif // __APPLE__
|
||||
# endif // __APPLE__
|
||||
return FileUtils::makePath(path, std::string( "lib"));
|
||||
#else
|
||||
# else
|
||||
Dl_info info;
|
||||
dladdr(reinterpret_cast<void*>(getIELibraryPath), &info);
|
||||
return getPathName(std::string(info.dli_fname)).c_str();
|
||||
#endif // USE_STATIC_IE
|
||||
# endif // USE_STATIC_IE
|
||||
#else
|
||||
# error "Unsupported OS"
|
||||
#endif // _WIN32
|
||||
}
|
||||
|
||||
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
||||
|
||||
std::wstring getIELibraryPathW() {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
wchar_t ie_library_path[4096];
|
||||
#ifdef _WIN32
|
||||
WCHAR ie_library_path[MAX_PATH];
|
||||
HMODULE hm = NULL;
|
||||
if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||
(LPCWSTR)getIELibraryPath, &hm)) {
|
||||
reinterpret_cast<LPCWSTR>(getIELibraryPath), &hm)) {
|
||||
THROW_IE_EXCEPTION << "GetModuleHandle returned " << GetLastError();
|
||||
}
|
||||
GetModuleFileNameW(hm, (LPWSTR)ie_library_path, sizeof(ie_library_path));
|
||||
GetModuleFileNameW(hm, (LPWSTR)ie_library_path, sizeof(ie_library_path) / sizeof(ie_library_path[0]));
|
||||
return getPathName(std::wstring(ie_library_path));
|
||||
#else
|
||||
#elif defined(__linux__) || defined(__APPLE__)
|
||||
return ::FileUtils::multiByteCharToWString(getIELibraryPathA().c_str());
|
||||
#else
|
||||
# error "Unsupported OS"
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,61 @@
|
||||
#include "details/ie_so_loader.h"
|
||||
#include "file_utils.h"
|
||||
|
||||
//
|
||||
// LoadLibraryA, LoadLibraryW:
|
||||
// WINAPI_FAMILY_DESKTOP_APP - OK (default)
|
||||
// WINAPI_FAMILY_PC_APP - FAIL ?? (defined by cmake)
|
||||
// WINAPI_FAMILY_PHONE_APP - FAIL ??
|
||||
// WINAPI_FAMILY_GAMES - OK
|
||||
// WINAPI_FAMILY_SERVER - OK
|
||||
// WINAPI_FAMILY_SYSTEM - OK
|
||||
//
|
||||
// GetModuleHandleExA, GetModuleHandleExW:
|
||||
// WINAPI_FAMILY_DESKTOP_APP - OK (default)
|
||||
// WINAPI_FAMILY_PC_APP - FAIL ?? (defined by cmake)
|
||||
// WINAPI_FAMILY_PHONE_APP - FAIL ??
|
||||
// WINAPI_FAMILY_GAMES - OK
|
||||
// WINAPI_FAMILY_SERVER - OK
|
||||
// WINAPI_FAMILY_SYSTEM - OK
|
||||
//
|
||||
// GetModuleHandleA, GetModuleHandleW:
|
||||
// WINAPI_FAMILY_DESKTOP_APP - OK (default)
|
||||
// WINAPI_FAMILY_PC_APP - FAIL ?? (defined by cmake)
|
||||
// WINAPI_FAMILY_PHONE_APP - FAIL ??
|
||||
// WINAPI_FAMILY_GAMES - OK
|
||||
// WINAPI_FAMILY_SERVER - OK
|
||||
// WINAPI_FAMILY_SYSTEM - OK
|
||||
//
|
||||
// SetDllDirectoryA, SetDllDirectoryW:
|
||||
// WINAPI_FAMILY_DESKTOP_APP - OK (default)
|
||||
// WINAPI_FAMILY_PC_APP - FAIL ?? (defined by cmake)
|
||||
// WINAPI_FAMILY_PHONE_APP - FAIL ??
|
||||
// WINAPI_FAMILY_GAMES - OK
|
||||
// WINAPI_FAMILY_SERVER - FAIL
|
||||
// WINAPI_FAMILY_SYSTEM - FAIL
|
||||
//
|
||||
// GetDllDirectoryA, GetDllDirectoryW:
|
||||
// WINAPI_FAMILY_DESKTOP_APP - FAIL
|
||||
// WINAPI_FAMILY_PC_APP - FAIL (defined by cmake)
|
||||
// WINAPI_FAMILY_PHONE_APP - FAIL
|
||||
// WINAPI_FAMILY_GAMES - FAIL
|
||||
// WINAPI_FAMILY_SERVER - FAIL
|
||||
// WINAPI_FAMILY_SYSTEM - FAIL
|
||||
//
|
||||
// SetupDiGetClassDevsA, SetupDiEnumDeviceInfo, SetupDiGetDeviceInstanceIdA, SetupDiDestroyDeviceInfoList:
|
||||
// WINAPI_FAMILY_DESKTOP_APP - FAIL (default)
|
||||
// WINAPI_FAMILY_PC_APP - FAIL (defined by cmake)
|
||||
// WINAPI_FAMILY_PHONE_APP - FAIL
|
||||
// WINAPI_FAMILY_GAMES - FAIL
|
||||
// WINAPI_FAMILY_SERVER - FAIL
|
||||
// WINAPI_FAMILY_SYSTEM - FAIL
|
||||
//
|
||||
|
||||
#if defined(WINAPI_FAMILY) && !WINAPI_PARTITION_DESKTOP
|
||||
# error "Only WINAPI_PARTITION_DESKTOP is supported, because of LoadLibrary[A|W]"
|
||||
#endif
|
||||
|
||||
#include <mutex>
|
||||
#include <direct.h>
|
||||
#include <windows.h>
|
||||
|
||||
@ -16,22 +71,53 @@ class SharedObjectLoader::Impl {
|
||||
private:
|
||||
HMODULE shared_object;
|
||||
|
||||
void ExcludeCurrentDirectory() {
|
||||
// Exclude current directory from DLL search path process wise.
|
||||
// If application specific path was configured before then
|
||||
// current directory is alread excluded.
|
||||
// GetDLLDirectory does not distinguish if aplication specific
|
||||
// path was set to "" or NULL so reset it to "" to keep
|
||||
// aplication safe.
|
||||
if (GetDllDirectory(0, NULL) <= 1) {
|
||||
SetDllDirectory(TEXT(""));
|
||||
}
|
||||
typedef DWORD(* GetDllDirectoryA_Fnc)(DWORD, LPSTR);
|
||||
typedef DWORD(* GetDllDirectoryW_Fnc)(DWORD, LPWSTR);
|
||||
|
||||
static GetDllDirectoryA_Fnc IEGetDllDirectoryA;
|
||||
static GetDllDirectoryW_Fnc IEGetDllDirectoryW;
|
||||
|
||||
void LoadSymbols() {
|
||||
static std::once_flag loadFlag;
|
||||
std::call_once(loadFlag, [&] () {
|
||||
if (HMODULE hm = GetModuleHandleW(L"kernel32.dll")) {
|
||||
IEGetDllDirectoryA = reinterpret_cast<GetDllDirectoryA_Fnc>(GetProcAddress(hm, "GetDllDirectoryA"));
|
||||
IEGetDllDirectoryW = reinterpret_cast<GetDllDirectoryW_Fnc>(GetProcAddress(hm, "GetDllDirectoryW"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Exclude current directory from DLL search path process wise.
|
||||
// If application specific path was configured before then
|
||||
// current directory is already excluded.
|
||||
// GetDLLDirectory does not distinguish if aplication specific
|
||||
// path was set to "" or NULL so reset it to "" to keep
|
||||
// application safe.
|
||||
void ExcludeCurrentDirectoryA() {
|
||||
GetDllDirectoryA;
|
||||
#ifndef WINAPI_FAMILY
|
||||
LoadSymbols();
|
||||
if (IEGetDllDirectoryA && IEGetDllDirectoryA(0, NULL) <= 1) {
|
||||
SetDllDirectoryA("");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
||||
void ExcludeCurrentDirectoryW() {
|
||||
#ifndef WINAPI_FAMILY
|
||||
LoadSymbols();
|
||||
if (IEGetDllDirectoryW && IEGetDllDirectoryW(0, NULL) <= 1) {
|
||||
SetDllDirectoryW(L"");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
public:
|
||||
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
||||
explicit Impl(const wchar_t* pluginName) {
|
||||
ExcludeCurrentDirectory();
|
||||
ExcludeCurrentDirectoryW();
|
||||
|
||||
shared_object = LoadLibraryW(pluginName);
|
||||
if (!shared_object) {
|
||||
@ -43,7 +129,7 @@ public:
|
||||
#endif
|
||||
|
||||
explicit Impl(const char* pluginName) {
|
||||
ExcludeCurrentDirectory();
|
||||
ExcludeCurrentDirectoryA();
|
||||
|
||||
shared_object = LoadLibraryA(pluginName);
|
||||
if (!shared_object) {
|
||||
|
@ -174,8 +174,8 @@ target_compile_definitions(${TARGET_NAME} PUBLIC -DMKLDNN_THR=${MKLDNN_THR})
|
||||
target_link_libraries(${TARGET_NAME} PRIVATE inference_engine inference_engine_lp_transformations
|
||||
inference_engine_transformations mkldnn)
|
||||
|
||||
## Cross compiled function
|
||||
## TODO: The same for proposal, proposalONNX, topk
|
||||
# Cross compiled function
|
||||
# TODO: The same for proposal, proposalONNX, topk
|
||||
cross_compiled_file(${TARGET_NAME}
|
||||
ARCH AVX512F AVX2 SSE42 ANY
|
||||
nodes/argmax_imp.cpp
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <tuple>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
@ -732,7 +733,7 @@ bool PreprocEngine::useGAPI() {
|
||||
static const bool NO_GAPI = [](const char *str) -> bool {
|
||||
std::string var(str ? str : "");
|
||||
return var == "N" || var == "NO" || var == "OFF" || var == "0";
|
||||
} (std::getenv("USE_GAPI"));
|
||||
} (getenv("USE_GAPI"));
|
||||
|
||||
return !NO_GAPI;
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ namespace
|
||||
auto dump_info = cv::gimpl::getCompileArg<cv::graph_dump_path>(args);
|
||||
if (!dump_info.has_value())
|
||||
{
|
||||
const char* path = std::getenv("GRAPH_DUMP_PATH");
|
||||
const char* path = getenv("GRAPH_DUMP_PATH");
|
||||
return path
|
||||
? cv::util::make_optional(std::string(path))
|
||||
: cv::util::optional<std::string>();
|
||||
|
@ -187,9 +187,9 @@ void file_util::iterate_files(const string& path,
|
||||
vector<string> files;
|
||||
vector<string> dirs;
|
||||
#ifdef _WIN32
|
||||
string file_match = path_join(path, "*");
|
||||
WIN32_FIND_DATA data;
|
||||
HANDLE hFind = FindFirstFile(file_match.c_str(), &data);
|
||||
std::string file_match = path_join(path, "*");
|
||||
WIN32_FIND_DATAA data;
|
||||
HANDLE hFind = FindFirstFileA(file_match.c_str(), &data);
|
||||
if (hFind != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
do
|
||||
@ -212,7 +212,7 @@ void file_util::iterate_files(const string& path,
|
||||
string file_name = path_join(path, data.cFileName);
|
||||
func(file_name, false);
|
||||
}
|
||||
} while (FindNextFile(hFind, &data));
|
||||
} while (FindNextFileA(hFind, &data));
|
||||
FindClose(hFind);
|
||||
}
|
||||
#else
|
||||
|
@ -16,6 +16,9 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#if defined(WINAPI_FAMILY) && !WINAPI_PARTITION_DESKTOP
|
||||
#error "Only WINAPI_PARTITION_DESKTOP is supported, because of LoadLibrary[A|W]"
|
||||
#endif
|
||||
#elif defined(__linux) || defined(__APPLE__)
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
@ -52,9 +55,11 @@ static string find_my_pathname()
|
||||
Dl_info dl_info;
|
||||
dladdr(reinterpret_cast<void*>(ngraph::to_lower), &dl_info);
|
||||
return dl_info.dli_fname;
|
||||
#else
|
||||
#error "Unsupported OS"
|
||||
#endif
|
||||
#else
|
||||
return "";
|
||||
return {};
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -161,11 +161,13 @@ DL_HANDLE runtime::BackendManager::open_shared_library(string type)
|
||||
file_util::get_directory(Backend::get_backend_shared_library_search_directory());
|
||||
string library_path = file_util::path_join(my_directory, library_name);
|
||||
#ifdef _WIN32
|
||||
SetDllDirectory((LPCSTR)my_directory.c_str());
|
||||
handle = LoadLibrary(library_path.c_str());
|
||||
#else
|
||||
SetDllDirectoryA((LPCSTR)my_directory.c_str());
|
||||
handle = LoadLibraryA(library_path.c_str());
|
||||
#elif defined(__APPLE__) || defined(__linux__)
|
||||
DLERROR(); // Clear any pending errors
|
||||
handle = dlopen(library_path.c_str(), RTLD_NOW | RTLD_GLOBAL);
|
||||
#else
|
||||
#error "Unsupported OS"
|
||||
#endif
|
||||
string error = DLERROR();
|
||||
if (!handle)
|
||||
|
Loading…
Reference in New Issue
Block a user