Skip to content

Commit c99463a

Browse files
authored
Merge pull request pytorch#105 from pjh5/windows_bats
Initial windows scripts from peterjc123
2 parents 1023c9e + 6023a84 commit c99463a

File tree

13 files changed

+471
-0
lines changed

13 files changed

+471
-0
lines changed

windows/build_all.bat

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
@echo off
2+
3+
set "CONDA_HOME=c:\ProgramData\miniconda3"
4+
set "PATH=%CONDA_HOME%;%CONDA_HOME%\scripts;%CONDA_HOME%\Library\bin;%PATH%"
5+
set "ORIG_PATH=%PATH%"
6+
7+
conda remove -n py35 --all -y || rmdir %CONDA_HOME%\envs\py35 /s
8+
conda remove -n py36 --all -y || rmdir %CONDA_HOME%\envs\py36 /s
9+
conda remove -n py37 --all -y || rmdir %CONDA_HOME%\envs\py37 /s
10+
11+
conda create -n py35 -y -q numpy=1.11 mkl=2018 cffi pyyaml boto3 cmake ninja typing python=3.5
12+
conda create -n py36 -y -q numpy=1.11 mkl=2018 cffi pyyaml boto3 cmake ninja typing python=3.6
13+
conda create -n py37 -y -q numpy=1.11 mkl=2018 cffi pyyaml boto3 cmake ninja typing python=3.7
14+
15+
REM Install MKL
16+
rmdir /s /q mkl
17+
del mkl_2018.2.185.7z
18+
curl https://s3.amazonaws.com/ossci-windows/mkl_2018.2.185.7z -k -O
19+
7z x -aoa mkl_2018.2.185.7z -omkl
20+
set CMAKE_INCLUDE_PATH=%cd%\\mkl\\include
21+
set LIB=%cd%\\mkl\\lib;%LIB%
22+
23+
REM Download MAGMA Files
24+
for %%p in (
25+
cuda80
26+
cuda90
27+
cuda92
28+
) do (
29+
rmdir /s /q magma_%%p_release
30+
del magma_%%p_release.7z
31+
curl -k https://s3.amazonaws.com/ossci-windows/magma_%%p_release_mkl_2018.2.185.7z -o magma_%%p_release.7z
32+
7z x -aoa magma_%%p_release.7z -omagma_%%p_release
33+
)
34+
35+
REM Install sccache
36+
mkdir %CD%\\tmp_bin
37+
curl -k https://s3.amazonaws.com/ossci-windows/sccache.exe --output %CD%\\tmp_bin\\sccache.exe
38+
copy %CD%\\tmp_bin\\sccache.exe %CD%\\tmp_bin\\nvcc.exe
39+
40+
set CUDA_NVCC_EXECUTABLE=%CD%\\tmp_bin\\nvcc
41+
set "PATH=%CD%\\tmp_bin;%PATH%"
42+
43+
set PYTORCH_BUILD_VERSION=0.4.1
44+
set PYTORCH_BUILD_NUMBER=1
45+
46+
set PYTORCH_BINARY_BUILD=1
47+
set TH_BINARY_BUILD=1
48+
49+
@setlocal EnableDelayedExpansion
50+
for %%v in (
51+
py35
52+
py36
53+
py37
54+
) do (
55+
REM Activate Python Environment
56+
set "CONDA_LIB_PATH=%CONDA_HOME%\envs\%%v\Library\bin"
57+
set "PATH=%CONDA_HOME%\envs\%%v;%CONDA_HOME%\envs\%%v\scripts;%CONDA_HOME%\envs\%%v\Library\bin;%ORIG_PATH%"
58+
pip install ninja
59+
for %%c in (
60+
cpu
61+
80
62+
90
63+
92
64+
) do (
65+
@setlocal
66+
67+
REM Set Flags
68+
if NOT "%%c"=="cpu" (
69+
if NOT "%%c"=="92" (
70+
set MAGMA_HOME=%cd%\\magma_!CUDA_PREFIX!_release
71+
) else (
72+
set MAGMA_HOME=%cd%\\magma_!CUDA_PREFIX!_release\magma_cuda92\magma\install
73+
)
74+
set CUDA_VERSION=%%c
75+
set CUDA_PREFIX=cuda!CUDA_VERSION!
76+
set CUDNN_VERSION=7
77+
) else (
78+
set CUDA_PREFIX=cpu
79+
)
80+
call !CUDA_PREFIX!.bat
81+
@endlocal
82+
)
83+
)
84+
85+
@endlocal
86+
87+
set "PATH=%ORIG_PATH%"

windows/cpu.bat

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@echo off
2+
3+
IF NOT EXIST "setup.py" IF NOT EXIST "pytorch" (
4+
call internal\clone.bat
5+
cd ..
6+
IF ERRORLEVEL 1 goto eof
7+
) ELSE (
8+
call internal\clean.bat
9+
)
10+
11+
call internal\check_deps.bat
12+
IF ERRORLEVEL 1 goto eof
13+
14+
REM Check for optional components
15+
16+
echo Disabling CUDA
17+
set NO_CUDA=1
18+
19+
call internal\check_opts.bat
20+
IF ERRORLEVEL 1 goto eof
21+
22+
call internal\copy_cpu.bat
23+
IF ERRORLEVEL 1 goto eof
24+
25+
call internal\setup.bat
26+
IF ERRORLEVEL 1 goto eof
27+
28+
:eof

