Skip to content

Commit

Permalink
[IE Sample Scripts] Use cmake to build samples (#8442)
Browse files Browse the repository at this point in the history
* Use cmake to build samples

* Add the option to set custom build output folder
  • Loading branch information
dpigasin committed Nov 10, 2021
1 parent 852dd93 commit 331372e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 142 deletions.
83 changes: 15 additions & 68 deletions scripts/demo/run_sample_benchmark_app.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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
Expand All @@ -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!
Expand Down Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions scripts/demo/run_sample_benchmark_app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand All @@ -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
;;
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
81 changes: 14 additions & 67 deletions scripts/demo/run_sample_squeezenet.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions scripts/demo/run_sample_squeezenet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand All @@ -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
;;
Expand All @@ -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"

Expand Down

0 comments on commit 331372e

Please sign in to comment.