|
| 1 | +@echo off |
| 2 | + |
| 3 | +:: This script parses args, installs required libraries (miniconda, MKL, |
| 4 | +:: Magma), and then delegates to cpu.bat, cuda80.bat, etc. |
| 5 | + |
| 6 | +if not "%CUDA_VERSION%" == "" if not "%PYTORCH_BUILD_VERSION%" == "" if not "%PYTORCH_BUILD_NUMBER%" == "" goto env_end |
| 7 | +if "%~1"=="" goto arg_error |
| 8 | +if "%~2"=="" goto arg_error |
| 9 | +if "%~3"=="" goto arg_error |
| 10 | +if not "%~4"=="" goto arg_error |
| 11 | +goto arg_end |
| 12 | + |
| 13 | +:arg_error |
| 14 | + |
| 15 | +echo Illegal number of parameters. Pass cuda version, pytorch version, build number |
| 16 | +echo CUDA version should be Mm with no dot, e.g. '80' |
| 17 | +echo DESIRED_PYTHON should be M.m, e.g. '2.7' |
| 18 | +exit /b 1 |
| 19 | + |
| 20 | +:arg_end |
| 21 | + |
| 22 | +set CUDA_VERSION=%~1 |
| 23 | +set PYTORCH_BUILD_VERSION=%~2 |
| 24 | +set PYTORCH_BUILD_NUMBER=%~3 |
| 25 | + |
| 26 | +:env_end |
| 27 | + |
| 28 | +set CUDA_PREFIX=cuda%CUDA_VERSION% |
| 29 | +if "%CUDA_VERSION%" == "cpu" set CUDA_PREFIX=cpu |
| 30 | +if "%CUDA_VERSION%" == "xpu" set CUDA_PREFIX=xpu |
| 31 | + |
| 32 | +if "%DESIRED_PYTHON%" == "" set DESIRED_PYTHON=3.5;3.6;3.7 |
| 33 | +set DESIRED_PYTHON_PREFIX=%DESIRED_PYTHON:.=% |
| 34 | +set DESIRED_PYTHON_PREFIX=py%DESIRED_PYTHON_PREFIX:;=;py% |
| 35 | + |
| 36 | +set SRC_DIR=%~dp0 |
| 37 | +pushd %SRC_DIR% |
| 38 | + |
| 39 | +:: Install Miniconda3 |
| 40 | +set "CONDA_HOME=%CD%\conda" |
| 41 | +set "tmp_conda=%CONDA_HOME%" |
| 42 | +set "miniconda_exe=%CD%\miniconda.exe" |
| 43 | +rmdir /s /q conda |
| 44 | +del miniconda.exe |
| 45 | +curl --retry 3 -k https://repo.anaconda.com/miniconda/Miniconda3-py311_23.9.0-0-Windows-x86_64.exe -o "%miniconda_exe%" |
| 46 | +start /wait "" "%miniconda_exe%" /S /InstallationType=JustMe /RegisterPython=0 /AddToPath=0 /D=%tmp_conda% |
| 47 | +if ERRORLEVEL 1 exit /b 1 |
| 48 | +set "ORIG_PATH=%PATH%" |
| 49 | +set "PATH=%CONDA_HOME%;%CONDA_HOME%\scripts;%CONDA_HOME%\Library\bin;%PATH%" |
| 50 | + |
| 51 | +:: create a new conda environment and install packages |
| 52 | +:try |
| 53 | +SET /A tries=3 |
| 54 | +:loop |
| 55 | +IF %tries% LEQ 0 GOTO :exception |
| 56 | +call condaenv.bat |
| 57 | +IF %ERRORLEVEL% EQU 0 GOTO :done |
| 58 | +SET /A "tries=%tries%-1" |
| 59 | +:exception |
| 60 | +echo "Failed to create conda env" |
| 61 | +exit /B 1 |
| 62 | +:done |
| 63 | + |
| 64 | +:: Download MAGMA Files on CUDA builds |
| 65 | +set MAGMA_VERSION=2.5.4 |
| 66 | + |
| 67 | +if "%DEBUG%" == "1" ( |
| 68 | + set BUILD_TYPE=debug |
| 69 | +) else ( |
| 70 | + set BUILD_TYPE=release |
| 71 | +) |
| 72 | + |
| 73 | +if not "%CUDA_VERSION%" == "cpu" if not "%CUDA_VERSION%" == "xpu" ( |
| 74 | + rmdir /s /q magma_%CUDA_PREFIX%_%BUILD_TYPE% |
| 75 | + del magma_%CUDA_PREFIX%_%BUILD_TYPE%.7z |
| 76 | + curl -k https://s3.amazonaws.com/ossci-windows/magma_%MAGMA_VERSION%_%CUDA_PREFIX%_%BUILD_TYPE%.7z -o magma_%CUDA_PREFIX%_%BUILD_TYPE%.7z |
| 77 | + 7z x -aoa magma_%CUDA_PREFIX%_%BUILD_TYPE%.7z -omagma_%CUDA_PREFIX%_%BUILD_TYPE% |
| 78 | +) |
| 79 | + |
| 80 | +:: Install sccache |
| 81 | +if "%USE_SCCACHE%" == "1" ( |
| 82 | + mkdir %CD%\tmp_bin |
| 83 | + curl -k https://s3.amazonaws.com/ossci-windows/sccache.exe --output %CD%\tmp_bin\sccache.exe |
| 84 | + curl -k https://s3.amazonaws.com/ossci-windows/sccache-cl.exe --output %CD%\tmp_bin\sccache-cl.exe |
| 85 | + if not "%CUDA_VERSION%" == "" ( |
| 86 | + set ADDITIONAL_PATH=%CD%\tmp_bin |
| 87 | + set SCCACHE_IDLE_TIMEOUT=1500 |
| 88 | + |
| 89 | + :: randomtemp is used to resolve the intermittent build error related to CUDA. |
| 90 | + :: code: https://github.com/peterjc123/randomtemp-rust |
| 91 | + :: issue: https://github.com/pytorch/pytorch/issues/25393 |
| 92 | + :: |
| 93 | + :: CMake requires a single command as CUDA_NVCC_EXECUTABLE, so we push the wrappers |
| 94 | + :: randomtemp.exe and sccache.exe into a batch file which CMake invokes. |
| 95 | + curl -kL https://github.com/peterjc123/randomtemp-rust/releases/download/v0.4/randomtemp.exe --output %SRC_DIR%\tmp_bin\randomtemp.exe |
| 96 | + echo @"%SRC_DIR%\tmp_bin\randomtemp.exe" "%SRC_DIR%\tmp_bin\sccache.exe" "%CUDA_PATH%\bin\nvcc.exe" %%* > "%SRC_DIR%/tmp_bin/nvcc.bat" |
| 97 | + cat %SRC_DIR%/tmp_bin/nvcc.bat |
| 98 | + set CUDA_NVCC_EXECUTABLE=%SRC_DIR%/tmp_bin/nvcc.bat |
| 99 | + :: CMake doesn't accept back-slashes in the path |
| 100 | + for /F "usebackq delims=" %%n in (`cygpath -m "%CUDA_PATH%\bin\nvcc.exe"`) do set CMAKE_CUDA_COMPILER=%%n |
| 101 | + set CMAKE_CUDA_COMPILER_LAUNCHER=%SRC_DIR%\tmp_bin\randomtemp.exe;%SRC_DIR%\tmp_bin\sccache.exe |
| 102 | + ) |
| 103 | +) |
| 104 | + |
| 105 | +set PYTORCH_BINARY_BUILD=1 |
| 106 | +set TH_BINARY_BUILD=1 |
| 107 | +set INSTALL_TEST=0 |
| 108 | + |
| 109 | +for %%v in (%DESIRED_PYTHON_PREFIX%) do ( |
| 110 | + :: Activate Python Environment |
| 111 | + set PYTHON_PREFIX=%%v |
| 112 | + set "CONDA_LIB_PATH=%CONDA_HOME%\envs\%%v\Library\bin" |
| 113 | + if not "%ADDITIONAL_PATH%" == "" ( |
| 114 | + set "PATH=%ADDITIONAL_PATH%;%CONDA_HOME%\envs\%%v;%CONDA_HOME%\envs\%%v\scripts;%CONDA_HOME%\envs\%%v\Library\bin;%ORIG_PATH%" |
| 115 | + ) else ( |
| 116 | + set "PATH=%CONDA_HOME%\envs\%%v;%CONDA_HOME%\envs\%%v\scripts;%CONDA_HOME%\envs\%%v\Library\bin;%ORIG_PATH%" |
| 117 | + ) |
| 118 | + pip install ninja |
| 119 | + @setlocal |
| 120 | + :: Set Flags |
| 121 | + if not "%CUDA_VERSION%"=="cpu" if not "%CUDA_VERSION%" == "xpu" ( |
| 122 | + set MAGMA_HOME=%cd%\magma_%CUDA_PREFIX%_%BUILD_TYPE% |
| 123 | + ) |
| 124 | + echo "Calling arch build script" |
| 125 | + call %CUDA_PREFIX%.bat |
| 126 | + if ERRORLEVEL 1 exit /b 1 |
| 127 | + @endlocal |
| 128 | +) |
| 129 | + |
| 130 | +set "PATH=%ORIG_PATH%" |
| 131 | +popd |
| 132 | + |
| 133 | +if ERRORLEVEL 1 exit /b 1 |
0 commit comments