This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 115
/
build.sh
executable file
·360 lines (314 loc) · 9.51 KB
/
build.sh
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#!/usr/bin/env bash
# Copyright (c) 2021 CINN Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -ex
workspace=$PWD
build_dir_name=${cinn_build:-build}
build_dir=$workspace/${build_dir_name}
py_version=${py_version:-3.8}
cinn_whl_path=python/dist/cinn-0.0.0-py3-none-any.whl
#export LLVM11_DIR=${workspace}/THIRDS/usr
JOBS=8
cuda_config=OFF
cudnn_config=OFF
mklcblas_config=ON
mkldnn_config=ON
function mklcblas_off {
mklcblas_config=OFF
}
function mkldnn_off {
mkldnn_config=OFF
}
function gpu_on {
cinn_whl_path=python/dist/cinn_gpu-0.0.0-py3-none-any.whl
cuda_config=ON
cudnn_config=ON
}
function test_doc {
mkdir -p $build_dir
cd $build_dir
export runtime_include_dir=$workspace/cinn/runtime/cuda
prepare_ci
cmake_
build
make_doc
}
function cudnn_off {
cudnn_config=OFF
}
set +x
OLD_HTTP_PROXY=$http_proxy &> /dev/null
OLD_HTTPS_PROXY=$https_proxy &> /dev/null
set -x
function proxy_off {
set +x
unset http_proxy &> /dev/null
unset https_proxy &> /dev/null
set -x
}
function proxy_on {
set +x
export http_proxy=$OLD_HTTP_PROXY &> /dev/null
export https_proxy=$OLD_HTTPS_PROXY &> /dev/null
set -x
}
function prepare_ci {
cd $workspace
proxy_on
if [[ ! -z ${PULL_ID} ]]; then
# in ci environment, we use aliyun ubuntu mirror, thus turn off proxy
proxy_off
fi
if [[ $(command -v python) == $build_dir/ci-env/bin/python ]]; then
return
elif [[ -e $build_dir/ci-env/bin/activate ]]; then
source $build_dir/ci-env/bin/activate
return
fi
# NVIDIA update GPG key on 04/29/2022. Fetch the public key for CI machine
# Reference: https://developer.nvidia.com/blog/updating-the-cuda-linux-gpg-repository-key/
set +x
apt-key adv --keyserver-options http-proxy=$http_proxy --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub
set -x
apt update
echo "the current user EUID=$EUID: $(whoami)"
if ! command -v doxygen &> /dev/null; then
apt install -y doxygen
fi
if ! command -v python${py_version}-config &> /dev/null; then
apt install -y python${py_version}-dev
fi
if ! command -v virtualenv &> /dev/null; then
apt install -y virtualenv
fi
if [[ ! -e $build_dir/ci-env/bin/activate ]]; then
virtualenv ${build_dir}/ci-env -p python${py_version}
fi
source $build_dir/ci-env/bin/activate
python${py_version} -m pip install -U --no-cache-dir pip
python${py_version} -m pip install pre-commit
python${py_version} -m pip install clang-format==13.0.0
python${py_version} -m pip install wheel
python${py_version} -m pip install sphinx==3.3.1 sphinx_gallery==0.8.1 recommonmark==0.6.0 exhale scipy breathe==4.24.0 matplotlib sphinx_rtd_theme
python${py_version} -m pip install paddlepaddle-gpu==0.0.0.post112 -f https://www.paddlepaddle.org.cn/whl/linux/gpu/develop.html
}
function prepare_doc_model_file {
proxy_off
local tar_file=$1
if [[ -f "$tar_file.tar.gz" ]]; then
echo "model file $tar_file.tar.gz for tutorials already downloaded."
elif [[ -f "$build_dir/thirds/$tar_file.tar.gz" ]]; then
rm -rf $workspace/tutorials/$tar_file
ln -s $build_dir/thirds/$tar_file $workspace/tutorials/$tar_file
else
wget https://paddle-inference-dist.bj.bcebos.com/CINN/$tar_file.tar.gz
tar -zxvf $tar_file.tar.gz
fi
}
function make_doc {
proxy_off
cd $workspace/tutorials
prepare_doc_model_file ResNet50
prepare_doc_model_file MobileNetV2
prepare_doc_model_file EfficientNet
prepare_doc_model_file FaceDet
if [[ $cuda_config == "ON" && ! -d "./is_cuda" ]]; then
mkdir is_cuda
fi
if [[ $cuda_config == "OFF" && -d "./is_cuda" ]]; then
rm -rf ./is_cuda
fi
cd $build_dir
rm -f $workspace/python/cinn/core_api.so
ln -s $build_dir/cinn/pybind/core_api.so $workspace/python/cinn/
cd $workspace/docs
mkdir -p docs/source/cpp
cat $workspace/tutorials/matmul.cc | python${py_version} $workspace/tools/gen_c++_tutorial.py > $workspace/docs/source/matmul.md
cat $workspace/tutorials/load_paddle_model.cc | python${py_version} $workspace/tools/gen_c++_tutorial.py > $workspace/docs/source/load_paddle_model.md
make html
}
function cmake_ {
proxy_off
mkdir -p $build_dir
cp $workspace/cmake/config.cmake $build_dir
# To enable Cuda backend, set(WITH_CUDA ON)
echo "set(WITH_CUDA $cuda_config)" >> $build_dir/config.cmake
echo "set(WITH_CUDNN $cudnn_config)" >> $build_dir/config.cmake
echo "set(WITH_MKL_CBLAS ON)" >> $build_dir/config.cmake
echo "set(WITH_MKL_CBLAS $mklcblas_config)" >> $build_dir/config.cmake
echo "set(WITH_MKLDNN $mkldnn_config)" >> $build_dir/config.cmake
cd $build_dir
cmake ${workspace} -DPUBLISH_LIBS=ON -DWITH_TESTING=ON -DPY_VERSION=${py_version}
}
function _download_and_untar {
proxy_off
local tar_file=$1
if [[ ! -f $tar_file ]]; then
wget https://paddle-inference-dist.bj.bcebos.com/CINN/$tar_file
tar -zxvf $tar_file
fi
}
function prepare_model {
proxy_off
cd $build_dir/thirds
_download_and_untar ResNet18.tar.gz
_download_and_untar MobileNetV2.tar.gz
_download_and_untar EfficientNet.tar.gz
_download_and_untar MobilenetV1.tar.gz
_download_and_untar ResNet50.tar.gz
_download_and_untar SqueezeNet.tar.gz
_download_and_untar FaceDet.tar.gz
proxy_on
mkdir -p $build_dir/paddle
cd $build_dir/paddle
if [[ ! -f "libexternal_kernels.so.tgz" ]]; then
wget https://github.com/T8T9/files/raw/main/libexternal_kernels.so.tgz
fi
tar -zxvf libexternal_kernels.so.tgz
if [[ ! -f "paddle_1.8_fc_model.tgz" ]]; then
wget https://github.com/T8T9/files/raw/main/paddle_1.8_fc_model.tgz
fi
tar -zxvf paddle_1.8_fc_model.tgz
if [[ ! -f "mkldnn.tgz" ]]; then
wget https://github.com/T8T9/files/raw/main/mkldnn.tgz
fi
tar -zxvf mkldnn.tgz
cd $build_dir/thirds
python${py_version} $workspace/python/tests/fake_model/naive_mul.py
python${py_version} $workspace/python/tests/fake_model/naive_multi_fc.py
python${py_version} $workspace/python/tests/fake_model/resnet_model.py
}
function codestyle_check {
proxy_on
cd $workspace
pre-commit run -a
if ! git diff-index --quiet HEAD --; then
echo "Code is dirty, please run 'pre-commit run -a' to reformat the code changes"
exit -1
fi
}
function build {
proxy_on
cd $build_dir
make -j $JOBS
ls python/dist
python${py_version} -m pip install xgboost
python${py_version} -m pip install -U ${cinn_whl_path}
}
function run_demo {
cd $build_dir/dist
export runtime_include_dir=$workspace/cinn/runtime/cuda
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$build_dir/dist/cinn/lib
bash build_demo.sh
./demo
rm ./demo
cd -
}
function run_test {
source $build_dir/ci-env/bin/activate
cd $build_dir
export runtime_include_dir=$workspace/cinn/runtime/cuda
if [ ${TESTING_DEBUG_MODE:-OFF} == "ON" ] ; then
ctest --parallel 10 -V
else
ctest --parallel 10 --output-on-failure
fi
}
function CI {
mkdir -p $build_dir
cd $build_dir
export runtime_include_dir=$workspace/cinn/runtime/cuda
prepare_ci
codestyle_check
cmake_
build
run_demo
prepare_model
run_test
# make_doc
}
function CINNRT {
mkdir -p $build_dir
cd $build_dir
export runtime_include_dir=$workspace/cinn/runtime/cuda
prepare_ci
codestyle_check
proxy_off
mkdir -p $build_dir
cp $workspace/cmake/config.cmake $build_dir
# To enable Cuda backend, set(WITH_CUDA ON)
echo "set(WITH_CUDA $cuda_config)" >> $build_dir/config.cmake
echo "set(WITH_CUDNN $cudnn_config)" >> $build_dir/config.cmake
echo "set(WITH_MKL_CBLAS ON)" >> $build_dir/config.cmake
cd $build_dir
cmake .. -DPUBLISH_LIBS=ON -DWITH_TESTING=ON
make cinnopt -j $JOBS
}
function main {
# Parse command line.
for i in "$@"; do
case $i in
mklcblas_off)
mklcblas_off
mkldnn_off
shift
;;
mkldnn_off)
mkldnn_off
shift
;;
gpu_on)
gpu_on
shift
;;
cudnn_off)
cudnn_off
shift
;;
check_style)
codestyle_check
shift
;;
cmake)
cmake_
shift
;;
build)
build
shift
;;
test)
run_test
shift
;;
test_doc)
test_doc
shift
;;
ci)
CI
shift
;;
CINNRT)
CINNRT
shift
;;
prepare_model)
prepare_model
shift
;;
esac
done
}
main $@