diff --git a/packaging/README.md b/packaging/README.md index e67565b60ce..7d3c5f7831b 100644 --- a/packaging/README.md +++ b/packaging/README.md @@ -29,6 +29,18 @@ conda install -y conda-build anaconda-client # anaconda upload -u pytorch torchvision*.bz2 ``` +### Windows + +```bash +# Open `Git Bash` and change dir to `conda` +./build_vision.sh 9.0 +./build_vision.sh 10.0 +./build_vision.sh cpu + +# copy packages to a output directory +# anaconda upload -u pytorch torchvision*.bz2 +``` + ## Wheels ### Linux @@ -62,6 +74,17 @@ pushd wheel ./osx_wheel.sh ``` +### Windows + +```cmd +set PYTORCH_REPO=pytorch + +pushd windows +call build_vision.bat 90 0.3.0 1 +call build_vision.bat 100 0.3.0 1 +call build_vision.bat cpu 0.3.0 1 +``` + wheels are in the current folder. You can upload them to twine with `twine upload *.whl` diff --git a/packaging/conda/install_conda.bat b/packaging/conda/install_conda.bat new file mode 100644 index 00000000000..6052ad08b10 --- /dev/null +++ b/packaging/conda/install_conda.bat @@ -0,0 +1 @@ +start /wait "" "%miniconda_exe%" /S /InstallationType=JustMe /RegisterPython=0 /AddToPath=0 /D=%tmp_conda% diff --git a/packaging/windows/build_vision.bat b/packaging/windows/build_vision.bat new file mode 100644 index 00000000000..c7b65dc04f1 --- /dev/null +++ b/packaging/windows/build_vision.bat @@ -0,0 +1,94 @@ +@echo off + +:: This script parses args, installs required libraries (miniconda, MKL, +:: Magma), and then delegates to cpu.bat, cuda80.bat, etc. + +IF NOT "%CUDA_VERSION%" == "" IF NOT "%TORCHVISION_BUILD_VERSION%" == "" if NOT "%TORCHVISION_BUILD_NUMBER%" == "" goto env_end +if "%~1"=="" goto arg_error +if "%~2"=="" goto arg_error +if "%~3"=="" goto arg_error +if NOT "%~4"=="" goto arg_error +goto arg_end + +:arg_error + +echo Illegal number of parameters. Pass cuda version, pytorch version, build number +echo CUDA version should be Mm with no dot, e.g. '80' +echo DESIRED_PYTHON should be M.m, e.g. '2.7' +exit /b 1 + +:arg_end + +set CUDA_VERSION=%~1 +set TORCHVISION_BUILD_VERSION=%~2 +set TORCHVISION_BUILD_NUMBER=%~3 + +:env_end + +if NOT "%CUDA_VERSION%" == "cpu" ( + set CUDA_PREFIX=cuda%CUDA_VERSION% + set CUVER=cu%CUDA_VERSION% +) else ( + set CUDA_PREFIX=cpu + set CUVER=cpu +) + +set BUILD_VISION=1 +set TORCH_WHEEL=torch -f https://download.pytorch.org/whl/%CUVER%/stable.html --no-index + +IF "%DESIRED_PYTHON%" == "" set DESIRED_PYTHON=3.5;3.6;3.7 +set DESIRED_PYTHON_PREFIX=%DESIRED_PYTHON:.=% +set DESIRED_PYTHON_PREFIX=py%DESIRED_PYTHON_PREFIX:;=;py% + +set SRC_DIR=%~dp0 +pushd %SRC_DIR% + +:: Install Miniconda3 +set "CONDA_HOME=%CD%\conda" +set "tmp_conda=%CONDA_HOME%" +set "miniconda_exe=%CD%\miniconda.exe" +rmdir /s /q conda +del miniconda.exe +curl -k https://repo.continuum.io/miniconda/Miniconda3-latest-Windows-x86_64.exe -o "%miniconda_exe%" +call ..\conda\install_conda.bat +IF ERRORLEVEL 1 exit /b 1 +set "ORIG_PATH=%PATH%" +set "PATH=%CONDA_HOME%;%CONDA_HOME%\scripts;%CONDA_HOME%\Library\bin;%PATH%" + +:: Create a new conda environment +setlocal EnableDelayedExpansion +FOR %%v IN (%DESIRED_PYTHON%) DO ( + set PYTHON_VERSION_STR=%%v + set PYTHON_VERSION_STR=!PYTHON_VERSION_STR:.=! + conda remove -n py!PYTHON_VERSION_STR! --all -y || rmdir %CONDA_HOME%\envs\py!PYTHON_VERSION_STR! /s + conda create -n py!PYTHON_VERSION_STR! -y -q numpy>=1.11 mkl>=2018 python=%%v +) +endlocal + +if "%DEBUG%" == "1" ( + set BUILD_TYPE=debug +) ELSE ( + set BUILD_TYPE=release +) + +for %%v in (%DESIRED_PYTHON_PREFIX%) do ( + :: Activate Python Environment + set PYTHON_PREFIX=%%v + set "PATH=%CONDA_HOME%\envs\%%v;%CONDA_HOME%\envs\%%v\scripts;%CONDA_HOME%\envs\%%v\Library\bin;%ORIG_PATH%" + pip install %TORCH_WHEEL% + @setlocal + :: Set Flags + if NOT "%CUDA_VERSION%"=="cpu" ( + set CUDNN_VERSION=7 + ) + call %CUDA_PREFIX%.bat + IF ERRORLEVEL 1 exit /b 1 + call internal\test.bat + IF ERRORLEVEL 1 exit /b 1 + @endlocal +) + +set "PATH=%ORIG_PATH%" +popd + +IF ERRORLEVEL 1 exit /b 1 diff --git a/packaging/windows/cpu.bat b/packaging/windows/cpu.bat new file mode 100644 index 00000000000..392a687f9dc --- /dev/null +++ b/packaging/windows/cpu.bat @@ -0,0 +1,37 @@ +@echo off + +IF NOT "%BUILD_VISION%" == "" ( + set MODULE_NAME=vision +) ELSE ( + set MODULE_NAME=pytorch +) + +IF NOT EXIST "setup.py" IF NOT EXIST "%MODULE_NAME%" ( + call internal\clone.bat + cd .. + IF ERRORLEVEL 1 goto eof +) ELSE ( + call internal\clean.bat +) + +call internal\check_deps.bat +IF ERRORLEVEL 1 goto eof + +REM Check for optional components + +echo Disabling CUDA +set NO_CUDA=1 +set USE_CUDA=0 + +IF "%BUILD_VISION%" == "" ( + call internal\check_opts.bat + IF ERRORLEVEL 1 goto eof + + call internal\copy_cpu.bat + IF ERRORLEVEL 1 goto eof +) + +call internal\setup.bat +IF ERRORLEVEL 1 goto eof + +:eof diff --git a/packaging/windows/cuda100.bat b/packaging/windows/cuda100.bat new file mode 100644 index 00000000000..ac9be3c6907 --- /dev/null +++ b/packaging/windows/cuda100.bat @@ -0,0 +1,59 @@ +@echo off + +IF NOT "%BUILD_VISION%" == "" ( + set MODULE_NAME=vision +) ELSE ( + set MODULE_NAME=pytorch +) + +IF NOT EXIST "setup.py" IF NOT EXIST "%MODULE_NAME%" ( + call internal\clone.bat + cd .. + IF ERRORLEVEL 1 goto eof +) ELSE ( + call internal\clean.bat +) + +call internal\check_deps.bat +IF ERRORLEVEL 1 goto eof + +REM Check for optional components + +set NO_CUDA= +set CMAKE_GENERATOR=Visual Studio 15 2017 Win64 + +IF "%NVTOOLSEXT_PATH%"=="" ( + echo NVTX ^(Visual Studio Extension ^for CUDA^) ^not installed, failing + exit /b 1 + goto optcheck +) + +IF "%CUDA_PATH_V10_0%"=="" ( + echo CUDA 10.0 not found, failing + exit /b 1 +) ELSE ( + IF "%BUILD_VISION%" == "" ( + set TORCH_CUDA_ARCH_LIST=3.5;5.0+PTX;6.0;6.1;7.0;7.5 + set TORCH_NVCC_FLAGS=-Xfatbin -compress-all + ) ELSE ( + set NVCC_FLAGS=-D__CUDA_NO_HALF_OPERATORS__ --expt-relaxed-constexpr -gencode=arch=compute_35,code=sm_35 -gencode=arch=compute_50,code=sm_50 -gencode=arch=compute_60,code=sm_60 -gencode=arch=compute_70,code=sm_70 -gencode=arch=compute_75,code=sm_75 -gencode=arch=compute_50,code=compute_50 + ) + + set "CUDA_PATH=%CUDA_PATH_V10_0%" + set "PATH=%CUDA_PATH_V10_0%\bin;%PATH%" +) + +:optcheck + +IF "%BUILD_VISION%" == "" ( + call internal\check_opts.bat + IF ERRORLEVEL 1 goto eof + + call internal\copy.bat + IF ERRORLEVEL 1 goto eof +) + +call internal\setup.bat +IF ERRORLEVEL 1 goto eof + +:eof diff --git a/packaging/windows/cuda90.bat b/packaging/windows/cuda90.bat new file mode 100644 index 00000000000..fe0294812e2 --- /dev/null +++ b/packaging/windows/cuda90.bat @@ -0,0 +1,59 @@ +@echo off + +IF NOT "%BUILD_VISION%" == "" ( + set MODULE_NAME=vision +) ELSE ( + set MODULE_NAME=pytorch +) + +IF NOT EXIST "setup.py" IF NOT EXIST "%MODULE_NAME%" ( + call internal\clone.bat + cd .. + IF ERRORLEVEL 1 goto eof +) ELSE ( + call internal\clean.bat +) + +call internal\check_deps.bat +IF ERRORLEVEL 1 goto eof + +REM Check for optional components + +set NO_CUDA= +set CMAKE_GENERATOR=Visual Studio 15 2017 Win64 + +IF "%NVTOOLSEXT_PATH%"=="" ( + echo NVTX ^(Visual Studio Extension ^for CUDA^) ^not installed, failing + exit /b 1 + goto optcheck +) + +IF "%CUDA_PATH_V9_0%"=="" ( + echo CUDA 9 not found, failing + exit /b 1 +) ELSE ( + IF "%BUILD_VISION%" == "" ( + set TORCH_CUDA_ARCH_LIST=3.5;5.0+PTX;6.0;7.0 + set TORCH_NVCC_FLAGS=-Xfatbin -compress-all + ) ELSE ( + set NVCC_FLAGS=-D__CUDA_NO_HALF_OPERATORS__ --expt-relaxed-constexpr -gencode=arch=compute_35,code=sm_35 -gencode=arch=compute_50,code=sm_50 -gencode=arch=compute_60,code=sm_60 -gencode=arch=compute_70,code=sm_70 -gencode=arch=compute_50,code=compute_50 + ) + + set "CUDA_PATH=%CUDA_PATH_V9_0%" + set "PATH=%CUDA_PATH_V9_0%\bin;%PATH%" +) + +:optcheck + +IF "%BUILD_VISION%" == "" ( + call internal\check_opts.bat + IF ERRORLEVEL 1 goto eof + + call internal\copy.bat + IF ERRORLEVEL 1 goto eof +) + +call internal\setup.bat +IF ERRORLEVEL 1 goto eof + +:eof diff --git a/packaging/windows/internal/7z_install.bat b/packaging/windows/internal/7z_install.bat new file mode 100644 index 00000000000..d5a1156360d --- /dev/null +++ b/packaging/windows/internal/7z_install.bat @@ -0,0 +1,9 @@ +@echo off + +curl -k https://www.7-zip.org/a/7z1805-x64.exe -O +if errorlevel 1 exit /b 1 + +start /wait 7z1805-x64.exe /S +if errorlevel 1 exit /b 1 + +set "PATH=%ProgramFiles%\7-Zip;%PATH%" diff --git a/packaging/windows/internal/auth.bat b/packaging/windows/internal/auth.bat new file mode 100644 index 00000000000..c874bce493c --- /dev/null +++ b/packaging/windows/internal/auth.bat @@ -0,0 +1,46 @@ +@echo off + +: From the following doc, the build won't be triggered if the users don't sign in daily. +: https://docs.microsoft.com/en-us/azure/devops/pipelines/build/triggers?tabs=yaml&view=vsts#my-build-didnt-run-what-happened +: To avoid this problem, we can just go through the sign in process using the following command. + +:auth_start + +if "%RETRY_TIMES%" == "" ( + set /a RETRY_TIMES=10 + set /a SLEEP_TIME=2 +) else ( + set /a RETRY_TIMES=%RETRY_TIMES%-1 + set /a SLEEP_TIME=%SLEEP_TIME%*2 +) + +for /f "usebackq tokens=*" %%i in (`curl -so NUL -w "%%{http_code}" -u %VSTS_AUTH% https://dev.azure.com/pytorch`) do ( + set STATUS_CODE=%%i +) + +IF NOT "%STATUS_CODE%" == "200" ( + echo Auth retry times remaining: %RETRY_TIMES% + echo Sleep time: %SLEEP_TIME% seconds + IF %RETRY_TIMES% EQU 0 ( + echo Auth failed + goto err + ) + waitfor SomethingThatIsNeverHappening /t %SLEEP_TIME% 2>nul || ver >nul + goto auth_start +) ELSE ( + echo Login Attempt Succeeded + goto auth_end +) + +:err + +: Throw a warning if it fails +powershell -c "Write-Warning 'Login Attempt Failed'" + +:auth_end + +set RETRY_TIMES= +set SLEEP_TIME= +set STATUS_CODE= + +exit /b 0 diff --git a/packaging/windows/internal/check_deps.bat b/packaging/windows/internal/check_deps.bat new file mode 100644 index 00000000000..a159d4436d6 --- /dev/null +++ b/packaging/windows/internal/check_deps.bat @@ -0,0 +1,67 @@ +@echo off + +REM Check for necessary components + +IF NOT "%PROCESSOR_ARCHITECTURE%"=="AMD64" ( + echo You should use 64 bits Windows to build and run PyTorch + exit /b 1 +) + +IF "%BUILD_VISION%" == "" ( + 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 -products * -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 ( + echo Python x64 3.5 or up is required to compile PyTorch on Windows + exit /b 1 +) + +for /F "usebackq delims=" %%i in (`python -c "import sys; print('{0[0]}{0[1]}'.format(sys.version_info))"`) do ( + set /a PYVER=%%i +) + +if %PYVER% LSS 35 ( + echo Warning: PyTorch for Python 2 under Windows is experimental. + echo Python x64 3.5 or up is recommended to compile PyTorch on Windows + echo Maybe you can create a virual environment if you have conda installed: + echo ^> conda create -n test python=3.6 pyyaml mkl numpy + echo ^> activate test +) + +for /F "usebackq delims=" %%i in (`python -c "import struct;print( 8 * struct.calcsize('P'))"`) do ( + set /a PYSIZE=%%i +) + +if %PYSIZE% NEQ 64 ( + echo Python x64 3.5 or up is required to compile PyTorch on Windows + exit /b 1 +) diff --git a/packaging/windows/internal/check_opts.bat b/packaging/windows/internal/check_opts.bat new file mode 100644 index 00000000000..003ad921328 --- /dev/null +++ b/packaging/windows/internal/check_opts.bat @@ -0,0 +1,33 @@ +@echo off + +REM Check for optional components + +where /q ninja.exe + +IF NOT ERRORLEVEL 1 ( + echo Ninja found, using it to speed up builds + set CMAKE_GENERATOR=Ninja +) + +where /q clcache.exe + +IF NOT ERRORLEVEL 1 ( + echo clcache found, using it to speed up builds + set CC=clcache + set CXX=clcache +) + +where /q sccache.exe + +IF NOT ERRORLEVEL 1 ( + echo sccache found, using it to speed up builds + set CC=sccache cl + set CXX=sccache cl +) + +IF exist "%MKLProductDir%\mkl\lib\intel64_win" ( + echo MKL found, adding it to build + set "LIB=%MKLProductDir%\mkl\lib\intel64_win;%MKLProductDir%\compiler\lib\intel64_win;%LIB%"; +) + +exit /b 0 diff --git a/packaging/windows/internal/clean.bat b/packaging/windows/internal/clean.bat new file mode 100644 index 00000000000..7489640f49a --- /dev/null +++ b/packaging/windows/internal/clean.bat @@ -0,0 +1,5 @@ +@echo off + +cd %MODULE_NAME% +python setup.py clean +cd .. diff --git a/packaging/windows/internal/clone.bat b/packaging/windows/internal/clone.bat new file mode 100644 index 00000000000..f93271978c6 --- /dev/null +++ b/packaging/windows/internal/clone.bat @@ -0,0 +1,60 @@ +@echo off + +:: The conda and wheels jobs are seperated on Windows, so we don't need to clone again. +IF "%BUILD_VISION%" == "" ( + if exist "%NIGHTLIES_PYTORCH_ROOT%" ( + xcopy /E /Y /Q "%NIGHTLIES_PYTORCH_ROOT%" pytorch\ + cd pytorch + goto submodule + ) +) + +git clone https://github.com/%PYTORCH_REPO%/%MODULE_NAME% + +cd %MODULE_NAME% + +IF NOT "%BUILD_VISION%" == "" goto latest_end + +IF "%PYTORCH_BRANCH%" == "latest" ( goto latest_start ) else ( goto latest_end ) + +:latest_start + +if "%NIGHTLIES_DATE%" == "" ( goto date_start ) else ( goto date_end ) + +:date_start + +set "DATE_CMD=Get-Date ([System.TimeZoneInfo]::ConvertTimeFromUtc((Get-Date).ToUniversalTime(), [System.TimeZoneInfo]::FindSystemTimeZoneById('Pacific Standard Time'))) -f 'yyyy_MM_dd'" +set "DATE_COMPACT_CMD=Get-Date ([System.TimeZoneInfo]::ConvertTimeFromUtc((Get-Date).ToUniversalTime(), [System.TimeZoneInfo]::FindSystemTimeZoneById('Pacific Standard Time'))) -f 'yyyyMMdd'" + +FOR /F "delims=" %%i IN ('powershell -c "%DATE_CMD%"') DO set NIGHTLIES_DATE=%%i +FOR /F "delims=" %%i IN ('powershell -c "%DATE_COMPACT_CMD%"') DO set NIGHTLIES_DATE_COMPACT=%%i + +:date_end + +if "%NIGHTLIES_DATE_COMPACT%" == "" set NIGHTLIES_DATE_COMPACT=%NIGHTLIES_DATE:~0,4%%NIGHTLIES_DATE:~5,2%%NIGHTLIES_DATE:~8,2% + +:: Switch to the latest commit by 11:59 yesterday +echo PYTORCH_BRANCH is set to latest so I will find the last commit +echo before 0:00 midnight on %NIGHTLIES_DATE% +set git_date=%NIGHTLIES_DATE:_=-% +FOR /F "delims=" %%i IN ('git log --before %git_date% -n 1 "--pretty=%%H"') DO set last_commit=%%i +echo Setting PYTORCH_BRANCH to %last_commit% since that was the last +echo commit before %NIGHTLIES_DATE% +set PYTORCH_BRANCH=%last_commit% + +:latest_end + +IF "%BUILD_VISION%" == "" ( + IF "%PYTORCH_BRANCH%" == "" ( + set PYTORCH_BRANCH=v%PYTORCH_BUILD_VERSION% + ) + git checkout %PYTORCH_BRANCH% + IF ERRORLEVEL 1 git checkout tags/%PYTORCH_BRANCH% +) ELSE ( + git checkout v%TORCHVISION_BUILD_VERSION% +) + +:submodule + +git submodule update --init --recursive +IF ERRORLEVEL 1 exit /b 1 diff --git a/packaging/windows/internal/copy.bat b/packaging/windows/internal/copy.bat new file mode 100644 index 00000000000..b4aa397c6c1 --- /dev/null +++ b/packaging/windows/internal/copy.bat @@ -0,0 +1,13 @@ +copy "%CUDA_PATH%\bin\cusparse64_%CUDA_VERSION%.dll*" pytorch\torch\lib +copy "%CUDA_PATH%\bin\cublas64_%CUDA_VERSION%.dll*" pytorch\torch\lib +copy "%CUDA_PATH%\bin\cudart64_%CUDA_VERSION%.dll*" pytorch\torch\lib +copy "%CUDA_PATH%\bin\curand64_%CUDA_VERSION%.dll*" pytorch\torch\lib +copy "%CUDA_PATH%\bin\cufft64_%CUDA_VERSION%.dll*" pytorch\torch\lib +copy "%CUDA_PATH%\bin\cufftw64_%CUDA_VERSION%.dll*" pytorch\torch\lib + +copy "%CUDA_PATH%\bin\cudnn64_%CUDNN_VERSION%.dll*" pytorch\torch\lib +copy "%CUDA_PATH%\bin\nvrtc64_%CUDA_VERSION%*.dll*" pytorch\torch\lib +copy "%CUDA_PATH%\bin\nvrtc-builtins64_%CUDA_VERSION%.dll*" pytorch\torch\lib + +copy "C:\Program Files\NVIDIA Corporation\NvToolsExt\bin\x64\nvToolsExt64_1.dll*" pytorch\torch\lib +copy "%CONDA_LIB_PATH%\libiomp*5md.dll" pytorch\torch\lib diff --git a/packaging/windows/internal/copy_cpu.bat b/packaging/windows/internal/copy_cpu.bat new file mode 100644 index 00000000000..f5b9d11515f --- /dev/null +++ b/packaging/windows/internal/copy_cpu.bat @@ -0,0 +1 @@ +copy "%CONDA_LIB_PATH%\libiomp*5md.dll" pytorch\torch\lib diff --git a/packaging/windows/internal/cuda_install.bat b/packaging/windows/internal/cuda_install.bat new file mode 100644 index 00000000000..b6ea9e23739 --- /dev/null +++ b/packaging/windows/internal/cuda_install.bat @@ -0,0 +1,122 @@ +@echo off + +set SRC_DIR=%~dp0\.. + +if not exist "%SRC_DIR%\temp_build" mkdir "%SRC_DIR%\temp_build" + +set /a CUDA_VER=%CUDA_VERSION% +set CUDA_VER_MAJOR=%CUDA_VERSION:~0,-1% +set CUDA_VER_MINOR=%CUDA_VERSION:~-1,1% +set CUDA_VERSION_STR=%CUDA_VER_MAJOR%.%CUDA_VER_MINOR% + +IF %CUDA_VER% LEQ 90 ( + set "NVCC_PACKAGE=compiler_%CUDA_VERSION_STR%" +) ELSE ( + set "NVCC_PACKAGE=nvcc_%CUDA_VERSION_STR%" +) + +IF %CUDA_VER% EQU 80 goto cuda80 +IF %CUDA_VER% EQU 90 goto cuda90 +IF %CUDA_VER% EQU 91 goto cuda91 +IF %CUDA_VER% EQU 92 goto cuda92 +IF %CUDA_VER% EQU 100 goto cuda100 + +echo CUDA %CUDA_VERSION_STR% is not supported +exit /b 1 + +:cuda80 + +echo CUDA 8.0 is not supported +exit /b 1 + +:cuda90 +IF NOT EXIST "%SRC_DIR%\temp_build\cuda_9.0.176_windows.7z" ( + curl -k -L 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" + if errorlevel 1 exit /b 1 + 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 -L 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" + if errorlevel 1 exit /b 1 + 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 -L 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" + if errorlevel 1 exit /b 1 + 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 -L 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" + if errorlevel 1 exit /b 1 + set "CUDNN_SETUP_FILE=%SRC_DIR%\temp_build\cudnn-9.1-windows7-x64-v7.zip" +) + +goto cuda_common + +:cuda92 + +echo CUDA 9.2 is not supported +exit /b 1 + +:cuda100 + +echo CUDA 10.0 is not supported +exit /b 1 + +:cuda_common + +set "CUDA_PREFIX=cuda%CUDA_VERSION%" + +IF NOT EXIST "%SRC_DIR%\temp_build\NvToolsExt.7z" ( + curl -k -L https://www.dropbox.com/s/9mcolalfdj4n979/NvToolsExt.7z?dl=1 --output "%SRC_DIR%\temp_build\NvToolsExt.7z" + if errorlevel 1 exit /b 1 +) + +echo Installing CUDA toolkit... + +7z x %CUDA_SETUP_FILE% -o"%SRC_DIR%\temp_build\cuda" +pushd "%SRC_DIR%\temp_build\cuda" +dir +start /wait 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% +popd +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_V%CUDA_VER_MAJOR%_%CUDA_VER_MINOR%=%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%" +set "NVTOOLSEXT_PATH=%ProgramFiles%\NVIDIA Corporation\NvToolsExt\" + +echo Cleaning temp files +rd /s /q "%SRC_DIR%\temp_build" +pushd %TEMP% +rd /s /q . +popd + +echo Using VS2015 as NVCC compiler +set "CUDAHOSTCXX=%VS140COMNTOOLS%\..\..\VC\bin\amd64\cl.exe" diff --git a/packaging/windows/internal/setup.bat b/packaging/windows/internal/setup.bat new file mode 100644 index 00000000000..fcf10f185c7 --- /dev/null +++ b/packaging/windows/internal/setup.bat @@ -0,0 +1,91 @@ +@echo off + +echo The flags after configuring: +echo NO_CUDA=%NO_CUDA% +echo CMAKE_GENERATOR=%CMAKE_GENERATOR% +if "%NO_CUDA%"=="" echo CUDA_PATH=%CUDA_PATH% +if NOT "%CC%"=="" echo CC=%CC% +if NOT "%CXX%"=="" echo CXX=%CXX% +if NOT "%DISTUTILS_USE_SDK%"=="" echo DISTUTILS_USE_SDK=%DISTUTILS_USE_SDK% + +set SRC_DIR=%~dp0\.. + +IF "%VSDEVCMD_ARGS%" == "" ( + call "%VS15VCVARSALL%" x64 +) ELSE ( + call "%VS15VCVARSALL%" x64 %VSDEVCMD_ARGS% +) + +pushd %SRC_DIR% + +IF NOT exist "setup.py" ( + cd %MODULE_NAME% +) + +if "%CXX%"=="sccache cl" ( + sccache --stop-server + sccache --start-server + sccache --zero-stats +) + + +if "%BUILD_PYTHONLESS%" == "" goto pytorch else goto libtorch + +:libtorch +set VARIANT=shared-with-deps + +mkdir libtorch +mkdir libtorch\bin +mkdir libtorch\cmake +mkdir libtorch\include +mkdir libtorch\lib +mkdir libtorch\share +mkdir libtorch\test + +mkdir build +pushd build +python ../tools/build_libtorch.py +popd + +IF ERRORLEVEL 1 exit /b 1 +IF NOT ERRORLEVEL 0 exit /b 1 + +move /Y torch\bin\*.* libtorch\bin\ +move /Y torch\cmake\*.* libtorch\cmake\ +robocopy /move /e torch\include\ libtorch\include\ +move /Y torch\lib\*.* libtorch\lib\ +robocopy /move /e torch\share\ libtorch\share\ +move /Y torch\test\*.* libtorch\test\ + +move /Y libtorch\bin\*.dll libtorch\lib\ + +git rev-parse HEAD > libtorch\build-hash + +IF "%DEBUG%" == "" ( + set LIBTORCH_PREFIX=libtorch-win-%VARIANT% +) ELSE ( + set LIBTORCH_PREFIX=libtorch-win-%VARIANT%-debug +) + +7z a -tzip %LIBTORCH_PREFIX%-%PYTORCH_BUILD_VERSION%.zip libtorch\* + +mkdir ..\output\%CUDA_PREFIX% +copy /Y %LIBTORCH_PREFIX%-%PYTORCH_BUILD_VERSION%.zip ..\output\%CUDA_PREFIX%\ +copy /Y %LIBTORCH_PREFIX%-%PYTORCH_BUILD_VERSION%.zip ..\output\%CUDA_PREFIX%\%LIBTORCH_PREFIX%-latest.zip + +goto build_end + +:pytorch +:: This stores in e.g. D:/_work/1/s/windows/output/cpu +pip wheel -e . --no-deps --wheel-dir ../output/%CUDA_PREFIX% + +:build_end +IF ERRORLEVEL 1 exit /b 1 +IF NOT ERRORLEVEL 0 exit /b 1 + +if "%CXX%"=="sccache cl" ( + taskkill /im sccache.exe /f /t || ver > nul + taskkill /im nvcc.exe /f /t || ver > nul +) + +cd .. diff --git a/packaging/windows/internal/test.bat b/packaging/windows/internal/test.bat new file mode 100644 index 00000000000..1ad7d2ebeb8 --- /dev/null +++ b/packaging/windows/internal/test.bat @@ -0,0 +1,75 @@ +@echo off + +set SRC_DIR=%~dp0\.. +pushd %SRC_DIR% + +set PYTHON_VERSION=%PYTHON_PREFIX:py=cp% + +if "%BUILD_VISION%" == "" ( + pip install future pytest coverage hypothesis protobuf +) ELSE ( + pip install future pytest "pillow>=4.1.1" +) + + +for /F "delims=" %%i in ('where /R %SRC_DIR%\output\%CUDA_PREFIX% %MODULE_NAME%*%PYTHON_VERSION%*.whl') do pip install "%%i" + +if ERRORLEVEL 1 exit /b 1 + +if NOT "%BUILD_VISION%" == "" goto smoke_test_end + +echo Smoke testing imports +python -c "import torch" +if ERRORLEVEL 1 exit /b 1 + +python -c "from caffe2.python import core" +if ERRORLEVEL 1 exit /b 1 + +echo Checking that MKL is available +python -c "import torch; exit(0 if torch.backends.mkl.is_available() else 1)" +if ERRORLEVEL 1 exit /b 1 + +setlocal EnableDelayedExpansion +set NVIDIA_GPU_EXISTS=0 +for /F "delims=" %%i in ('wmic path win32_VideoController get name') do ( + set GPUS=%%i + if not "x!GPUS:NVIDIA=!" == "x!GPUS!" ( + SET NVIDIA_GPU_EXISTS=1 + goto gpu_check_end + ) +) +:gpu_check_end +endlocal & set NVIDIA_GPU_EXISTS=%NVIDIA_GPU_EXISTS% + +if NOT "%CUDA_PREFIX%" == "cpu" if "%NVIDIA_GPU_EXISTS%" == "1" ( + echo Checking that CUDA archs are setup correctly + python -c "import torch; torch.randn([3,5]).cuda()" + if ERRORLEVEL 1 exit /b 1 + + echo Checking that magma is available + python -c "import torch; torch.rand(1).cuda(); exit(0 if torch.cuda.has_magma else 1)" + if ERRORLEVEL 1 exit /b 1 + + echo Checking that CuDNN is available + python -c "import torch; exit(0 if torch.backends.cudnn.is_available() else 1)" + if ERRORLEVEL 1 exit /b 1 +) +:smoke_test_end + +echo Not running unit tests. Hopefully these problems are caught by CI +goto test_end + +if "%BUILD_VISION%" == "" ( + cd pytorch\test + python run_test.py -v +) else ( + cd vision + pytest . +) + +if ERRORLEVEL 1 exit /b 1 + +:test_end + +popd +exit /b 0 diff --git a/packaging/windows/internal/vs_install.bat b/packaging/windows/internal/vs_install.bat new file mode 100644 index 00000000000..624227f0be0 --- /dev/null +++ b/packaging/windows/internal/vs_install.bat @@ -0,0 +1,28 @@ +@echo off + +set VS_DOWNLOAD_LINK=https://aka.ms/vs/15/release/vs_buildtools.exe +IF "%VS_LATEST%" == "1" ( + set VS_INSTALL_ARGS= --nocache --norestart --quiet --wait --add Microsoft.VisualStudio.Workload.VCTools + set VSDEVCMD_ARGS= +) ELSE ( + set VS_INSTALL_ARGS=--nocache --quiet --wait --add Microsoft.VisualStudio.Workload.VCTools ^ + --add Microsoft.VisualStudio.Component.VC.Tools.14.11 ^ + --add Microsoft.Component.MSBuild ^ + --add Microsoft.VisualStudio.Component.Roslyn.Compiler ^ + --add Microsoft.VisualStudio.Component.TextTemplating ^ + --add Microsoft.VisualStudio.Component.VC.CoreIde ^ + --add Microsoft.VisualStudio.Component.VC.Redist.14.Latest ^ + --add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core ^ + --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ^ + --add Microsoft.VisualStudio.Component.VC.Tools.14.11 ^ + --add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81 + set VSDEVCMD_ARGS=-vcvars_ver=14.11 +) + +curl -k -L %VS_DOWNLOAD_LINK% --output vs_installer.exe +if errorlevel 1 exit /b 1 + +start /wait .\vs_installer.exe %VS_INSTALL_ARGS% +if not errorlevel 0 exit /b 1 +if errorlevel 1 if not errorlevel 3010 exit /b 1 +if errorlevel 3011 exit /b 1