forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_pytorch_libs.bat
executable file
·250 lines (216 loc) · 7.82 KB
/
build_pytorch_libs.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
:: @echo off
cd "%~dp0\.."
set PATH=%INSTALL_DIR%\bin;%PATH%
: The following environment variables are used exclusively by cmake and should have forward slashes rather than backslashes
set BASE_DIR=%cd:\=/%
set TORCH_LIB_DIR=%cd:\=/%/torch/lib
set INSTALL_DIR=%cd:\=/%/torch/lib/tmp_install
set THIRD_PARTY_DIR=%cd:\=/%/third_party
set BASIC_C_FLAGS= /I%INSTALL_DIR%/include /I%INSTALL_DIR%/include/TH /I%INSTALL_DIR%/include/THC /I%INSTALL_DIR%/include/THS /I%INSTALLDIR%/include/THCS /I%INSTALLDIR%/include/THPP /I%INSTALLDIR%/include/THNN /I%INSTALLDIR%/include/THCUNN
set BASIC_CUDA_FLAGS= -I%INSTALL_DIR%/include -I%INSTALL_DIR%/include/TH -I%INSTALL_DIR%/include/THC -I%INSTALL_DIR%/include/THS -I%INSTALLDIR%/include/THCS -I%INSTALLDIR%/include/THPP -I%INSTALLDIR%/include/THNN -I%INSTALLDIR%/include/THCUNN
set LDFLAGS=/LIBPATH:%INSTALL_DIR%/lib
:: set TORCH_CUDA_ARCH_LIST=6.1
set CWRAP_FILES=%BASE_DIR%/torch/lib/ATen/Declarations.cwrap;%BASE_DIR%/torch/lib/ATen/Local.cwrap;%BASE_DIR%/torch/lib/THNN/generic/THNN.h;%BASE_DIR%/torch/lib/THCUNN/generic/THCUNN.h;%BASE_DIR%/torch/lib/ATen/nn.yaml
set C_FLAGS=%BASIC_C_FLAGS% /D_WIN32 /Z7 /EHa /DNOMINMAX
set LINK_FLAGS=/DEBUG:FULL
: End cmake variables
if not exist torch\lib\tmp_install mkdir torch\lib\tmp_install
: Variable defaults
set /a USE_CUDA=0
set /a USE_ROCM=0
set /a USE_NNPACK=0
set /a USE_QNNPACK=0
set /a USE_GLOO_IBVERBS=0
set /a USE_MKLDNN=0
set /a NO_NNPACK=1
set _BUILD_ARGS=
: Process command line arguments
:process_args
if "%1"=="" (
goto :process_args_exit
)
if "%1"=="--use-cuda" (
set /a USE_CUDA=1
goto :process_args_processed
)
if "%1"=="--use-rocm" (
set /a USE_ROCM=1
goto :process_args_processed
)
if "%1"=="--use-nnpack" (
set /a USE_NNPACK=1
set /a NO_NNPACK=0
goto :process_args_processed
)
if "%1"=="--use-qnnpack" (
set /a USE_QNNPACK=1
goto :process_args_processed
)
if "%1"=="--use-mkldnn" (
set /a USE_MKLDNN=1
goto :process_args_processed
)
if "%1"=="--use-gloo-ibverbs" (
echo Warning: gloo iverbs is enabled but build is not yet implemented 1>&2
set /a USE_GLOO_IBVERBS=1
goto :process_args_processed
)
set _BUILD_ARGS=%_BUILD_ARGS% %1
:: Fall-through intended
:process_args_processed
shift
goto :process_args
:process_args_exit
: Set vars based on environment state
set BUILD_TYPE=Release
IF "%DEBUG%"=="1" (
set BUILD_TYPE=Debug
)
IF "%REL_WITH_DEB_INFO%"=="1" (
set BUILD_TYPE=RelWithDebInfo
)
:: sccache will fail if all cores are used for compiling
IF NOT DEFINED MAX_JOBS (
set /a MAX_JOBS=%NUMBER_OF_PROCESSORS% - 1
)
IF NOT DEFINED BUILD_SHARED_LIBS (
set BUILD_SHARED_LIBS=ON
)
IF "%CMAKE_GENERATOR%"=="" (
set CMAKE_GENERATOR_COMMAND=
set MAKE_COMMAND=msbuild INSTALL.vcxproj /p:Configuration=Release
) ELSE (
set CMAKE_GENERATOR_COMMAND=-G "%CMAKE_GENERATOR%"
IF "%CMAKE_GENERATOR%"=="Ninja" (
IF "%CC%"== "" set CC=cl.exe
IF "%CXX%"== "" set CXX=cl.exe
set MAKE_COMMAND=cmake --build . --target install --config %BUILD_TYPE% -- -j%MAX_JOBS%
) ELSE (
set MAKE_COMMAND=msbuild INSTALL.vcxproj /p:Configuration=%BUILD_TYPE%
)
)
: Invoke functionality for each build requested
FOR %%a IN (%_BUILD_ARGS%) DO (
echo --------------------------------------------------------------------------------
echo ^|
echo ^| Building %%a
echo ^|
echo --------------------------------------------------------------------------------
IF "%%a"=="caffe2" (
call:build_caffe2 %%a
) ELSE (
IF "%%a"=="libshm_windows" (
SET IS_OURS=1
pushd torch\lib
call:build %%a
popd
) ELSE (
pushd third_party
call:build %%a
popd
)
)
)
: Copy Artifacts
cd torch\lib
copy /Y tmp_install\lib\* .
IF EXIST ".\tmp_install\bin" (
copy /Y tmp_install\bin\* .
)
xcopy /Y /E tmp_install\include\*.* include\*.*
xcopy /Y ..\..\aten\src\THNN\generic\THNN.h .
xcopy /Y ..\..\aten\src\THCUNN\generic\THCUNN.h .
cd ..\..
goto:eof
: Generate Build Functionality
:build
@setlocal
IF NOT "%PREBUILD_COMMAND%"=="" call "%PREBUILD_COMMAND%" %PREBUILD_COMMAND_ARGS%
if not exist build mkdir build\%~1
pushd build\%~1
cmake ../../%~1 %CMAKE_GENERATOR_COMMAND% ^
-DCMAKE_MODULE_PATH=%BASE_DIR%/cmake/FindCUDA ^
-DTorch_FOUND="1" ^
-DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%" ^
-DCMAKE_C_FLAGS="%C_FLAGS%" ^
-DCMAKE_SHARED_LINKER_FLAGS="%LINK_FLAGS%" ^
-DCMAKE_CXX_FLAGS="%C_FLAGS% %CPP_FLAGS%" ^
-DCUDA_NVCC_FLAGS="%BASIC_CUDA_FLAGS%" ^
-Dcwrap_files="%CWRAP_FILES%" ^
-DTH_INCLUDE_PATH="%INSTALL_DIR%/include" ^
-DTH_LIB_PATH="%INSTALL_DIR%/lib" ^
-DTH_LIBRARIES="%INSTALL_DIR%/lib/caffe2.lib" ^
-DTHS_LIBRARIES="%INSTALL_DIR%/lib/caffe2.lib" ^
-DTHC_LIBRARIES="%INSTALL_DIR%/lib/caffe2_gpu.lib" ^
-DTHCS_LIBRARIES="%INSTALL_DIR%/lib/caffe2_gpu.lib" ^
-DC10_LIBRARIES="%INSTALL_DIR%/lib/c10.lib" ^
-DCAFFE2_LIBRARIES="%INSTALL_DIR%/lib/caffe2.lib" ^
-DTHNN_LIBRARIES="%INSTALL_DIR%/lib/caffe2.lib" ^
-DTHCUNN_LIBRARIES="%INSTALL_DIR%/lib/caffe2_gpu.lib" ^
-DTH_SO_VERSION=1 ^
-DTHC_SO_VERSION=1 ^
-DTHNN_SO_VERSION=1 ^
-DTHCUNN_SO_VERSION=1 ^
-DUSE_CUDA=%USE_CUDA% ^
-DBUILD_EXAMPLES=OFF ^
-DBUILD_TEST=%BUILD_TEST% ^
-DNO_NNPACK=%NO_NNPACK% ^
-DCMAKE_BUILD_TYPE=%BUILD_TYPE%
IF ERRORLEVEL 1 exit 1
IF NOT ERRORLEVEL 0 exit 1
%MAKE_COMMAND%
IF ERRORLEVEL 1 exit 1
IF NOT ERRORLEVEL 0 exit 1
popd
@endlocal
goto:eof
: libtorch-specific build functionality
:build_caffe2
@setlocal
IF NOT "%PREBUILD_COMMAND%"=="" call "%PREBUILD_COMMAND%" %PREBUILD_COMMAND_ARGS%
if not exist build mkdir build
pushd build
cmake .. %CMAKE_GENERATOR_COMMAND% ^
-DCMAKE_BUILD_TYPE=%BUILD_TYPE% ^
-DTORCH_BUILD_VERSION="%PYTORCH_BUILD_VERSION%" ^
-DBUILD_TORCH="%BUILD_TORCH%" ^
-DNVTOOLEXT_HOME="%NVTOOLEXT_HOME%" ^
-DNO_API=ON ^
-DBUILD_SHARED_LIBS="%BUILD_SHARED_LIBS%" ^
-DBUILD_PYTHON=%BUILD_PYTHON% ^
-DBUILD_BINARY=%BUILD_BINARY% ^
-DBUILD_TEST=%BUILD_TEST% ^
-DINSTALL_TEST=%INSTALL_TEST% ^
-DBUILD_CAFFE2_OPS=%BUILD_CAFFE2_OPS% ^
-DONNX_NAMESPACE=%ONNX_NAMESPACE% ^
-DUSE_CUDA=%USE_CUDA% ^
-DUSE_DISTRIBUTED=%USE_DISTRIBUTED% ^
-DUSE_NUMPY=%USE_NUMPY% ^
-DUSE_NNPACK=%USE_NNPACK% ^
-DUSE_LEVELDB=%USE_LEVELDB% ^
-DUSE_LMDB=%USE_LMDB% ^
-DUSE_OPENCV=%USE_OPENCV% ^
-DUSE_QNNPACK=%USE_QNNPACK% ^
-DUSE_FFMPEG=%USE_FFMPEG% ^
-DUSE_GLOG=OFF ^
-DUSE_GFLAGS=OFF ^
-DUSE_SYSTEM_EIGEN_INSTALL=OFF ^
-DCUDNN_INCLUDE_DIR="%CUDNN_INCLUDE_DIR%" ^
-DCUDNN_LIB_DIR="%CUDNN_LIB_DIR%" ^
-DCUDNN_LIBRARY="%CUDNN_LIBRARY%" ^
-DUSE_MKLDNN=%USE_MKLDNN% ^
-DATEN_NO_CONTRIB=1 ^
-DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%" ^
-DCMAKE_C_FLAGS="%USER_CFLAGS%" ^
-DCMAKE_CXX_FLAGS="/EHa %USER_CFLAGS%" ^
-DCMAKE_EXE_LINKER_FLAGS="%USER_LDFLAGS%" ^
-DCMAKE_SHARED_LINKER_FLAGS="%USER_LDFLAGS%" ^
-DUSE_ROCM=%USE_ROCM%
IF ERRORLEVEL 1 exit 1
IF NOT ERRORLEVEL 0 exit 1
%MAKE_COMMAND%
IF ERRORLEVEL 1 exit 1
IF NOT ERRORLEVEL 0 exit 1
popd
@endlocal
goto:eof