windows/cuda80.bat

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
@echo off
2+
3+
IF NOT EXIST "setup.py" IF NOT EXIST "pytorch" (
4+
call internal\clone.bat
5+
cd ..
6+
IF ERRORLEVEL 1 goto eof
7+
) ELSE (
8+
call internal\clean.bat
9+
)
10+
11+
call internal\check_deps.bat
12+
IF ERRORLEVEL 1 goto eof
13+
14+
REM Check for optional components
15+
16+
set NO_CUDA=
17+
set CMAKE_GENERATOR=Visual Studio 15 2017 Win64
18+
19+
IF "%NVTOOLSEXT_PATH%"=="" (
20+
echo NVTX ^(Visual Studio Extension ^for CUDA^) ^not installed, disabling CUDA
21+
set NO_CUDA=1
22+
goto optcheck
23+
)
24+
25+
IF "%CUDA_PATH_V8_0%"=="" (
26+
echo CUDA 8 not found, disabling it
27+
set NO_CUDA=1
28+
) ELSE (
29+
IF "%VS140COMNTOOLS%"=="" (
30+
echo CUDA 8 found, but VS2015 not found, disabling it
31+
set NO_CUDA=1
32+
) ELSE (
33+
set TORCH_CUDA_ARCH_LIST=3.5;5.0+PTX;6.0;6.1
34+
set TORCH_NVCC_FLAGS=-Xfatbin -compress-all
35+
36+
set "CUDA_PATH=%CUDA_PATH_V8_0%"
37+
set "PATH=%CUDA_PATH_V8_0%\bin;%PATH%"
38+
set CMAKE_GENERATOR=Visual Studio 14 2015 Win64
39+
set "PREBUILD_COMMAND=%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat"
40+
set PREBUILD_COMMAND_ARGS=x86_amd64
41+
)
42+
)
43+
44+
:optcheck
45+
46+
call internal\check_opts.bat
47+
IF ERRORLEVEL 1 goto eof
48+
49+
call internal\copy.bat
50+
IF ERRORLEVEL 1 goto eof
51+
52+
call internal\setup.bat
53+
IF ERRORLEVEL 1 goto eof
54+
55+
:eof

windows/cuda90.bat

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
@echo off
2+
3+
IF NOT EXIST "setup.py" IF NOT EXIST "pytorch" (
4+
call internal\clone.bat
5+
cd ..
6+
IF ERRORLEVEL 1 goto eof
7+
) ELSE (
8+
call internal\clean.bat
9+
)
10+
11+
call internal\check_deps.bat
12+
IF ERRORLEVEL 1 goto eof
13+
14+
REM Check for optional components
15+
16+
set NO_CUDA=
17+
set CMAKE_GENERATOR=Visual Studio 15 2017 Win64
18+
19+
IF "%NVTOOLSEXT_PATH%"=="" (
20+
echo NVTX ^(Visual Studio Extension ^for CUDA^) ^not installed, disabling CUDA
21+
set NO_CUDA=1
22+
goto optcheck
23+
)
24+
25+
IF "%CUDA_PATH_V9_0%"=="" (
26+
echo CUDA 9 not found, disabling it
27+
set NO_CUDA=1
28+
) ELSE (
29+
set TORCH_CUDA_ARCH_LIST=3.5;5.0+PTX;6.0;6.1;7.0
30+
set TORCH_NVCC_FLAGS=-Xfatbin -compress-all
31+
32+
set "CUDA_PATH=%CUDA_PATH_V9_0%"
33+
set "PATH=%CUDA_PATH_V9_0%\bin;%PATH%"
34+
)
35+
36+
:optcheck
37+
38+
call internal\check_opts.bat
39+
IF ERRORLEVEL 1 goto eof
40+
41+
call internal\copy.bat
42+
IF ERRORLEVEL 1 goto eof
43+
44+
call internal\setup.bat
45+
IF ERRORLEVEL 1 goto eof
46+
47+
:eof

