1
1
#! /bin/bash
2
2
3
- echo " === Building ${PKG_NAME} (py: ${PY_VER} ) ==="
4
-
5
3
set -ex
6
4
5
+ echo " #########################################################################"
6
+ echo " Building ${PKG_NAME} (py: ${PY_VER} ) using BLAS implementation $blas_impl "
7
+ echo " #########################################################################"
8
+
7
9
# This is used to detect if it's in the process of building pytorch
8
10
export IN_PYTORCH_BUILD=1
9
11
@@ -20,9 +22,22 @@ rm -rf pyproject.toml
20
22
export USE_CUFILE=0
21
23
export USE_NUMA=0
22
24
export USE_ITT=0
25
+
26
+ # ################### ADJUST COMPILER AND LINKER FLAGS #####################
27
+ # Pytorch's build system doesn't like us setting the c++ standard through CMAKE_CXX_FLAGS
28
+ # and will issue a warning. We need to use at least C++17 to match the abseil ABI, see
29
+ # https://github.com/conda-forge/abseil-cpp-feedstock/issues/45, which pytorch 2.5 uses already:
30
+ # https://github.com/pytorch/pytorch/blob/v2.5.1/CMakeLists.txt#L36-L48
31
+ export CXXFLAGS=" $( echo $CXXFLAGS | sed ' s/-std=c++[0-9][0-9]//g' ) "
32
+ # The below three lines expose symbols that would otherwise be hidden or
33
+ # optimised away. They were here before, so removing them would potentially
34
+ # break users' programs
23
35
export CFLAGS=" $( echo $CFLAGS | sed ' s/-fvisibility-inlines-hidden//g' ) "
24
36
export CXXFLAGS=" $( echo $CXXFLAGS | sed ' s/-fvisibility-inlines-hidden//g' ) "
25
37
export LDFLAGS=" $( echo $LDFLAGS | sed ' s/-Wl,--as-needed//g' ) "
38
+ # The default conda LDFLAGs include -Wl,-dead_strip_dylibs, which removes all the
39
+ # MKL sequential, core, etc. libraries, resulting in a "Symbol not found: _mkl_blas_caxpy"
40
+ # error on osx-64.
26
41
export LDFLAGS=" $( echo $LDFLAGS | sed ' s/-Wl,-dead_strip_dylibs//g' ) "
27
42
export LDFLAGS_LD=" $( echo $LDFLAGS_LD | sed ' s/-dead_strip_dylibs//g' ) "
28
43
if [[ " $c_compiler " == " clang" ]]; then
45
60
# can be imported on system without a GPU
46
61
LDFLAGS=" ${LDFLAGS// -Wl,-z,now/ -Wl,-z,lazy} "
47
62
63
+ # ############### CONFIGURE CMAKE FOR CONDA ENVIRONMENT ###################
48
64
export CMAKE_GENERATOR=Ninja
49
65
export CMAKE_LIBRARY_PATH=$PREFIX /lib:$PREFIX /include:$CMAKE_LIBRARY_PATH
50
66
export CMAKE_PREFIX_PATH=$PREFIX
@@ -73,6 +89,8 @@ export USE_SYSTEM_SLEEF=1
73
89
# use our protobuf
74
90
export BUILD_CUSTOM_PROTOBUF=OFF
75
91
rm -rf $PREFIX /bin/protoc
92
+ export USE_SYSTEM_PYBIND11=1
93
+ export USE_SYSTEM_EIGEN_INSTALL=1
76
94
77
95
# prevent six from being downloaded
78
96
> third_party/NNPACK/cmake/DownloadSix.cmake
@@ -98,18 +116,29 @@ if [[ "${CI}" == "github_actions" ]]; then
98
116
# reduce parallelism to avoid getting OOM-killed on
99
117
# cirun-openstack-gpu-2xlarge, which has 32GB RAM, 8 CPUs
100
118
export MAX_JOBS=4
101
- else
119
+ elif [[ " ${CI} " == " azure " ]] ; then
102
120
export MAX_JOBS=${CPU_COUNT}
103
- fi
104
-
105
- if [[ " $blas_impl " == " generic" ]]; then
106
- # Fake openblas
107
- export BLAS=OpenBLAS
108
- export OpenBLAS_HOME=${PREFIX}
109
121
else
110
- export BLAS=MKL
122
+ # Leave a spare core for other tasks, per common practice.
123
+ # Reducing further can help with out-of-memory errors.
124
+ export MAX_JOBS=$(( CPU_COUNT > 1 ? CPU_COUNT - 1 : 1 ))
111
125
fi
112
126
127
+ case " $blas_impl " in
128
+ " generic" )
129
+ # Fake openblas
130
+ export BLAS=OpenBLAS
131
+ export OpenBLAS_HOME=${PREFIX}
132
+ ;;
133
+ " mkl" )
134
+ export BLAS=MKL
135
+ ;;
136
+ * )
137
+ echo " [ERROR] Unsupported BLAS implementation '${blas_impl} '" >&2
138
+ exit 1
139
+ ;;
140
+ esac
141
+
113
142
if [[ " $PKG_NAME " == " pytorch" ]]; then
114
143
# Trick Cmake into thinking python hasn't changed
115
144
sed " s/3\.12/$PY_VER /g" build/CMakeCache.txt.orig > build/CMakeCache.txt
@@ -163,12 +192,24 @@ elif [[ ${cuda_compiler_version} != "None" ]]; then
163
192
echo " unknown CUDA arch, edit build.sh"
164
193
exit 1
165
194
esac
195
+
196
+ # Compatibility matrix for update: https://en.wikipedia.org/wiki/CUDA#GPUs_supported
197
+ # Warning from pytorch v1.12.1: In the future we will require one to
198
+ # explicitly pass TORCH_CUDA_ARCH_LIST to cmake instead of implicitly
199
+ # setting it as an env variable.
200
+ # Doing this is nontrivial given that we're using setup.py as an entry point, but should
201
+ # be addressed to pre-empt upstream changing it, as it probably won't result in a failed
202
+ # configuration.
203
+ #
204
+ # See:
205
+ # https://pytorch.org/docs/stable/cpp_extension.html (Compute capabilities)
206
+ # https://github.com/pytorch/pytorch/blob/main/.ci/manywheel/build_cuda.sh
166
207
case ${cuda_compiler_version} in
167
- 12.6 )
208
+ 12.[0-6] )
168
209
export TORCH_CUDA_ARCH_LIST=" 5.0;6.0;6.1;7.0;7.5;8.0;8.6;8.9;9.0+PTX"
169
210
;;
170
211
* )
171
- echo " unsupported cuda version. edit build.sh"
212
+ echo " No CUDA architecture list exists for CUDA v ${cuda_compiler_version} . See build.sh for information on adding one. "
172
213
exit 1
173
214
esac
174
215
export TORCH_NVCC_FLAGS=" -Xfatbin -compress-all"
@@ -203,15 +244,16 @@ case ${PKG_NAME} in
203
244
204
245
mv build/lib.* /torch/bin/* ${PREFIX} /bin/
205
246
mv build/lib.* /torch/lib/* ${PREFIX} /lib/
206
- mv build/lib.* /torch/share/* ${PREFIX} /share/
247
+ # need to merge these now because we're using system pybind11, meaning the destination directory is not empty
248
+ rsync -a build/lib.* /torch/share/* ${PREFIX} /share/
207
249
mv build/lib.* /torch/include/{ATen,caffe2,tensorpipe,torch,c10} ${PREFIX} /include/
208
250
rm ${PREFIX} /lib/libtorch_python.*
209
251
210
252
# Keep the original backed up to sed later
211
253
cp build/CMakeCache.txt build/CMakeCache.txt.orig
212
254
;;
213
255
pytorch)
214
- $PREFIX /bin/python -m pip install . --no-deps -vvv --no-clean \
256
+ $PREFIX /bin/python -m pip install . --no-deps --no-build-isolation - vvv --no-clean \
215
257
| sed " s,${CXX} ,\$ \{CXX\},g" \
216
258
| sed " s,${PREFIX} ,\$ \{PREFIX\},g"
217
259
# Keep this in ${PREFIX}/lib so that the library can be found by
0 commit comments