未验证 提交 c7c47523 编写于 作者: Z zhangchunle 提交者: GitHub

cherrypick1.8 update paddle_build.sh (#25904)

上级 05603c9a
......@@ -59,11 +59,14 @@ function init() {
}
function cmake_base() {
# build script will not fail if *.deb does not exist
# Build script will not fail if *.deb does not exist
rm *.deb 2>/dev/null || true
# delete previous built whl packages
# Delete previous built whl packages
rm -rf python/dist 2>/dev/null || true
# `gym` is only used in unittest, it's not suitable to add in requirements.txt.
# Add it dynamically.
echo "gym" >> ${PADDLE_ROOT}/python/requirements.txt
# Support build for all python versions, currently
# including cp27-cp27m and cp27-cp27mu.
PYTHON_FLAGS=""
......@@ -119,6 +122,8 @@ function cmake_base() {
exit 1
fi
fi
# delete `gym` to avoid modifying requirements.txt in *.whl
sed -i .bak "/^gym$/d" ${PADDLE_ROOT}/python/requirements.txt
else
if [ "$1" != "" ]; then
echo "using python abi: $1"
......@@ -175,6 +180,8 @@ function cmake_base() {
else
pip install -r ${PADDLE_ROOT}/python/requirements.txt
fi
# delete `gym` to avoid modifying requirements.txt in *.whl
sed -i "/^gym$/d" ${PADDLE_ROOT}/python/requirements.txt
fi
if [ "$SYSTEM" == "Darwin" ]; then
......@@ -193,15 +200,12 @@ function cmake_base() {
Configuring cmake in /paddle/build ...
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Release}
${PYTHON_FLAGS}
-DWITH_DSO=ON
-DWITH_GPU=${WITH_GPU:-OFF}
-DWITH_AMD_GPU=${WITH_AMD_GPU:-OFF}
-DWITH_DISTRIBUTE=${distibuted_flag}
-DWITH_MKL=${WITH_MKL:-ON}
-DWITH_AVX=${WITH_AVX:-OFF}
-DWITH_GOLANG=${WITH_GOLANG:-OFF}
-DCUDA_ARCH_NAME=${CUDA_ARCH_NAME:-All}
-DCUDA_ARCH_BIN=${CUDA_ARCH_BIN}
-DWITH_PYTHON=${WITH_PYTHON:-ON}
-DCUDNN_ROOT=/usr/
-DWITH_TESTING=${WITH_TESTING:-ON}
......@@ -216,24 +220,23 @@ function cmake_base() {
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX:-/paddle/build}
-DWITH_GRPC=${grpc_flag}
-DWITH_LITE=${WITH_LITE:-OFF}
-DLITE_GIT_TAG=develop
========================================
EOF
# Disable UNITTEST_USE_VIRTUALENV in docker because
# docker environment is fully controlled by this script.
# See /Paddle/CMakeLists.txt, UNITTEST_USE_VIRTUALENV option.
set +e
cmake .. \
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Release} \
${PYTHON_FLAGS} \
-DWITH_DSO=ON \
-DWITH_GPU=${WITH_GPU:-OFF} \
-DWITH_AMD_GPU=${WITH_AMD_GPU:-OFF} \
-DWITH_DISTRIBUTE=${distibuted_flag} \
-DWITH_MKL=${WITH_MKL:-ON} \
-DWITH_AVX=${WITH_AVX:-OFF} \
-DNOAVX_CORE_FILE=${NOAVX_CORE_FILE:-""} \
-DWITH_GOLANG=${WITH_GOLANG:-OFF} \
-DCUDA_ARCH_NAME=${CUDA_ARCH_NAME:-All} \
-DCUDA_ARCH_BIN=${CUDA_ARCH_BIN} \
-DWITH_PYTHON=${WITH_PYTHON:-ON} \
-DCUDNN_ROOT=/usr/ \
-DWITH_TESTING=${WITH_TESTING:-ON} \
......@@ -246,8 +249,11 @@ EOF
-DPY_VERSION=${PY_VERSION:-2.7} \
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX:-/paddle/build} \
-DWITH_GRPC=${grpc_flag} \
-DWITH_LITE=${WITH_LITE:-OFF}
-DLITE_GIT_TAG=develop \
-DWITH_LITE=${WITH_LITE:-OFF};build_error=$?
if [ "$build_error" != 0 ];then
exit 7;
fi
}
function cmake_gen() {
......@@ -270,6 +276,7 @@ function check_style() {
eval "$(GIMME_GO_VERSION=1.8.3 gimme)"
fi
pip install cpplint pylint pytest astroid isort
# set up go environment for running gometalinter
mkdir -p $GOPATH/src/github.com/PaddlePaddle/
......@@ -298,6 +305,7 @@ function check_style() {
#=================================================
function build_base() {
set +e
if [ "$SYSTEM" == "Linux" ];then
if [ `nproc` -gt 16 ];then
parallel_number=$(expr `nproc` - 8)
......@@ -315,7 +323,36 @@ function build_base() {
make clean
fi
make install -j ${parallel_number}
make install -j ${parallel_number};build_error=$?
if [ "$build_error" != 0 ];then
exit 7;
fi
}
function build_size() {
cat <<EOF
============================================
Calculate /paddle/build size and PR whl size
============================================
EOF
if [ "$1" == "fluid_inference" ]; then
cd ${PADDLE_ROOT}/build
cp -r fluid_inference_install_dir fluid_inference
tar -czf fluid_inference.tgz fluid_inference
buildSize=$(du -h --max-depth=0 ${PADDLE_ROOT}/build/fluid_inference.tgz |awk '{print $1}')
echo "FLuid_Inference Size: $buildSize"
else
SYSTEM=`uname -s`
if [ "$SYSTEM" == "Darwin" ]; then
com='du -h -d 0'
else
com='du -h --max-depth=0'
fi
buildSize=$($com ${PADDLE_ROOT}/build |awk '{print $1}')
echo "Build Size: $buildSize"
PR_whlSize=$($com ${PADDLE_ROOT}/build/python/dist |awk '{print $1}')
echo "PR whl Size: $PR_whlSize"
fi
}
function build() {
......@@ -327,9 +364,22 @@ function build() {
============================================
EOF
build_base $@
current_branch=`git branch | grep \* | cut -d ' ' -f2`
if [ "$current_branch" != "develop_base_pr" ];then
build_size
fi
}
function cmake_gen_and_build() {
startTime_s=`date +%s`
cmake_gen $1
build $2
endTime_s=`date +%s`
echo "Build Time: $[ $endTime_s - $startTime_s ]s"
}
function build_mac() {
set +e
mkdir -p ${PADDLE_ROOT}/build
cd ${PADDLE_ROOT}/build
cat <<EOF
......@@ -340,7 +390,20 @@ EOF
if [[ "$ENABLE_MAKE_CLEAN" != "OFF" ]]; then
make clean
fi
make install -j 8
make install -j 8;build_error=$?
if [ "$build_error" != 0 ];then
exit 7;
fi
set -e
build_size
}
function cmake_gen_and_build_mac() {
startTime_s=`date +%s`
cmake_gen $1
build_mac
endTime_s=`date +%s`
echo "Build Time: $[ $endTime_s - $startTime_s ]s"
}
function run_test() {
......@@ -428,12 +491,11 @@ function run_mac_test() {
Running unit tests ...
========================================
EOF
#remove proxy here to fix dist error on mac
#remove proxy here to fix dist ut 'test_fl_listen_and_serv_op' error on mac.
#see details: https://github.com/PaddlePaddle/Paddle/issues/24738
my_proxy=$http_proxy
export http_proxy=
export https_proxy=
# make install should also be test when unittest
make install -j 8
set +ex
if [ "$1" == "cp27-cp27m" ]; then
......@@ -458,8 +520,10 @@ EOF
elif [ "$1" == "cp37-cp37m" ]; then
pip3.7 install --user ${INSTALL_PREFIX:-/paddle/build}/opt/paddle/share/wheels/*.whl
fi
ut_startTime_s=`date +%s`
ctest --output-on-failure -j $2
ut_endTime_s=`date +%s`
echo "Mac testCase Time: $[ $ut_endTime_s - $ut_startTime_s ]s"
paddle version
# Recovery proxy to avoid failure in later steps
export http_proxy=$my_proxy
......@@ -520,6 +584,10 @@ function generate_api_spec() {
op_desc_path=${PADDLE_ROOT}/paddle/fluid/OP_DESC_${spec_kind}.spec
python ${PADDLE_ROOT}/tools/print_op_desc.py > $op_desc_path
# print api and the md5 of source code of the api.
api_source_md5_path=${PADDLE_ROOT}/paddle/fluid/API_${spec_kind}.source.md5
python ${PADDLE_ROOT}/tools/count_api_without_core_ops.py -p paddle > $api_source_md5_path
awk -F '(' '{print $NF}' $spec_path >${spec_path}.doc
awk -F '(' '{$NF="";print $0}' $spec_path >${spec_path}.api
if [ "$1" == "cp35-cp35m" ] || [ "$1" == "cp36-cp36m" ] || [ "$1" == "cp37-cp37m" ]; then
......@@ -612,9 +680,9 @@ EOF
function assert_api_spec_approvals() {
/bin/bash ${PADDLE_ROOT}/tools/check_api_approvals.sh
if [ "$?" != 0 ];then
exit 1
/bin/bash ${PADDLE_ROOT}/tools/check_api_approvals.sh;approval_error=$?
if [ "$approval_error" != 0 ];then
exit 6
fi
}
......@@ -684,9 +752,42 @@ function caught_error() {
done
}
function case_count(){
cat <<EOF
============================================
Generating TestCases Count ...
============================================
EOF
testcases=$1
num=$(echo $testcases|grep -o '\^'|wc -l)
if [ "$2" == "" ]; then
echo "exclusive TestCases count is $num"
else
echo "$2 card TestCases count is $num"
fi
}
failed_test_lists=''
tmp_dir=`mktemp -d`
function collect_failed_tests() {
for file in `ls $tmp_dir`; do
exit_code=0
grep -q 'The following tests FAILED:' $tmp_dir/$file||exit_code=$?
if [ $exit_code -ne 0 ]; then
failuretest=''
else
failuretest=`grep -A 10000 'The following tests FAILED:' $tmp_dir/$file | sed 's/The following tests FAILED://g'|sed '/^$/d'`
failed_test_lists="${failed_test_lists}
${failuretest}"
fi
done
}
function card_test() {
set -m
case_count $1 $2
ut_startTime_s=`date +%s`
# get the CUDA device count
CUDA_DEVICE_COUNT=$(nvidia-smi -L | wc -l)
......@@ -705,7 +806,7 @@ function card_test() {
fi
trap 'caught_error' CHLD
tmpfile_rand=`date +%s%N`
NUM_PROC=$[CUDA_DEVICE_COUNT/$cardnumber]
for (( i = 0; i < $NUM_PROC; i++ )); do
# CUDA_VISIBLE_DEVICES http://acceleware.com/blog/cudavisibledevices-masking-gpus
......@@ -718,26 +819,32 @@ function card_test() {
cuda_list="$cuda_list,$[i*cardnumber+j]"
fi
done
tmpfile=$tmp_dir/$tmpfile_rand"_"$i
if [ ${TESTING_DEBUG_MODE:-OFF} == "ON" ] ; then
if [[ $cardnumber == $CUDA_DEVICE_COUNT ]]; then
ctest -I $i,,$NUM_PROC -R "($testcases)" -V &
else
env CUDA_VISIBLE_DEVICES=$cuda_list ctest -I $i,,$NUM_PROC -R "($testcases)" -V &
(ctest -I $i,,$NUM_PROC -R "($testcases)" -V | tee $tmpfile; test ${PIPESTATUS[0]} -eq 0) &
else
(env CUDA_VISIBLE_DEVICES=$cuda_list ctest -I $i,,$NUM_PROC -R "($testcases)" -V | tee $tmpfile; test ${PIPESTATUS[0]} -eq 0) &
fi
else
if [[ $cardnumber == $CUDA_DEVICE_COUNT ]]; then
ctest -I $i,,$NUM_PROC -R "($testcases)" --output-on-failure &
(ctest -I $i,,$NUM_PROC -R "($testcases)" --output-on-failure | tee $tmpfile; test ${PIPESTATUS[0]} -eq 0) &
else
env CUDA_VISIBLE_DEVICES=$cuda_list ctest -I $i,,$NUM_PROC -R "($testcases)" --output-on-failure &
(env CUDA_VISIBLE_DEVICES=$cuda_list ctest -I $i,,$NUM_PROC -R "($testcases)" --output-on-failure | tee $tmpfile; test ${PIPESTATUS[0]} -eq 0) &
fi
fi
done
wait; # wait for all subshells to finish
ut_endTime_s=`date +%s`
if [ "$2" == "" ]; then
echo "exclusive TestCases Total Time: $[ $ut_endTime_s - $ut_startTime_s ]s"
else
echo "$2 card TestCases Total Time: $[ $ut_endTime_s - $ut_startTime_s ]s"
fi
set +m
}
function parallel_test_base() {
function parallel_test_base_gpu() {
if [ ${WITH_TESTING:-ON} == "ON" ] ; then
cat <<EOF
========================================
......@@ -786,6 +893,15 @@ set +x
multiple_card_tests="$multiple_card_tests|^$testcase$"
fi
else
if [[ "${#single_card_tests}" -gt 3000 ]];then
if [[ "$single_card_tests_1" == "" ]]; then
single_card_tests_1="^$testcase$"
else
single_card_tests_1="$single_card_tests_1|^$testcase$"
fi
continue
fi
if [[ "$single_card_tests" == "" ]]; then
single_card_tests="^$testcase$"
else
......@@ -799,8 +915,19 @@ set +x
done <<< "$test_cases";
card_test "$single_card_tests" 1 # run cases with single GPU
card_test "$single_card_tests_1" 1 # run cases with single GPU
card_test "$multiple_card_tests" 2 # run cases with two GPUs
card_test "$exclusive_tests" # run cases exclusively, in this cases would be run with 4/8 GPUs
collect_failed_tests
if [ -n "${failed_test_lists}" ];then
failed_test_lists_ult=`echo "${failed_test_lists}" |grep -Po '[^ ].*$'`
echo "========================================"
echo "Summary Failed Tests... "
echo "========================================"
echo "The following tests FAILED: "
echo "${failed_test_lists_ult}"
fi
rm -f $tmp_dir/*
if [[ "$EXIT_CODE" != "0" ]]; then
exit 8;
fi
......@@ -808,10 +935,36 @@ set -ex
fi
}
function parallel_test_base_cpu() {
mkdir -p ${PADDLE_ROOT}/build
cd ${PADDLE_ROOT}/build
if [ ${WITH_TESTING:-ON} == "ON" ] ; then
cat <<EOF
========================================
Running unit cpu tests ...
========================================
EOF
ut_startTime_s=`date +%s`
ctest --output-on-failure -j $1
ut_endTime_s=`date +%s`
echo "CPU testCase Time: $[ $ut_endTime_s - $ut_startTime_s ]s"
if [[ "$EXIT_CODE" != "0" ]]; then
exit 8;
fi
fi
}
function parallel_test() {
ut_total_startTime_s=`date +%s`
mkdir -p ${PADDLE_ROOT}/build
cd ${PADDLE_ROOT}/build
parallel_test_base
if [ "$WITH_GPU" == "ON" ];then
parallel_test_base_gpu
else
parallel_test_base_cpu ${PROC_RUN:-1}
fi
ut_total_endTime_s=`date +%s`
echo "TestCases Total Time: $[ $ut_total_endTime_s - $ut_total_startTime_s ]s"
}
function enable_unused_var_check() {
......@@ -1069,10 +1222,17 @@ EOF
if [[ "$1" != "" ]]; then
parallel_number=$1
fi
cmake .. -DWITH_DISTRIBUTE=OFF -DON_INFER=ON -DCUDA_ARCH_NAME=${CUDA_ARCH_NAME:-Auto} -DCUDA_ARCH_BIN=${CUDA_ARCH_BIN}
make -j ${parallel_number} fluid_lib_dist
make -j ${parallel_number} inference_lib_dist
startTime_s=`date +%s`
set +e
cmake .. -DWITH_DISTRIBUTE=OFF -DON_INFER=ON -DCUDA_ARCH_NAME=${CUDA_ARCH_NAME:-Auto};build_error=$?
make -j ${parallel_number} fluid_lib_dist;build_error=$?
make -j ${parallel_number} inference_lib_dist;build_error=$?
if [ "$build_error" != 0 ];then
exit 7;
fi
endTime_s=`date +%s`
echo "Build Time: $[ $endTime_s - $startTime_s ]s"
build_size "fluid_inference"
}
function tar_fluid_lib() {
......@@ -1094,10 +1254,13 @@ function test_fluid_lib() {
Testing fluid library for inference ...
========================================
EOF
fluid_startTime_s=`date +%s`
cd ${PADDLE_ROOT}/paddle/fluid/inference/api/demo_ci
./run.sh ${PADDLE_ROOT} ${WITH_MKL:-ON} ${WITH_GPU:-OFF} ${INFERENCE_DEMO_INSTALL_DIR} \
${TENSORRT_INCLUDE_DIR:-/usr/local/TensorRT/include} \
${TENSORRT_LIB_DIR:-/usr/local/TensorRT/lib}
fluid_endTime_s=`date +%s`
echo "test_fluid_lib Total Time: $[ $fluid_endTime_s - $fluid_startTime_s ]s"
./clean.sh
}
......@@ -1107,8 +1270,11 @@ function test_fluid_lib_train() {
Testing fluid library for training ...
========================================
EOF
fluid_train_startTime_s=`date +%s`
cd ${PADDLE_ROOT}/paddle/fluid/train/demo
./run.sh ${PADDLE_ROOT} ${WITH_MKL:-ON}
fluid_train_endTime_s=`date +%s`
echo "test_fluid_lib_train Total Time: $[ $fluid_train_endTime_s - $fluid_train_startTime_s ]s"
./clean.sh
}
......@@ -1121,28 +1287,25 @@ function example() {
pip install ${PADDLE_ROOT}/build/python/dist/*.whl
paddle version
cd ${PADDLE_ROOT}/tools
python sampcd_processor.py cpu
if [ "$?" != "0" ];then
python sampcd_processor.py cpu;example_error=$?
if [ "$example_error" != "0" ];then
echo "Code instance execution failed"
exit 1
exit 5
fi
}
function main() {
local CMD=$1
local parallel_number=$2
init
case $CMD in
build_only)
cmake_gen ${PYTHON_ABI:-""}
build ${parallel_number}
cmake_gen_and_build ${PYTHON_ABI:-""} ${parallel_number}
;;
build_and_check)
check_style
generate_upstream_develop_api_spec ${PYTHON_ABI:-""} ${parallel_number}
cmake_gen ${PYTHON_ABI:-""}
build ${parallel_number}
cmake_gen_and_build ${PYTHON_ABI:-""} ${parallel_number}
check_sequence_op_unittest
generate_api_spec ${PYTHON_ABI:-""} "PR"
example
......@@ -1198,8 +1361,7 @@ function main() {
;;
cicheck_coverage)
check_approvals_of_unittest 1
cmake_gen ${PYTHON_ABI:-""}
build ${parallel_number}
cmake_gen_and_build ${PYTHON_ABI:-""} ${parallel_number}
enable_unused_var_check
parallel_test
check_coverage
......@@ -1227,13 +1389,11 @@ function main() {
assert_api_spec_approvals
;;
maccheck)
cmake_gen ${PYTHON_ABI:-""}
build_mac
cmake_gen_and_build_mac ${PYTHON_ABI:-""}
run_mac_test ${PYTHON_ABI:-""} ${PROC_RUN:-1}
;;
maccheck_py35)
cmake_gen ${PYTHON_ABI:-""}
build_mac
cmake_gen_and_build_mac ${PYTHON_ABI:-""}
run_mac_test ${PYTHON_ABI:-""} ${PROC_RUN:-1}
check_change_of_unittest ${PYTHON_ABI:-""}
;;
......@@ -1242,8 +1402,7 @@ function main() {
build_mac
;;
cicheck_py35)
cmake_gen ${PYTHON_ABI:-""}
build ${parallel_number}
cmake_gen_and_build ${PYTHON_ABI:-""} ${parallel_number}
parallel_test
;;
cmake_gen)
......
......@@ -105,6 +105,10 @@ def visit_member(parent_name, member):
if hasattr(value, '__name__') and (not name.startswith("_") or
name == "__init__"):
visit_member(cur_name, value)
elif inspect.ismethoddescriptor(member):
return
elif inspect.isbuiltin(member):
return
elif callable(member):
queue_dict(member, cur_name)
elif inspect.isgetsetdescriptor(member):
......
......@@ -470,7 +470,7 @@ def get_filenames():
except AttributeError:
whl_error.append(api)
continue
if len(module.split('.')) > 2:
if len(module.split('.')) > 1:
filename = '../python/'
module_py = '%s.py' % module.split('.')[-1]
for i in range(0, len(module.split('.')) - 1):
......@@ -478,10 +478,16 @@ def get_filenames():
filename = filename + module_py
else:
filename = ''
print("\n----Exception in get api filename----\n")
print("\nWARNING:----Exception in get api filename----\n")
print("\n" + api + ' module is ' + module + "\n")
if filename not in filenames:
filenames.append(filename)
if filename != '':
# rm contrib file
if filename.startswith(
'../python/paddle/fluid/contrib'
) or filename == '../python/paddle/verison.py':
pass
elif filename not in filenames:
filenames.append(filename)
# get all methods
method = ''
if inspect.isclass(eval(api)):
......@@ -492,7 +498,7 @@ def get_filenames():
name = '%s.%s' % (api.split('.')[-2], api.split('.')[-1])
else:
name = ''
print("\n----Exception in get api methods----\n")
print("\nWARNING:----Exception in get api methods----\n")
print("\n" + line + "\n")
print("\n" + api + ' method is None!!!' + "\n")
for j in range(2, len(module.split('.'))):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册