windows/cuda91.bat

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
@echo off
2+
3+
IF NOT EXIST "setup.py" IF NOT EXIST "pytorch" (
4+
call internal\clone.bat
5+
cd ..
6+
IF ERRORLEVEL 1 goto eof
7+
) ELSE (
8+
call internal\clean.bat
9+
)
10+
11+
call internal\check_deps.bat
12+
IF ERRORLEVEL 1 goto eof
13+
14+
REM Check for optional components
15+
16+
set NO_CUDA=
17+
set CMAKE_GENERATOR=Visual Studio 15 2017 Win64
18+
19+
IF "%NVTOOLSEXT_PATH%"=="" (
20+
echo NVTX ^(Visual Studio Extension ^for CUDA^) ^not installed, disabling CUDA
21+
set NO_CUDA=1
22+
goto optcheck
23+
)
24+
25+
IF "%CUDA_PATH_V9_1%"=="" (
26+
echo CUDA 9.1 not found, disabling it
27+
set NO_CUDA=1
28+
) ELSE (
29+
set TORCH_CUDA_ARCH_LIST=3.5;5.0+PTX;6.0;6.1;7.0
30+
set TORCH_NVCC_FLAGS=-Xfatbin -compress-all
31+
32+
set "CUDA_PATH=%CUDA_PATH_V9_1%"
33+
set "PATH=%CUDA_PATH_V9_1%\bin;%PATH%"
34+
)
35+
36+
:optcheck
37+
38+
call internal\check_opts.bat
39+
IF ERRORLEVEL 1 goto eof
40+
41+
call internal\copy.bat
42+
IF ERRORLEVEL 1 goto eof
43+
44+
call internal\setup.bat
45+
IF ERRORLEVEL 1 goto eof
46+
47+
:eof

windows/cuda92.bat

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
@echo off
2+
3+
IF NOT EXIST "setup.py" IF NOT EXIST "pytorch" (
4+
call internal\clone.bat
5+
cd ..
6+
IF ERRORLEVEL 1 goto eof
7+
) ELSE (
8+
call internal\clean.bat
9+
)
10+
11+
call internal\check_deps.bat
12+
IF ERRORLEVEL 1 goto eof
13+
14+
REM Check for optional components
15+
16+
set NO_CUDA=
17+
set CMAKE_GENERATOR=Visual Studio 15 2017 Win64
18+
19+
IF "%NVTOOLSEXT_PATH%"=="" (
20+
echo NVTX ^(Visual Studio Extension ^for CUDA^) ^not installed, disabling CUDA
21+
set NO_CUDA=1
22+
goto optcheck
23+
)
24+
25+
IF "%CUDA_PATH_V9_2%"=="" (
26+
echo CUDA 9.2 not found, disabling it
27+
set NO_CUDA=1
28+
) ELSE (
29+
set TORCH_CUDA_ARCH_LIST=3.5;5.0+PTX;6.0;6.1;7.0
30+
set TORCH_NVCC_FLAGS=-Xfatbin -compress-all
31+
32+
set "CUDA_PATH=%CUDA_PATH_V9_2%"
33+
set "PATH=%CUDA_PATH_V9_2%\bin;%PATH%"
34+
)
35+
36+
:optcheck
37+
38+
call internal\check_opts.bat
39+
IF ERRORLEVEL 1 goto eof
40+
41+
call internal\copy.bat
42+
IF ERRORLEVEL 1 goto eof
43+
44+
call internal\setup.bat
45+
IF ERRORLEVEL 1 goto eof
46+
47+
:eof

windows/internal/check_deps.bat

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
@echo off
2+
3+
REM Check for necessary components
4+
5+
IF NOT "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
6+
echo You should use 64 bits Windows to build and run PyTorch
7+
exit /b 1
8+
)
9+
10+
where /q cmake.exe
11+
12+
IF ERRORLEVEL 1 (
13+
echo CMake is required to compile PyTorch on Windows
14+
exit /b 1
15+
)
16+
17+
IF NOT EXIST "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" (
18+
echo Visual Studio 2017 C++ BuildTools is required to compile PyTorch on Windows
19+
exit /b 1
20+
)
21+
22+
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -version [15^,16^) -property installationPath`) do (
23+
if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" (
24+
set "VS15INSTALLDIR=%%i"
25+
set "VS15VCVARSALL=%%i\VC\Auxiliary\Build\vcvarsall.bat"
26+
goto vswhere
27+
)
28+
)
29+
30+
:vswhere
31+
IF "%VS15VCVARSALL%"=="" (
32+
echo Visual Studio 2017 C++ BuildTools is required to compile PyTorch on Windows
33+
exit /b 1
34+
)
35+
36+
set MSSdk=1
37+
set DISTUTILS_USE_SDK=1
38+
39+
where /q python.exe
40+
41+
IF ERRORLEVEL 1 (
42+
echo Python x64 3.5 or up is required to compile PyTorch on Windows
43+
exit /b 1
44+
)
45+
46+
for /F "usebackq delims=" %%i in (`python -c "import sys; print('{0[0]}{0[1]}'.format(sys.version_info))"`) do (
47+
set /a PYVER=%%i
48+
)
49+
50+
if %PYVER% LSS 35 (
51+
echo Warning: PyTorch for Python 2 under Windows is experimental.
52+
echo Python x64 3.5 or up is recommended to compile PyTorch on Windows
53+
echo Maybe you can create a virual environment if you have conda installed:
54+
echo ^> conda create -n test python=3.6 pyyaml mkl numpy
55+
echo ^> activate test
56+
)
57+
58+
for /F "usebackq delims=" %%i in (`python -c "import struct;print( 8 * struct.calcsize('P'))"`) do (
59+
set /a PYSIZE=%%i
60+
)
61+
62+
if %PYSIZE% NEQ 64 (
63+
echo Python x64 3.5 or up is required to compile PyTorch on Windows
64+
exit /b 1
65+
)

0 commit comments

Comments
 (0)