Files
ANSCORE/tools/build_openvino_ep.bat
2026-06-18 05:55:31 +10:00

78 lines
4.4 KiB
Batchfile

@echo off
REM ============================================================================
REM build_openvino_ep.bat
REM Build the ONNX Runtime OpenVINO Execution Provider (ORT 1.24 / API 24) and
REM stage the 3 resulting DLLs into SharedCore\ep\openvino so verify_ep.ps1
REM -RequiredApi 24 goes green.
REM
REM Self-contained: sets up MSVC + an isolated Python venv + OpenVINO env, then
REM builds and stages. Run from a PLAIN cmd.exe (NOT PowerShell - OpenVINO's
REM setupvars.bat env vars only persist in cmd).
REM
REM Usage: tools\build_openvino_ep.bat
REM ============================================================================
setlocal enableextensions
REM ---- Paths (edit here if your layout differs) ------------------------------
set "ORT_SRC=C:\Projects\onnxruntime-ov"
set "PYDIR=C:\ANSLibs\Python311"
set "OV_SETUP=C:\ANSLibs\OpenVINO\setupvars.bat"
set "EP_DST=C:\Projects\SharedCore\ep\openvino"
set "OV_DEVICE=GPU"
echo === [1/6] Locate MSVC (vcvars64) ===
set "VCVARS="
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath 2^>nul`) do set "VSPATH=%%i"
if defined VSPATH if exist "%VSPATH%\VC\Auxiliary\Build\vcvars64.bat" set "VCVARS=%VSPATH%\VC\Auxiliary\Build\vcvars64.bat"
if not defined VCVARS set "VCVARS=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
if not exist "%VCVARS%" ( echo ERROR: vcvars64.bat not found. Install VS 2022 C++ workload. & exit /b 1 )
call "%VCVARS%" || ( echo ERROR: vcvars64 failed & exit /b 1 )
echo === [2/6] OpenVINO environment ===
if not exist "%OV_SETUP%" ( echo ERROR: OpenVINO setupvars not found at %OV_SETUP% & exit /b 1 )
call "%OV_SETUP%"
REM Release-only OpenVINO archives still ship a Debug cmake config whose DLLs are
REM absent, which breaks find_package(OpenVINO). Neutralize it (safe: ANSCORE links
REM OpenVINO via explicit paths, not find_package, and this build is Release-only).
set "OV_DBG=C:\ANSLibs\OpenVINO\runtime\cmake\OpenVINOTargets-debug.cmake"
if exist "%OV_DBG%" ( ren "%OV_DBG%" "OpenVINOTargets-debug.cmake.disabled" && echo neutralized OpenVINO Debug cmake config )
REM This ANSLibs OpenVINO is stripped of its runtime DLLs (deployed to SharedCore),
REM but find_package(OpenVINO) validates DLL presence. Restore Release DLLs from SharedCore.
set "OV_REL=C:\ANSLibs\OpenVINO\runtime\bin\intel64\Release"
if not exist "%OV_REL%\openvino_onnx_frontend.dll" (
echo restoring OpenVINO Release DLLs from SharedCore...
if not exist "%OV_REL%" mkdir "%OV_REL%"
copy /Y "C:\Projects\SharedCore\openvino*.dll" "%OV_REL%\" >nul
copy /Y "C:\Projects\SharedCore\tbb*.dll" "%OV_REL%\" >nul
)
echo === [3/6] Isolated Python venv (keeps build deps out of %PYDIR%) ===
if not exist "%PYDIR%\python.exe" ( echo ERROR: python not at %PYDIR% & exit /b 1 )
if not exist "%ORT_SRC%\.buildvenv\Scripts\python.exe" (
"%PYDIR%\python.exe" -m venv "%ORT_SRC%\.buildvenv" || ( echo ERROR: venv create failed & exit /b 1 )
)
call "%ORT_SRC%\.buildvenv\Scripts\activate.bat"
python --version || ( echo ERROR: venv python not usable & exit /b 1 )
python -m pip install --upgrade pip setuptools wheel packaging numpy >nul
echo === [4/6] Build (Release, shared lib, OpenVINO %OV_DEVICE%) ===
cd /d "%ORT_SRC%" || ( echo ERROR: ORT source not found at %ORT_SRC% & exit /b 1 )
REM NOTE: full path, not bare 'build.bat' - VS dev env sets
REM NoDefaultCurrentDirectoryInExePath, so cmd won't resolve build.bat from CWD.
call "%ORT_SRC%\build.bat" --config Release --use_openvino %OV_DEVICE% --build_shared_lib --parallel --skip_tests --cmake_generator "Visual Studio 17 2022"
if errorlevel 1 ( echo ERROR: build failed - see log above & exit /b 1 )
echo === [5/6] Stage DLLs into %EP_DST% (with one-time backup) ===
set "OUT=%ORT_SRC%\build\Windows\Release\Release"
if not exist "%OUT%\onnxruntime_providers_openvino.dll" ( echo ERROR: build output missing in %OUT% & exit /b 1 )
if not exist "%EP_DST%._bak_123" ( xcopy /E /I /Y "%EP_DST%" "%EP_DST%._bak_123" >nul )
copy /Y "%OUT%\onnxruntime.dll" "%EP_DST%\" >nul
copy /Y "%OUT%\onnxruntime_providers_openvino.dll" "%EP_DST%\" >nul
copy /Y "%OUT%\onnxruntime_providers_shared.dll" "%EP_DST%\" >nul
echo === [6/6] Done ===
echo Staged into %EP_DST% (1.23 backup at %EP_DST%._bak_123)
echo Validate:
echo powershell -ExecutionPolicy Bypass -File C:\Projects\CLionProjects\ANSCORE\tools\verify_ep.ps1 -RequiredApi 24
endlocal