Skip to content

Commit

Permalink
Static MSVC runtime (openvinotoolkit#8726)
Browse files Browse the repository at this point in the history
* Try to fix Windows Azure

* Try static MSVC runtime

* Fixed type

* cnpy

* Rename

* Set CMAKE_MSVC_RUNTIME_LIBRARY

* Fixed issues with oneDNN

* Removed IB

* Minimize a number of threads

* Increase image size to avoid test failures on some platforms

There is an assert 'length >= nlanes' and 'nlanes' value depends on machine architecture
Set 320x320 test image to guarantee that image size >= nlanes

Also increased image size for 'plugin shared tests' to ensure the same (even though tests do not work with legacy preprocessing)

* Descreased to 160x160

* Specify toolchain for samples

* Build samples and its tests even for static build

* Used 3.21 to enable CMAKE_TOOLCHAIN_FILE env var usage

* Fixed cmake download path

* Set CMAKE_TOOLCHAIN_FILE conditionally

* Fix

Co-authored-by: Michael Nosov <[email protected]>
  • Loading branch information
ilya-lavrenov and nosovmik authored Nov 24, 2021
1 parent 2da5631 commit 2223341
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 42 deletions.
7 changes: 1 addition & 6 deletions .ci/azure/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -312,20 +312,15 @@ jobs:
$(REPO_DIR)/tests/samples_tests
workingDirectory: $(BUILD_SAMPLES_TESTS_DIR)

- script: ninja
workingDirectory: $(BUILD_SAMPLES_TESTS_DIR)
displayName: 'Build Samples Tests'

- script: cmake -DCOMPONENT=tests -DCMAKE_INSTALL_PREFIX=$(INSTALL_DIR) -P cmake_install.cmake
workingDirectory: $(BUILD_SAMPLES_TESTS_DIR)
displayName: 'Install Samples Tests'

- script: |
python3 -m pip install -r $(INSTALL_DIR)/tests/smoke_tests/requirements.txt
workingDirectory: $(INSTALL_DIR)
displayName: 'Install dependencies for samples smoke tests'
displayName: 'Install dependencies for samples smoke tests'
continueOnError: false
condition: eq(variables['CMAKE_BUILD_SHARED_LIBS'], 'ON')
- script: |
export IE_APP_PATH=$(INSTALL_DIR)/samples_bin
Expand Down
37 changes: 18 additions & 19 deletions .ci/azure/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ jobs:
IB_DIR: C:\Program Files (x86)\IncrediBuild
IB_TESTCONSOLE: $(IB_DIR)\IBTestConsole.exe
PYTHON_DIR: C:\hostedtoolcache\windows\Python\3.7.6\x64
CMAKE_VERSION: 3.21.0
CMAKE_CMD: $(WORK_DIR)\cmake-$(CMAKE_VERSION)-windows-x86_64\cmake-$(CMAKE_VERSION)-windows-x86_64\bin\cmake.exe
OV_CMAKE_TOOLCHAIN_FILE: $(REPO_DIR)\cmake\toolchains\mt.runtime.win32.toolchain.cmake

steps:
- script: |
Expand Down Expand Up @@ -114,17 +117,22 @@ jobs:
python -m pip install -r $(REPO_DIR)\model-optimizer\requirements.txt
python -m pip install -r $(REPO_DIR)\model-optimizer\requirements_dev.txt
rem Speed up build
certutil -urlcache -split -f https://github.com/Kitware/CMake/releases/download/v3.17.0/cmake-3.17.0-win64-x64.zip cmake-3.17.0-win64-x64.zip
powershell -command "Expand-Archive -Force cmake-3.17.0-win64-x64.zip"
certutil -urlcache -split -f https://github.com/Kitware/CMake/releases/download/v$(CMAKE_VERSION)/cmake-$(CMAKE_VERSION)-windows-x86_64.zip cmake-$(CMAKE_VERSION)-windows-x86_64.zip
powershell -command "Expand-Archive -Force cmake-$(CMAKE_VERSION)-windows-x86_64.zip"
certutil -urlcache -split -f https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-win.zip ninja-win.zip
powershell -command "Expand-Archive -Force ninja-win.zip"
git clone https://github.com/google/gtest-parallel.git
workingDirectory: $(WORK_DIR)
displayName: 'Install dependencies'
- powershell: |
Write-Host "##vso[task.setvariable variable=CMAKE_TOOLCHAIN_FILE]$(OV_CMAKE_TOOLCHAIN_FILE)"
condition: eq(variables['CMAKE_BUILD_SHARED_LIBS'], 'ON')
displayName: "Set cmake toolchain"
- script: |
set PATH=$(WORK_DIR)\ninja-win;%PATH%
call "$(MSVS_VARS_PATH)" && $(WORK_DIR)\cmake-3.17.0-win64-x64\cmake-3.17.0-win64-x64\bin\cmake.exe -GNinja -DENABLE_ONEDNN_FOR_GPU=OFF -DENABLE_GNA=$(CMAKE_BUILD_SHARED_LIBS) -DENABLE_CLDNN=$(CMAKE_BUILD_SHARED_LIBS) -DENABLE_GAPI_PREPROCESSING=$(CMAKE_BUILD_SHARED_LIBS) -DBUILD_SHARED_LIBS=$(CMAKE_BUILD_SHARED_LIBS) -DENABLE_REQUIREMENTS_INSTALL=OFF -DENABLE_FASTER_BUILD=ON -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DENABLE_TESTS=ON -DENABLE_STRICT_DEPENDENCIES=OFF -DENABLE_PYTHON=ON -DPYTHON_EXECUTABLE="C:\hostedtoolcache\windows\Python\3.7.6\x64\python.exe" -DPYTHON_INCLUDE_DIR="C:\hostedtoolcache\windows\Python\3.7.6\x64\include" -DPYTHON_LIBRARY="C:\hostedtoolcache\windows\Python\3.7.6\x64\libs\python37.lib" -DIE_EXTRA_MODULES=$(OPENVINO_CONTRIB_REPO_DIR)\modules -DCMAKE_C_COMPILER:PATH="$(MSVC_COMPILER_PATH)" -DCMAKE_CXX_COMPILER:PATH="$(MSVC_COMPILER_PATH)" $(REPO_DIR)
call "$(MSVS_VARS_PATH)" && $(CMAKE_CMD) -GNinja -DENABLE_ONEDNN_FOR_GPU=OFF -DENABLE_GNA=$(CMAKE_BUILD_SHARED_LIBS) -DENABLE_CLDNN=$(CMAKE_BUILD_SHARED_LIBS) -DENABLE_GAPI_PREPROCESSING=$(CMAKE_BUILD_SHARED_LIBS) -DBUILD_SHARED_LIBS=$(CMAKE_BUILD_SHARED_LIBS) -DENABLE_REQUIREMENTS_INSTALL=OFF -DENABLE_FASTER_BUILD=ON -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DENABLE_TESTS=ON -DENABLE_STRICT_DEPENDENCIES=OFF -DENABLE_PYTHON=ON -DPYTHON_EXECUTABLE="C:\hostedtoolcache\windows\Python\3.7.6\x64\python.exe" -DPYTHON_INCLUDE_DIR="C:\hostedtoolcache\windows\Python\3.7.6\x64\include" -DPYTHON_LIBRARY="C:\hostedtoolcache\windows\Python\3.7.6\x64\libs\python37.lib" -DIE_EXTRA_MODULES=$(OPENVINO_CONTRIB_REPO_DIR)\modules -DCMAKE_C_COMPILER:PATH="$(MSVC_COMPILER_PATH)" -DCMAKE_CXX_COMPILER:PATH="$(MSVC_COMPILER_PATH)" $(REPO_DIR)
workingDirectory: $(BUILD_DIR)
displayName: 'CMake'
Expand All @@ -133,36 +141,29 @@ jobs:

- script: |
set PATH=$(WORK_DIR)\ninja-win;%PATH%
call "$(MSVS_VARS_PATH)" && "C:\Program Files (x86)\IncrediBuild\BuildConsole.exe" /COMMAND="ninja"
call "$(MSVS_VARS_PATH)" && "C:\Program Files (x86)\IncrediBuild\BuildConsole.exe" /COMMAND="$(CMAKE_CMD) --build . --config Release"
workingDirectory: $(BUILD_DIR)
displayName: 'Build Win - IB'
- script: dir $(REPO_DIR)\bin\ /s
displayName: 'List bin files'

- script: $(WORK_DIR)\cmake-3.17.0-win64-x64\cmake-3.17.0-win64-x64\bin\cmake.exe -DCMAKE_INSTALL_PREFIX=$(INSTALL_DIR) -P cmake_install.cmake
- script: $(CMAKE_CMD) -DCMAKE_INSTALL_PREFIX=$(INSTALL_DIR) -P cmake_install.cmake
workingDirectory: $(BUILD_DIR)
displayName: 'Install'

- script: dir $(INSTALL_DIR) /s
displayName: 'List install files'

- script: call "$(MSVS_VARS_PATH)" && $(WORK_DIR)\cmake-3.17.0-win64-x64\cmake-3.17.0-win64-x64\bin\cmake.exe -GNinja -DCMAKE_C_COMPILER:PATH="$(MSVC_COMPILER_PATH)" -DCMAKE_CXX_COMPILER:PATH="$(MSVC_COMPILER_PATH)" $(REPO_DIR)\tests\samples_tests
- script: call "$(MSVS_VARS_PATH)" && $(CMAKE_CMD) -DCMAKE_C_COMPILER:PATH="$(MSVC_COMPILER_PATH)" -DCMAKE_CXX_COMPILER:PATH="$(MSVC_COMPILER_PATH)" $(REPO_DIR)\tests\samples_tests
workingDirectory: $(BUILD_SAMPLES_TESTS_DIR)
displayName: 'CMake'
condition: eq(variables['CMAKE_BUILD_SHARED_LIBS'], 'ON')

- script: call "$(MSVS_VARS_PATH)" && "C:\Program Files (x86)\IncrediBuild\BuildConsole.exe" /COMMAND="ninja"
workingDirectory: $(BUILD_SAMPLES_TESTS_DIR)
displayName: 'Build Samples Tests'
condition: eq(variables['CMAKE_BUILD_SHARED_LIBS'], 'ON')

- script: $(WORK_DIR)\cmake-3.17.0-win64-x64\cmake-3.17.0-win64-x64\bin\cmake.exe -DCOMPONENT=tests -DCMAKE_INSTALL_PREFIX=$(INSTALL_DIR) -P cmake_install.cmake
- script: $(CMAKE_CMD) -DCOMPONENT=tests -DCMAKE_INSTALL_PREFIX=$(INSTALL_DIR) -P cmake_install.cmake
workingDirectory: $(BUILD_SAMPLES_TESTS_DIR)
displayName: 'Install Samples Tests'
condition: eq(variables['CMAKE_BUILD_SHARED_LIBS'], 'ON')

- script: $(WORK_DIR)\cmake-3.17.0-win64-x64\cmake-3.17.0-win64-x64\bin\cmake.exe -DCMAKE_INSTALL_PREFIX=$(INSTALL_DIR) -DCOMPONENT=tests -P cmake_install.cmake && xcopy $(BUILD_DIR)\temp\opencv_4.5.2\opencv\* $(INSTALL_DIR)\opencv\ /e /h /y
- script: $(CMAKE_CMD) -DCMAKE_INSTALL_PREFIX=$(INSTALL_DIR) -DCOMPONENT=tests -P cmake_install.cmake && xcopy $(BUILD_DIR)\temp\opencv_4.5.2\opencv\* $(INSTALL_DIR)\opencv\ /e /h /y
workingDirectory: $(BUILD_DIR)
displayName: 'Install tests'

Expand All @@ -173,20 +174,18 @@ jobs:
workingDirectory: $(BUILD_SAMPLES_DIR)
displayName: 'Build cpp samples'
continueOnError: false
condition: eq(variables['CMAKE_BUILD_SHARED_LIBS'], 'ON')

- script: $(INSTALL_DIR)\samples\c\build_samples_msvc.bat -i $(INSTALL_DIR)
workingDirectory: $(BUILD_SAMPLES_DIR)
displayName: 'Build c samples'
continueOnError: false
condition: eq(variables['CMAKE_BUILD_SHARED_LIBS'], 'ON')

- script: |
python -m pip install -r $(INSTALL_DIR)\tests\smoke_tests\requirements.txt
workingDirectory: $(INSTALL_DIR)
displayName: 'Install dependencies for samples smoke tests'
displayName: 'Install dependencies for samples smoke tests'
continueOnError: false
condition: eq(variables['CMAKE_BUILD_SHARED_LIBS'], 'ON')
- script: |
call $(SETUPVARS) && set IE_APP_PATH=$(INSTALL_DIR)\samples_bin
set IE_APP_PYTHON_PATH=$(INSTALL_DIR)\samples\python\
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ message (STATUS "OpenVINO_SOURCE_DIR ................... " ${OpenVINO_SOURCE_DIR
message (STATUS "CMAKE_GENERATOR ....................... " ${CMAKE_GENERATOR})
message (STATUS "CMAKE_C_COMPILER_ID ................... " ${CMAKE_C_COMPILER_ID})
message (STATUS "CMAKE_BUILD_TYPE ...................... " ${CMAKE_BUILD_TYPE})
message (STATUS "CMAKE_TOOLCHAIN_FILE .................. " ${CMAKE_TOOLCHAIN_FILE})

# remove file with exported developer targets to force its regeneration
file(REMOVE "${CMAKE_BINARY_DIR}/ngraph/ngraphTargets.cmake")
Expand Down
42 changes: 29 additions & 13 deletions cmake/toolchains/mt.runtime.win32.toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@

set(use_static_runtime ON)

if(use_static_runtime)
set(use_dynamic_runtime OFF)
else()
set(use_dynamic_runtime ON)
endif()

# CMAKE_MSVC_RUNTIME_LIBRARY is available since cmake 3.15
if(use_static_runtime AND CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "^MultiThreaded.*DLL$")
message(FATAL_ERROR "Misleading configuration, CMAKE_MSVC_RUNTIME_LIBRARY is ${CMAKE_MSVC_RUNTIME_LIBRARY}")
else()
set(CMAKE_MSVC_RUNTIME_LIBRARY
MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<BOOL:${use_dynamic_runtime}>:DLL>)
endif()

if(use_static_runtime)
foreach(lang C CXX)
foreach(build_type "" "_DEBUG" "_MINSIZEREL" "_RELEASE" "_RELWITHDEBINFO")
Expand All @@ -17,25 +31,27 @@ if(use_static_runtime)
endforeach()
endif()

function(onecoreuap_set_runtime var)
set(${var} ${use_static_runtime} CACHE BOOL "" FORCE)
endfunction()
macro(ov_set_msvc_runtime var value)
if(NOT DEFINED ${var})
set(${var} ${value} CACHE BOOL "" FORCE)
endif()
endmacro()

# static TBBBind_2_5 is built with dynamic CRT runtime
ov_set_msvc_runtime(ENABLE_TBBBIND_2_5 ${use_dynamic_runtime})
# ONNX
onecoreuap_set_runtime(ONNX_USE_MSVC_STATIC_RUNTIME)
ov_set_msvc_runtime(ONNX_USE_MSVC_STATIC_RUNTIME ${use_static_runtime})
ov_set_msvc_runtime(ONNX_USE_MSVC_SHARED_RUNTIME ${use_dynamic_runtime})
# pugixml
onecoreuap_set_runtime(STATIC_CRT)
ov_set_msvc_runtime(STATIC_CRT ${use_static_runtime})
# protobuf
onecoreuap_set_runtime(protobuf_MSVC_STATIC_RUNTIME)
ov_set_msvc_runtime(protobuf_MSVC_STATIC_RUNTIME ${use_static_runtime})
# clDNN
onecoreuap_set_runtime(CLDNN__COMPILE_LINK_USE_STATIC_RUNTIME)
ov_set_msvc_runtime(CLDNN__COMPILE_LINK_USE_STATIC_RUNTIME ${use_static_runtime})
# OpenCL
onecoreuap_set_runtime(USE_DYNAMIC_VCXX_RUNTIME)
ov_set_msvc_runtime(USE_DYNAMIC_VCXX_RUNTIME ${use_dynamic_runtime})
# google-test
if(use_static_runtime)
set(gtest_force_shared_crt OFF CACHE BOOL "" FORCE)
else()
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif()
ov_set_msvc_runtime(gtest_force_shared_crt ${use_dynamic_runtime})

unset(use_static_runtime)
unset(use_dynamic_runtime)
2 changes: 1 addition & 1 deletion cmake/toolchains/onecoreuap.toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if(CMAKE_GENERATOR_PLATFORM)
endif()

if(_onecoreuap_arch STREQUAL "x64")
# Forcefull make VS search for C++ libreries in these folders prior to other c++ standard libraries localizations.
# Forcefull make VS search for C++ libraries in these folders prior to other c++ standard libraries localizations.
add_link_options("/LIBPATH:\"\$\(VC_LibraryPath_VC_x64_OneCore\)\"")

set(CMAKE_C_STANDARD_LIBRARIES "\$\(UCRTContentRoot\)lib/\$\(TargetUniversalCRTVersion\)/um/\$\(Platform\)/OneCoreUap.lib" CACHE STRING "" FORCE)
Expand Down
1 change: 1 addition & 0 deletions thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ if(ENABLE_ONEDNN_FOR_GPU)
"-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}"
"-DCMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE=${ENABLE_LTO}"
"-DCMAKE_POLICY_DEFAULT_CMP0069=NEW"
"-DCMAKE_MSVC_RUNTIME_LIBRARY=${CMAKE_MSVC_RUNTIME_LIBRARY}"
"-DDNNL_CPU_RUNTIME=NONE"
"-DDNNL_GPU_RUNTIME=OCL"
"-DDNNL_LIBRARY_NAME=onednn_gpu"
Expand Down
7 changes: 4 additions & 3 deletions thirdparty/cnpy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
project(cnpy)

set(TARGET_NAME "cnpy")
add_library(cnpy STATIC cnpy.cpp)

if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_library(${TARGET_NAME} STATIC cnpy.cpp)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$")
target_compile_options(${TARGET_NAME} PUBLIC -Wno-unused-variable
PRIVATE -Wno-all)
endif()

target_link_libraries(${TARGET_NAME} PUBLIC zlib)
target_include_directories(${TARGET_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")

set_target_properties(cnpy PROPERTIES FOLDER thirdparty)
set_target_properties(${TARGET_NAME} PROPERTIES FOLDER thirdparty)

0 comments on commit 2223341

Please sign in to comment.