From 5f16494446cc262be31fee746e82c6fe2b22adca Mon Sep 17 00:00:00 2001 From: peter Date: Sat, 3 Nov 2018 15:03:16 +0800 Subject: [PATCH] Add auto resolve mechanism --- auto.bat | 23 ++++++ cuda100.bat | 31 +++++--- cuda80.bat | 33 ++++++++ cuda90.bat | 31 +++++--- cuda91.bat | 31 +++++--- cuda92.bat | 31 +++++--- internal/auto_resolve.bat | 161 ++++++++++++++++++++++++++++++++++++++ internal/check_deps.bat | 135 +++++++++++++++++++++++++------- internal/check_opts.bat | 23 +++++- internal/setup.bat | 11 ++- 10 files changed, 436 insertions(+), 74 deletions(-) create mode 100644 internal/auto_resolve.bat diff --git a/auto.bat b/auto.bat index 99f4476..1425aea 100644 --- a/auto.bat +++ b/auto.bat @@ -40,6 +40,29 @@ IF NOT "%CUDA_PATH_V8_0%"=="" IF "%CUDA_PATH_V8_0%"=="%CUDA_PATH%" ( ) ) + +IF "%CUDA_PATH_V8_0%"=="%CUDA_PATH%" ( + set CUDA_VERSION=80 + set CUDA_VERSION_STR=8.0 +) +IF "%CUDA_PATH_V9_0%"=="%CUDA_PATH%" ( + set CUDA_VERSION=90 + set CUDA_VERSION_STR=9.0 +) +IF "%CUDA_PATH_V9_1%"=="%CUDA_PATH%" ( + set CUDA_VERSION=91 + set CUDA_VERSION_STR=9.1 +) +IF "%CUDA_PATH_V9_2%"=="%CUDA_PATH%" ( + set CUDA_VERSION=92 + set CUDA_VERSION_STR=9.2 +) +IF "%CUDA_PATH_V10_0%"=="%CUDA_PATH%" ( + set CUDA_VERSION=100 + set CUDA_VERSION_STR=10.0 +) + + :optcheck call internal\check_opts.bat diff --git a/cuda100.bat b/cuda100.bat index 1d9d4be..e7e1215 100644 --- a/cuda100.bat +++ b/cuda100.bat @@ -17,19 +17,30 @@ REM Check for optional components set NO_CUDA= set CMAKE_GENERATOR=Visual Studio 15 2017 Win64 +set CUDA_VERSION=100 +set CUDA_VERSION_STR=10.0 -IF "%NVTOOLSEXT_PATH%"=="" ( - echo NVTX ^(Visual Studio Extension ^for CUDA^) ^not installed, disabling CUDA - set NO_CUDA=1 - goto optcheck +IF "%CUDA_PATH_V10_0%"=="" ( + IF %AUTO_RESOLVE_VALUE% GEQ 1 ( + call internal\auto_resolve.bat cuda100 + IF ERRORLEVEL 1 goto eof + ) ELSE ( + echo CUDA 10.0 not found + goto eof + ) ) -IF "%CUDA_PATH_V10_0%"=="" ( - echo CUDA 9.2 not found, disabling it - set NO_CUDA=1 -) ELSE ( - set "CUDA_PATH=%CUDA_PATH_V10_0%" - set "PATH=%CUDA_PATH_V10_0%\bin;%PATH%" +set "CUDA_PATH=%CUDA_PATH_V10_0%" +set "PATH=%CUDA_PATH_V10_0%\bin;%PATH%" + +IF "%NVTOOLSEXT_PATH%"=="" ( + IF %AUTO_RESOLVE_VALUE% GEQ 1 ( + call internal\auto_resolve.bat nvtx + IF ERRORLEVEL 1 goto eof + ) ELSE ( + echo NVTX ^(Visual Studio Extension ^for CUDA^) ^not installed + goto eof + ) ) :optcheck diff --git a/cuda80.bat b/cuda80.bat index 387c894..56fb597 100644 --- a/cuda80.bat +++ b/cuda80.bat @@ -17,6 +17,8 @@ REM Check for optional components set NO_CUDA= set CMAKE_GENERATOR=Visual Studio 15 2017 Win64 +set CUDA_VERSION=80 +set CUDA_VERSION_STR=8.0 IF "%NVTOOLSEXT_PATH%"=="" ( echo NVTX ^(Visual Studio Extension ^for CUDA^) ^not installed, disabling CUDA @@ -39,6 +41,37 @@ IF "%CUDA_PATH_V8_0%"=="" ( ) ) +IF "%CUDA_PATH_V8_0%"=="" ( + IF %AUTO_RESOLVE_VALUE% GEQ 1 ( + call internal\auto_resolve.bat cuda80 + IF ERRORLEVEL 1 goto eof + ) ELSE ( + echo CUDA 8.0 not found + goto eof + ) +) + +set "CUDA_PATH=%CUDA_PATH_V8_0%" +set "PATH=%CUDA_PATH_V8_0%\bin;%PATH%" + +IF "%VS140COMNTOOLS%"=="" ( + echo CUDA 8 found, but VS2015 not found + goto eof +) ELSE ( + set CMAKE_GENERATOR=Visual Studio 14 2015 Win64 + set "CUDAHOSTCXX=%VS140COMNTOOLS%\..\..\VC\bin\amd64\cl.exe" +) + +IF "%NVTOOLSEXT_PATH%"=="" ( + IF %AUTO_RESOLVE_VALUE% GEQ 1 ( + call internal\auto_resolve.bat nvtx + IF ERRORLEVEL 1 goto eof + ) ELSE ( + echo NVTX ^(Visual Studio Extension ^for CUDA^) ^not installed + goto eof + ) +) + :optcheck call internal\check_opts.bat diff --git a/cuda90.bat b/cuda90.bat index 3504e09..7ca4b01 100644 --- a/cuda90.bat +++ b/cuda90.bat @@ -17,19 +17,30 @@ REM Check for optional components set NO_CUDA= set CMAKE_GENERATOR=Visual Studio 15 2017 Win64 +set CUDA_VERSION=90 +set CUDA_VERSION_STR=9.0 -IF "%NVTOOLSEXT_PATH%"=="" ( - echo NVTX ^(Visual Studio Extension ^for CUDA^) ^not installed, disabling CUDA - set NO_CUDA=1 - goto optcheck +IF "%CUDA_PATH_V9_0%"=="" ( + IF %AUTO_RESOLVE_VALUE% GEQ 1 ( + call internal\auto_resolve.bat cuda90 + IF ERRORLEVEL 1 goto eof + ) ELSE ( + echo CUDA 9.0 not found + goto eof + ) ) -IF "%CUDA_PATH_V9_0%"=="" ( - echo CUDA 9 not found, disabling it - set NO_CUDA=1 -) ELSE ( - set "CUDA_PATH=%CUDA_PATH_V9_0%" - set "PATH=%CUDA_PATH_V9_0%\bin;%PATH%" +set "CUDA_PATH=%CUDA_PATH_V9_0%" +set "PATH=%CUDA_PATH_V9_0%\bin;%PATH%" + +IF "%NVTOOLSEXT_PATH%"=="" ( + IF %AUTO_RESOLVE_VALUE% GEQ 1 ( + call internal\auto_resolve.bat nvtx + IF ERRORLEVEL 1 goto eof + ) ELSE ( + echo NVTX ^(Visual Studio Extension ^for CUDA^) ^not installed + goto eof + ) ) :optcheck diff --git a/cuda91.bat b/cuda91.bat index d960511..28a1d35 100644 --- a/cuda91.bat +++ b/cuda91.bat @@ -17,19 +17,30 @@ REM Check for optional components set NO_CUDA= set CMAKE_GENERATOR=Visual Studio 15 2017 Win64 +set CUDA_VERSION=91 +set CUDA_VERSION_STR=9.1 -IF "%NVTOOLSEXT_PATH%"=="" ( - echo NVTX ^(Visual Studio Extension ^for CUDA^) ^not installed, disabling CUDA - set NO_CUDA=1 - goto optcheck +IF "%CUDA_PATH_V9_1%"=="" ( + IF %AUTO_RESOLVE_VALUE% GEQ 1 ( + call internal\auto_resolve.bat cuda91 + IF ERRORLEVEL 1 goto eof + ) ELSE ( + echo CUDA 9.1 not found + goto eof + ) ) -IF "%CUDA_PATH_V9_1%"=="" ( - echo CUDA 9.1 not found, disabling it - set NO_CUDA=1 -) ELSE ( - set "CUDA_PATH=%CUDA_PATH_V9_1%" - set "PATH=%CUDA_PATH_V9_1%\bin;%PATH%" +set "CUDA_PATH=%CUDA_PATH_V9_1%" +set "PATH=%CUDA_PATH_V9_1%\bin;%PATH%" + +IF "%NVTOOLSEXT_PATH%"=="" ( + IF %AUTO_RESOLVE_VALUE% GEQ 1 ( + call internal\auto_resolve.bat nvtx + IF ERRORLEVEL 1 goto eof + ) ELSE ( + echo NVTX ^(Visual Studio Extension ^for CUDA^) ^not installed + goto eof + ) ) :optcheck diff --git a/cuda92.bat b/cuda92.bat index 559fc8e..94fb5ef 100644 --- a/cuda92.bat +++ b/cuda92.bat @@ -17,19 +17,30 @@ REM Check for optional components set NO_CUDA= set CMAKE_GENERATOR=Visual Studio 15 2017 Win64 +set CUDA_VERSION=92 +set CUDA_VERSION_STR=9.2 -IF "%NVTOOLSEXT_PATH%"=="" ( - echo NVTX ^(Visual Studio Extension ^for CUDA^) ^not installed, disabling CUDA - set NO_CUDA=1 - goto optcheck +IF "%CUDA_PATH_V9_2%"=="" ( + IF %AUTO_RESOLVE_VALUE% GEQ 1 ( + call internal\auto_resolve.bat cuda92 + IF ERRORLEVEL 1 goto eof + ) ELSE ( + echo CUDA 9.2 not found + goto eof + ) ) -IF "%CUDA_PATH_V9_2%"=="" ( - echo CUDA 9.2 not found, disabling it - set NO_CUDA=1 -) ELSE ( - set "CUDA_PATH=%CUDA_PATH_V9_2%" - set "PATH=%CUDA_PATH_V9_2%\bin;%PATH%" +set "CUDA_PATH=%CUDA_PATH_V9_2%" +set "PATH=%CUDA_PATH_V9_2%\bin;%PATH%" + +IF "%NVTOOLSEXT_PATH%"=="" ( + IF %AUTO_RESOLVE_VALUE% GEQ 1 ( + call internal\auto_resolve.bat nvtx + IF ERRORLEVEL 1 goto eof + ) ELSE ( + echo NVTX ^(Visual Studio Extension ^for CUDA^) ^not installed + goto eof + ) ) :optcheck diff --git a/internal/auto_resolve.bat b/internal/auto_resolve.bat new file mode 100644 index 0000000..beb71ff --- /dev/null +++ b/internal/auto_resolve.bat @@ -0,0 +1,161 @@ +@echo off + +IF "%~1" == "vs" goto vs +IF "%~1" == "vs1411" goto vs1411 +IF "%~1" == "cuda" goto cuda +IF "%~1" == "cuda90" goto cuda90 +IF "%~1" == "cuda91" goto cuda91 +IF "%~1" == "nvtx" goto nvtx +IF "%~1" == "magma" goto magma +IF "%~1" == "mkl" goto mkl +IF "%~1" == "ninja" goto ninja + +echo "The dependency you specified is not yet avaiable: %~1" +exit /b 1 + +:vs + +curl -k https://www.dropbox.com/s/spq7vtfb6uxgo0m/vs_BuildTools.exe?dl=1 --output "%SRC_DIR%\temp_build\vs_BuildTools.exe" +IF EXIST "vs_BuildTools.exe" ( + start /wait "%SRC_DIR%\temp_build\vs_buildtools.exe" --quiet --wait --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.VC.Tools.14.11 +) ELSE ( + echo Download failed + exit /b 1 +) + +goto end_check + +:vs1411 + +IF EXIST "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vs_installer.exe" ( + start /wait "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vs_installer.exe" --quiet --wait --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.VC.Tools.14.11 +) ELSE ( + echo VS Installer does not exist + exit /b 1 +) + +goto end_check + +:cuda80 + +:cuda +:cuda90 + +IF NOT EXIST "%SRC_DIR%\temp_build\cuda_9.0.176_windows.7z" ( + curl -k https://www.dropbox.com/s/z5b7ryz0zrimntl/cuda_9.0.176_windows.7z?dl=1 --output "%SRC_DIR%\temp_build\cuda_9.0.176_windows.7z" + set "CUDA_SETUP_FILE=%SRC_DIR%\temp_build\cuda_9.0.176_windows.7z" + set "NVCC_PACKAGE=compiler_%CUDA_VERSION_STR%" +) + +IF NOT EXIST "%SRC_DIR%\temp_build\cudnn-9.0-windows7-x64-v7.zip" ( + curl -k https://www.dropbox.com/s/6p0xyqh472nu8m1/cudnn-9.0-windows7-x64-v7.zip?dl=1 --output "%SRC_DIR%\temp_build\cudnn-9.0-windows7-x64-v7.zip" + set "CUDNN_SETUP_FILE=%SRC_DIR%\temp_build\cudnn-9.0-windows7-x64-v7.zip" +) + +goto cuda_common + +:cuda91 + +IF NOT EXIST "%SRC_DIR%\temp_build\cuda_9.1.85_windows.7z" ( + curl -k https://www.dropbox.com/s/7a4sbq0dln6v7t2/cuda_9.1.85_windows.7z?dl=1 --output "%SRC_DIR%\temp_build\cuda_9.1.85_windows.7z" + set "CUDA_SETUP_FILE=%SRC_DIR%\temp_build\cuda_9.1.85_windows.7z" + set "NVCC_PACKAGE=nvcc_%CUDA_VERSION_STR%" +) + +IF NOT EXIST "%SRC_DIR%\temp_build\cudnn-9.1-windows7-x64-v7.zip" ( + curl -k https://www.dropbox.com/s/e0prhgsrbyfi4ov/cudnn-9.1-windows7-x64-v7.zip?dl=1 --output "%SRC_DIR%\temp_build\cudnn-9.1-windows7-x64-v7.zip" + set "CUDNN_SETUP_FILE=%SRC_DIR%\temp_build\cudnn-9.1-windows7-x64-v7.zip" +) + +goto cuda_common + +:cuda_common + +set "CUDA_PREFIX=cuda%CUDA_VERSION%" + +IF NOT EXIST "%SRC_DIR%\temp_build\NvToolsExt.7z" ( + curl -k https://drive.google.com/uc?export=download&id=0B-X0-FlSGfCYclUyTWROZVlLT2s --output "%SRC_DIR%\temp_build\NvToolsExt.7z" +) + +echo Installing CUDA toolkit... + +7z x %CUDA_SETUP_FILE% -o"%SRC_DIR%\temp_build\cuda" +start /wait "%SRC_DIR%\temp_build\cuda\setup.exe" -s %NVCC_PACKAGE% cublas_%CUDA_VERSION_STR% cublas_dev_%CUDA_VERSION_STR% cudart_%CUDA_VERSION_STR% curand_%CUDA_VERSION_STR% curand_dev_%CUDA_VERSION_STR% cusparse_%CUDA_VERSION_STR% cusparse_dev_%CUDA_VERSION_STR% nvrtc_%CUDA_VERSION_STR% nvrtc_dev_%CUDA_VERSION_STR% cufft_%CUDA_VERSION_STR% cufft_dev_%CUDA_VERSION_STR% +echo Installing VS integration... +xcopy /Y "%SRC_DIR%\temp_build\cuda\_vs\*.*" "c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\BuildCustomizations" + +echo Installing NvToolsExt... +7z x %SRC_DIR%\temp_build\NvToolsExt.7z -o"%SRC_DIR%\temp_build\NvToolsExt" +mkdir "%ProgramFiles%\NVIDIA Corporation\NvToolsExt\bin\x64" +mkdir "%ProgramFiles%\NVIDIA Corporation\NvToolsExt\include" +mkdir "%ProgramFiles%\NVIDIA Corporation\NvToolsExt\lib\x64" +xcopy /Y "%SRC_DIR%\temp_build\NvToolsExt\bin\x64\*.*" "%ProgramFiles%\NVIDIA Corporation\NvToolsExt\bin\x64" +xcopy /Y "%SRC_DIR%\temp_build\NvToolsExt\include\*.*" "%ProgramFiles%\NVIDIA Corporation\NvToolsExt\include" +xcopy /Y "%SRC_DIR%\temp_build\NvToolsExt\lib\x64\*.*" "%ProgramFiles%\NVIDIA Corporation\NvToolsExt\lib\x64" + +echo Installing cuDNN... +7z x %CUDNN_SETUP_FILE% -o"%SRC_DIR%\temp_build\cudnn" +xcopy /Y "%SRC_DIR%\temp_build\cudnn\cuda\bin\*.*" "%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%\bin" +xcopy /Y "%SRC_DIR%\temp_build\cudnn\cuda\lib\x64\*.*" "%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%\lib\x64" +xcopy /Y "%SRC_DIR%\temp_build\cudnn\cuda\include\*.*" "%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%\include" + +echo Setting up environment... +set "PATH=%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%\bin;%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%\libnvvp;%PATH%" +set "CUDA_PATH=%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%" +set "CUDA_PATH_V8_0=%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%" +set "NVTOOLSEXT_PATH=%ProgramFiles%\NVIDIA Corporation\NvToolsExt\" + +goto end_check + +:nvtx + +IF NOT EXIST "%SRC_DIR%\temp_build\NvToolsExt.7z" ( + curl -k https://drive.google.com/uc?export=download&id=0B-X0-FlSGfCYclUyTWROZVlLT2s --output "%SRC_DIR%\temp_build\NvToolsExt.7z" +) + +7z x %SRC_DIR%\temp_build\NvToolsExt.7z -o"%SRC_DIR%\temp_build\NvToolsExt" +mkdir "%ProgramFiles%\NVIDIA Corporation\NvToolsExt\bin\x64" +mkdir "%ProgramFiles%\NVIDIA Corporation\NvToolsExt\include" +mkdir "%ProgramFiles%\NVIDIA Corporation\NvToolsExt\lib\x64" +xcopy /Y "%SRC_DIR%\temp_build\NvToolsExt\bin\x64\*.*" "%ProgramFiles%\NVIDIA Corporation\NvToolsExt\bin\x64" +xcopy /Y "%SRC_DIR%\temp_build\NvToolsExt\include\*.*" "%ProgramFiles%\NVIDIA Corporation\NvToolsExt\include" +xcopy /Y "%SRC_DIR%\temp_build\NvToolsExt\lib\x64\*.*" "%ProgramFiles%\NVIDIA Corporation\NvToolsExt\lib\x64" + +set "NVTOOLSEXT_PATH=%ProgramFiles%\NVIDIA Corporation\NvToolsExt\" + +goto end_check + +:magma + +set "CUDA_PREFIX=cuda%CUDA_VERSION%" +set "MAGMA_URL=https://s3.amazonaws.com/ossci-windows/magma_%CUDA_PREFIX%_release_mkl_2018.2.185.7z" +curl -k %MAGMA_URL% --output "%SRC_DIR%\temp_build\magma.7z" + +echo Installing MAGMA... +7z x %SRC_DIR%\temp_build\magma.7z -o"%SRC_DIR%\temp_build\magma" +set "MAGMA_HOME=%SRC_DIR%\temp_build\magma\" + +goto end_check + +:mkl + +IF NOT EXIST "%SRC_DIR%\temp_build\mkl.7z" ( + curl -k https://s3.amazonaws.com/ossci-windows/mkl_2018.2.185.7z --output %SRC_DIR%\temp_build\mkl.7z +) + +7z x "%SRC_DIR%\temp_build\mkl.7z" -o"%SRC_DIR%\temp_build\mkl" +set "LIB=%SRC_DIR%\temp_build\mkl\lib;%LIB%" +set "CMAKE_INCLUDE_PATH=%CD%\temp_build\mkl\include" + +goto end_check + +:ninja + +%PIP_BIN% install ninja + +goto end_check + + +:end_check +IF ERRORLEVEL 1 exit /b 1 +IF NOT ERRORLEVEL 0 exit /b 1 \ No newline at end of file diff --git a/internal/check_deps.bat b/internal/check_deps.bat index 9e53de0..f4fd900 100644 --- a/internal/check_deps.bat +++ b/internal/check_deps.bat @@ -2,40 +2,13 @@ REM Check for necessary components +set SRC_DIR=%~dp0\.. + IF NOT "%PROCESSOR_ARCHITECTURE%"=="AMD64" ( echo You should use 64 bits Windows to build and run PyTorch exit /b 1 ) -where /q cmake.exe - -IF ERRORLEVEL 1 ( - echo CMake is required to compile PyTorch on Windows - exit /b 1 -) - -IF NOT EXIST "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" ( - echo Visual Studio 2017 C++ BuildTools is required to compile PyTorch on Windows - exit /b 1 -) - -for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -version [15^,16^) -property installationPath`) do ( - if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" ( - set "VS15INSTALLDIR=%%i" - set "VS15VCVARSALL=%%i\VC\Auxiliary\Build\vcvarsall.bat" - goto vswhere - ) -) - -:vswhere -IF "%VS15VCVARSALL%"=="" ( - echo Visual Studio 2017 C++ BuildTools is required to compile PyTorch on Windows - exit /b 1 -) - -set MSSdk=1 -set DISTUTILS_USE_SDK=1 - where /q python.exe IF ERRORLEVEL 1 ( @@ -89,3 +62,107 @@ if %PYSIZE% NEQ 64 ( echo Python x64 3.5 or up is required to compile PyTorch on Windows exit /b 1 ) + +IF "%AUTO_RESOLVE_MODE%" == "RECOMMENDED" ( + set /a AUTO_RESOLVE_VALUE=2 +) ELSE ( + IF "%AUTO_RESOLVE_MODE%" == "MINIMAL" ( + set /a AUTO_RESOLVE_VALUE=1 + ) ELSE ( + set /a AUTO_RESOLVE_VALUE=0 + ) +) + +IF NOT %AUTO_RESOLVE_VALUE% GEQ 1 goto auto_resolve_check_end + +IF NOT EXIST "%CD%\tmp_build" ( + mkdir %CD%\tmp_build +) + +where /q choco.exe +IF ERRORLEVEL 1 ( + set NO_CHOCO=1 +) + +where /q curl.exe + +IF ERRORLEVEL 1 ( + IF "%NO_CHOCO%" == "1" ( + echo Chocolatey is required to resolve missing dependencies automatically. + echo If you don't want to install it, please install cURL. + exit /b 1 + ) + echo Installing cURL... + choco install -y curl +) + +where /q 7z.exe + +IF ERRORLEVEL 1 ( + IF "%NO_CHOCO%" == "1" ( + echo Chocolatey is required to resolve missing dependencies automatically. + echo If you don't want to install it, please install 7Zip. + exit /b 1 + ) + echo Installing 7Zip... + choco install -y 7Zip +) + +for /F "usebackq delims=" %%i in (`python -c "import sys; print('{0[0]}{0[1]}'.format(sys.version_info))"`) do ( + set "PIP_BIN=%%i\Scripts\pip.exe" +) + +IF NOT EXIST %PIP_BIN% ( + echo It looks like pip is not installed in your current Python environment. + echo Please install it before running this build script. + exit /b 1 +) + +:auto_resolve_check_end + +IF NOT EXIST "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" ( + IF %AUTO_RESOLVE_VALUE% GEQ 1 ( + echo Installing VS BuildTools... + call .\auto_resolve.bat vs + IF ERRORLEVEL 1 exit /b 1 + goto vs_check + ) ELSE ( + echo Visual Studio 2017 C++ BuildTools is required to compile PyTorch on Windows + exit /b 1 + ) +) + +:vs_check +for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -version [15^,16^) -property installationPath`) do ( + if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" ( + set "VS15INSTALLDIR=%%i" + set "VS15VCVARSALL=%%i\VC\Auxiliary\Build\vcvarsall.bat" + goto vswhere + ) +) + +:vswhere +IF "%VS15VCVARSALL%"=="" ( + echo Visual Studio 2017 C++ BuildTools is required to compile PyTorch on Windows + exit /b 1 +) + +set MSSdk=1 +set DISTUTILS_USE_SDK=1 + +where /q cmake.exe + +IF ERRORLEVEL 1 ( + IF %AUTO_RESOLVE_VALUE% GEQ 1 ( + IF "%NO_CHOCO%" == 1 ( + echo Chocolatey is required to resolve missing dependencies automatically. + echo If you don't want to install it, please install CMake. + ) ELSE ( + echo Installing CMake... + choco install -y cmake + ) + ) ELSE ( + echo CMake is required to compile PyTorch on Windows + exit /b 1 + ) +) diff --git a/internal/check_opts.bat b/internal/check_opts.bat index de19840..48a7857 100644 --- a/internal/check_opts.bat +++ b/internal/check_opts.bat @@ -8,8 +8,14 @@ IF NOT ERRORLEVEL 1 ( echo Ninja found, using it to speed up builds set CMAKE_GENERATOR=Ninja ) ELSE ( - echo Ninja not found. It can be used to accelerate builds. - echo You can install ninja using ^`pip install ninja^`. + IF %AUTO_RESOLVE_VALUE% GEQ 2 ( + echo Installing Ninja... + call .\auto_resolve.bat ninja + IF ERRORLEVEL 1 exit /b 1 + ) ELSE ( + echo Ninja not found. It can be used to accelerate builds. + echo You can install ninja using ^`pip install ninja^`. + ) ) where /q clcache.exe @@ -44,13 +50,24 @@ IF exist "%MKLProductDir%\mkl\lib\intel64_win" ( echo MKL found, adding it to build set "CMAKE_INCLUDE_PATH=%MKLProductDir%\mkl\include" set "LIB=%MKLProductDir%\mkl\lib\intel64_win;%MKLProductDir%\compiler\lib\intel64_win;%LIB%"; +) ELSE ( + IF %AUTO_RESOLVE_VALUE% GEQ 2 ( + echo Installing MKL... + call .\auto_resolve.bat mkl + IF ERRORLEVEL 1 exit /b 1 + ) ) if "%NO_CUDA%"=="" ( IF "%MAGMA_HOME%" == "" ( echo MAGMA_HOME is set. MAGMA will be included in build. ) ELSE ( - echo MAGMA_HOME not set. Skip MAGMA in build. + IF %AUTO_RESOLVE_VALUE% GEQ 2 ( + call .\auto_resolve.bat magma + IF ERRORLEVEL 1 exit /b 1 + ) ELSE ( + echo MAGMA_HOME not set. Skip MAGMA in build. + ) ) ) diff --git a/internal/setup.bat b/internal/setup.bat index 31d28e1..e97cb87 100644 --- a/internal/setup.bat +++ b/internal/setup.bat @@ -28,6 +28,7 @@ IF NOT "%CMAKE_GENERATOR%" == "Ninja" goto reactivate_end set SRC_DIR=%~dp0\.. +:activate setlocal call "%VS15VCVARSALL%" x64 -vcvars_ver=14.11 call "%VS15VCVARSALL%" x86_amd64 -vcvars_ver=14.11 @@ -37,8 +38,14 @@ IF ERRORLEVEL 1 ( echo VS 14.11 toolset not found endlocal IF NOT "%SKIP_VS_VER_CHECK%" == "1" ( - echo Use ^`set SKIP_VS_VER_CHECK^=1^` to override this error. - goto no + IF %AUTO_RESOLVE_VALUE% GEQ 1 ( + call internal\auto_resolve.bat vs1411 + IF ERRORLEVEL 1 exit /b 1 + goto activate + ) ELSE ( + echo Use ^`set SKIP_VS_VER_CHECK^=1^` to override this error. + goto no + ) ) ) ELSE ( goto reactivate_end