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

fixes for UWP #2255

Merged
merged 20 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function(build_ngraph)
ngraph_set(NGRAPH_UNIT_TEST_ENABLE FALSE)
endif()

if(NOT ANDROID)
if(NOT (ANDROID OR WINDOWS_STORE))
ilya-lavrenov marked this conversation as resolved.
Show resolved Hide resolved
ngraph_set(NGRAPH_ONNX_IMPORT_ENABLE TRUE)
else()
ngraph_set(NGRAPH_ONNX_IMPORT_ENABLE FALSE)
Expand Down
26 changes: 13 additions & 13 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion cmake/features.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions cmake/uwp.toolchain.cmake
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 1 addition & 1 deletion inference-engine/cmake/features_ie.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions inference-engine/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()
Expand Down
39 changes: 23 additions & 16 deletions inference-engine/src/inference_engine/file_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}

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

Expand All @@ -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) {
Expand All @@ -43,7 +129,7 @@ class SharedObjectLoader::Impl {
#endif

explicit Impl(const char* pluginName) {
ExcludeCurrentDirectory();
ExcludeCurrentDirectoryA();

shared_object = LoadLibraryA(pluginName);
if (!shared_object) {
Expand Down
4 changes: 2 additions & 2 deletions inference-engine/src/mkldnn_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion inference-engine/src/preprocessing/ie_preprocess_gapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <utility>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <tuple>
#include <string>
#include <unordered_map>
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down
8 changes: 4 additions & 4 deletions ngraph/core/src/file_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion ngraph/test/runtime/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
Loading