From 481dfeb632e5affcfa2ee44bd4ee4d58ec61be04 Mon Sep 17 00:00:00 2001 From: Dmitry Pigasin Date: Wed, 10 Nov 2021 17:31:28 +0300 Subject: [PATCH] [IE Sample Scripts] Use cmake to build samples (#8442) * Use cmake to build samples * Add the option to set custom build output folder --- scripts/demo/run_sample_benchmark_app.bat | 83 ++++------------------- scripts/demo/run_sample_benchmark_app.sh | 13 ++-- scripts/demo/run_sample_squeezenet.bat | 81 ++++------------------ scripts/demo/run_sample_squeezenet.sh | 12 +++- 4 files changed, 47 insertions(+), 142 deletions(-) diff --git a/scripts/demo/run_sample_benchmark_app.bat b/scripts/demo/run_sample_benchmark_app.bat index b9499bcca4e076..18f78faea58d70 100644 --- a/scripts/demo/run_sample_benchmark_app.bat +++ b/scripts/demo/run_sample_benchmark_app.bat @@ -4,12 +4,18 @@ @echo off setlocal enabledelayedexpansion +set ROOT_DIR=%~dp0 + set TARGET=CPU set BUILD_FOLDER=%USERPROFILE%\Documents\Intel\OpenVINO :: command line arguments parsing :input_arguments_loop if not "%1"=="" ( + if "%1"=="-b" ( + set BUILD_FOLDER=%2 + shift + ) if "%1"=="-d" ( set TARGET=%2 echo target = !TARGET! @@ -25,6 +31,7 @@ if not "%1"=="" ( echo. echo Options: echo -help Print help message + echo -b BUILD_FOLDER Specify the sample build directory echo -d DEVICE Specify the target device to infer on; CPU, GPU, HDDL or MYRIAD are acceptable. Sample will look for a suitable plugin for device specified echo -sample-options OPTIONS Specify command line arguments for the sample exit /b @@ -33,12 +40,12 @@ if not "%1"=="" ( goto :input_arguments_loop ) +set "SOLUTION_DIR64=%BUILD_FOLDER%\inference_engine_cpp_samples_build" + IF "%SAMPLE_OPTIONS%"=="" ( set SAMPLE_OPTIONS=-niter 1000 ) -set ROOT_DIR=%~dp0 - set TARGET_PRECISION=FP16 echo target_precision = !TARGET_PRECISION! @@ -158,81 +165,21 @@ if "%PROCESSOR_ARCHITECTURE%" == "AMD64" ( set "PLATFORM=Win32" ) -set VSWHERE="false" -if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" ( - set VSWHERE="true" - cd /d "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer" -) else if exist "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" ( - set VSWHERE="true" - cd /d "%ProgramFiles%\Microsoft Visual Studio\Installer" -) else ( - echo "vswhere tool is not found" -) - -if !VSWHERE! == "true" ( - for /f "usebackq tokens=*" %%i in (`vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do ( - set VS_PATH=%%i - ) - if exist "!VS_PATH!\MSBuild\14.0\Bin\MSBuild.exe" ( - set "MSBUILD_BIN=!VS_PATH!\MSBuild\14.0\Bin\MSBuild.exe" - ) - if exist "!VS_PATH!\MSBuild\15.0\Bin\MSBuild.exe" ( - set "MSBUILD_BIN=!VS_PATH!\MSBuild\15.0\Bin\MSBuild.exe" - ) - if exist "!VS_PATH!\MSBuild\Current\Bin\MSBuild.exe" ( - set "MSBUILD_BIN=!VS_PATH!\MSBuild\Current\Bin\MSBuild.exe" - ) - for /f "usebackq tokens=1 delims=." %%i in (`vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationVersion`) do ( - set VS_MAJOR_VER=%%i - ) - if "!VS_MAJOR_VER!"=="16" set "MSBUILD_VERSION=16 2019" - if "!VS_MAJOR_VER!"=="15" set "MSBUILD_VERSION=15 2017" -) - -if "!MSBUILD_BIN!" == "" ( - if exist "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" ( - set "MSBUILD_BIN=C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" - set "MSBUILD_VERSION=14 2015" - ) - if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe" ( - set "MSBUILD_BIN=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe" - set "MSBUILD_VERSION=15 2017" - ) - if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe" ( - set "MSBUILD_BIN=C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe" - set "MSBUILD_VERSION=15 2017" - ) - if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe" ( - set "MSBUILD_BIN=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe" - set "MSBUILD_VERSION=15 2017" - ) -) else ( - if not "!MSBUILD_BIN:2019=!"=="!MSBUILD_BIN!" set "MSBUILD_VERSION=16 2019" - if not "!MSBUILD_BIN:2017=!"=="!MSBUILD_BIN!" set "MSBUILD_VERSION=15 2017" - if not "!MSBUILD_BIN:2015=!"=="!MSBUILD_BIN!" set "MSBUILD_VERSION=14 2015" -) - -if "!MSBUILD_BIN!" == "" ( - echo Build tools for Visual Studio 2015 / 2017 / 2019 cannot be found. If you use Visual Studio 2017, please download and install build tools from https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017 - GOTO errorHandling -) - -set "SOLUTION_DIR64=%BUILD_FOLDER%\inference_engine_cpp_samples_build" - -echo Creating Visual Studio !MSBUILD_VERSION! %PLATFORM% files in %SOLUTION_DIR64%... && ^ if exist "%SOLUTION_DIR64%\CMakeCache.txt" del "%SOLUTION_DIR64%\CMakeCache.txt" -cd /d "%INTEL_OPENVINO_DIR%\samples\cpp" && cmake -E make_directory "%SOLUTION_DIR64%" && cd /d "%SOLUTION_DIR64%" && cmake -G "Visual Studio !MSBUILD_VERSION!" -A %PLATFORM% "%INTEL_OPENVINO_DIR%\samples\cpp" + +cd /d "%INTEL_OPENVINO_DIR%\samples\cpp" && cmake -E make_directory "%SOLUTION_DIR64%" && cd /d "%SOLUTION_DIR64%" && cmake -G "Visual Studio 16 2019" -A %PLATFORM% "%INTEL_OPENVINO_DIR%\samples\cpp" if ERRORLEVEL 1 GOTO errorHandling CALL :delay 7 echo. -echo ###############^|^| Build Inference Engine samples using MS Visual Studio (MSBuild.exe) ^|^|############### +echo ###############^|^| Build Inference Engine samples using cmake ^|^|############### echo. + CALL :delay 3 -echo "!MSBUILD_BIN!" Samples.sln /p:Configuration=Release /t:cpp_samples\benchmark_app /clp:ErrorsOnly /m -"!MSBUILD_BIN!" Samples.sln /p:Configuration=Release /t:cpp_samples\benchmark_app /clp:ErrorsOnly /m +echo cmake --build . --config Release --target benchmark_app +cmake --build . --config Release --target benchmark_app if ERRORLEVEL 1 GOTO errorHandling CALL :delay 7 diff --git a/scripts/demo/run_sample_benchmark_app.sh b/scripts/demo/run_sample_benchmark_app.sh index 9e273d6c2a515e..d7b1077afcca76 100755 --- a/scripts/demo/run_sample_benchmark_app.sh +++ b/scripts/demo/run_sample_benchmark_app.sh @@ -6,6 +6,7 @@ echo -ne "\e[0;33mWARNING: If you get an error when running the sample in the Docker container, you may need to install additional packages. To do this, run the container as root (-u 0) and run install_openvino_dependencies.sh script. If you get a package-independent error, try setting additional parameters using -sample-options.\e[0m\n" ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]-$0}" )" && pwd )" +build_dir="$HOME/inference_engine_cpp_samples_build" . "$ROOT_DIR/utils.sh" @@ -14,6 +15,7 @@ usage() { echo echo "Options:" echo " -help Print help message" + echo " -b BUILD_DIR Specify the sample build directory" echo " -d DEVICE Specify the target device to infer on; CPU, GPU, HDDL or MYRIAD are acceptable. Sample will look for a suitable plugin for device specified" echo " -sample-options OPTIONS Specify command line arguments for the sample" echo @@ -30,6 +32,10 @@ do key="$1" case $key in + -b | --build_dir) + build_dir="$2/inference_engine_cpp_samples_build" + shift + ;; -h | -help | --help) usage ;; @@ -58,9 +64,9 @@ target_precision="FP16" echo -ne "target_precision = ${target_precision}\n" -models_path="$HOME/openvino_models/models" -models_cache="$HOME/openvino_models/cache" -irs_path="$HOME/openvino_models/ir" +models_path="$build_dir/../openvino_models/models" +models_cache="$build_dir/../openvino_models/cache" +irs_path="$build_dir/../openvino_models/ir" model_name="squeezenet1.1" @@ -163,7 +169,6 @@ if [ "$OS_PATH" == "x86_64" ]; then fi samples_path="${INTEL_OPENVINO_DIR}/samples/cpp" -build_dir="$HOME/inference_engine_cpp_samples_build" binaries_dir="${build_dir}/${OS_PATH}/Release" if [ -e "$build_dir/CMakeCache.txt" ]; then diff --git a/scripts/demo/run_sample_squeezenet.bat b/scripts/demo/run_sample_squeezenet.bat index 293168cb9e710d..2ccb9e7c18b022 100644 --- a/scripts/demo/run_sample_squeezenet.bat +++ b/scripts/demo/run_sample_squeezenet.bat @@ -4,12 +4,18 @@ @echo off setlocal enabledelayedexpansion +set ROOT_DIR=%~dp0 + set TARGET=CPU set BUILD_FOLDER=%USERPROFILE%\Documents\Intel\OpenVINO :: command line arguments parsing :input_arguments_loop if not "%1"=="" ( + if "%1"=="-b" ( + set BUILD_FOLDER=%2 + shift + ) if "%1"=="-d" ( set TARGET=%2 echo target = !TARGET! @@ -25,6 +31,7 @@ if not "%1"=="" ( echo. echo Options: echo -help Print help message + echo -b BUILD_FOLDER Specify the sample build directory echo -d DEVICE Specify the target device to infer on; CPU, GPU, HDDL or MYRIAD are acceptable. Sample will look for a suitable plugin for device specified echo -sample-options OPTIONS Specify command line arguments for the sample exit /b @@ -33,7 +40,7 @@ if not "%1"=="" ( goto :input_arguments_loop ) -set ROOT_DIR=%~dp0 +set "SOLUTION_DIR64=%BUILD_FOLDER%\inference_engine_cpp_samples_build" set TARGET_PRECISION=FP16 @@ -154,81 +161,21 @@ if "%PROCESSOR_ARCHITECTURE%" == "AMD64" ( set "PLATFORM=Win32" ) -set VSWHERE="false" -if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" ( - set VSWHERE="true" - cd /d "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer" -) else if exist "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" ( - set VSWHERE="true" - cd /d "%ProgramFiles%\Microsoft Visual Studio\Installer" -) else ( - echo "vswhere tool is not found" -) - -if !VSWHERE! == "true" ( - for /f "usebackq tokens=*" %%i in (`vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do ( - set VS_PATH=%%i - ) - if exist "!VS_PATH!\MSBuild\14.0\Bin\MSBuild.exe" ( - set "MSBUILD_BIN=!VS_PATH!\MSBuild\14.0\Bin\MSBuild.exe" - ) - if exist "!VS_PATH!\MSBuild\15.0\Bin\MSBuild.exe" ( - set "MSBUILD_BIN=!VS_PATH!\MSBuild\15.0\Bin\MSBuild.exe" - ) - if exist "!VS_PATH!\MSBuild\Current\Bin\MSBuild.exe" ( - set "MSBUILD_BIN=!VS_PATH!\MSBuild\Current\Bin\MSBuild.exe" - ) - for /f "usebackq tokens=1 delims=." %%i in (`vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationVersion`) do ( - set VS_MAJOR_VER=%%i - ) - if "!VS_MAJOR_VER!"=="16" set "MSBUILD_VERSION=16 2019" - if "!VS_MAJOR_VER!"=="15" set "MSBUILD_VERSION=15 2017" -) - -if "!MSBUILD_BIN!" == "" ( - if exist "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" ( - set "MSBUILD_BIN=C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" - set "MSBUILD_VERSION=14 2015" - ) - if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe" ( - set "MSBUILD_BIN=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe" - set "MSBUILD_VERSION=15 2017" - ) - if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe" ( - set "MSBUILD_BIN=C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe" - set "MSBUILD_VERSION=15 2017" - ) - if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe" ( - set "MSBUILD_BIN=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe" - set "MSBUILD_VERSION=15 2017" - ) -) else ( - if not "!MSBUILD_BIN:2019=!"=="!MSBUILD_BIN!" set "MSBUILD_VERSION=16 2019" - if not "!MSBUILD_BIN:2017=!"=="!MSBUILD_BIN!" set "MSBUILD_VERSION=15 2017" - if not "!MSBUILD_BIN:2015=!"=="!MSBUILD_BIN!" set "MSBUILD_VERSION=14 2015" -) - -if "!MSBUILD_BIN!" == "" ( - echo Build tools for Visual Studio 2015 / 2017 / 2019 cannot be found. If you use Visual Studio 2017, please download and install build tools from https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017 - GOTO errorHandling -) - -set "SOLUTION_DIR64=%BUILD_FOLDER%\inference_engine_cpp_samples_build" - -echo Creating Visual Studio !MSBUILD_VERSION! %PLATFORM% files in %SOLUTION_DIR64%... && ^ if exist "%SOLUTION_DIR64%\CMakeCache.txt" del "%SOLUTION_DIR64%\CMakeCache.txt" -cd /d "%INTEL_OPENVINO_DIR%\samples\cpp" && cmake -E make_directory "%SOLUTION_DIR64%" && cd /d "%SOLUTION_DIR64%" && cmake -G "Visual Studio !MSBUILD_VERSION!" -A %PLATFORM% "%INTEL_OPENVINO_DIR%\samples\cpp" + +cd /d "%INTEL_OPENVINO_DIR%\samples\cpp" && cmake -E make_directory "%SOLUTION_DIR64%" && cd /d "%SOLUTION_DIR64%" && cmake -G "Visual Studio 16 2019" -A %PLATFORM% "%INTEL_OPENVINO_DIR%\samples\cpp" if ERRORLEVEL 1 GOTO errorHandling CALL :delay 7 echo. -echo ###############^|^| Build Inference Engine samples using MS Visual Studio (MSBuild.exe) ^|^|############### +echo ###############^|^| Build Inference Engine samples using cmake ^|^|############### echo. + CALL :delay 3 -echo "!MSBUILD_BIN!" Samples.sln /p:Configuration=Release /t:cpp_samples\classification_sample_async /clp:ErrorsOnly /m -"!MSBUILD_BIN!" Samples.sln /p:Configuration=Release /t:cpp_samples\classification_sample_async /clp:ErrorsOnly /m +echo cmake --build . --config Release --target classification_sample_async +cmake --build . --config Release --target classification_sample_async if ERRORLEVEL 1 GOTO errorHandling CALL :delay 7 diff --git a/scripts/demo/run_sample_squeezenet.sh b/scripts/demo/run_sample_squeezenet.sh index 3d1b12a1fec6fc..1ce3a61cb9d5c7 100755 --- a/scripts/demo/run_sample_squeezenet.sh +++ b/scripts/demo/run_sample_squeezenet.sh @@ -6,6 +6,7 @@ echo -ne "\e[0;33mWARNING: If you get an error when running the sample in the Docker container, you may need to install additional packages. To do this, run the container as root (-u 0) and run install_openvino_dependencies.sh script. If you get a package-independent error, try setting additional parameters using -sample-options.\e[0m\n" ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]-$0}" )" && pwd )" +build_dir="$HOME/inference_engine_cpp_samples_build" . "$ROOT_DIR/utils.sh" @@ -14,6 +15,7 @@ usage() { echo echo "Options:" echo " -help Print help message" + echo " -b BUILD_DIR Specify the sample build directory" echo " -d DEVICE Specify the target device to infer on; CPU, GPU, HDDL or MYRIAD are acceptable. Sample will look for a suitable plugin for device specified" echo " -sample-options OPTIONS Specify command line arguments for the sample" echo @@ -30,6 +32,10 @@ do key="$1" case $key in + -b | --build_dir) + build_dir="$2/inference_engine_cpp_samples_build" + shift + ;; -h | -help | --help) usage ;; @@ -54,9 +60,9 @@ target_precision="FP16" echo -ne "target_precision = ${target_precision}\n" -models_path="$HOME/openvino_models/models" -models_cache="$HOME/openvino_models/cache" -irs_path="$HOME/openvino_models/ir" +models_path="$build_dir/../openvino_models/models" +models_cache="$build_dir/../openvino_models/cache" +irs_path="$build_dir/../openvino_models/ir" model_name="squeezenet1.1"