build.sh 6.5 KB
Newer Older
Y
Yan Chunwei 已提交
1
#!/bin/bash
2
set -ex
Y
Yan Chunwei 已提交
3

4
TESTS_FILE="./lite_tests.txt"
Y
Yan Chunwei 已提交
5 6

readonly common_flags="-DWITH_LITE=ON -DLITE_WITH_LIGHT_WEIGHT_FRAMEWORK=OFF -DWITH_PYTHON=OFF -DWITH_TESTING=ON -DLITE_WITH_ARM=OFF"
7 8 9 10 11 12 13 14

# for code gen, a source file is generated after a test, but is dependended by some targets in cmake.
# here we fake an empty file to make cmake works.
function prepare_for_codegen {
    # in build directory
    mkdir -p ./paddle/fluid/lite/gen_code
    touch ./paddle/fluid/lite/gen_code/__generated_code__.cc
}
Y
Yan Chunwei 已提交
15
function cmake_x86 {
16
    prepare_for_codegen
17
    cmake ..  -DWITH_GPU=OFF -DWITH_MKLDNN=OFF -DLITE_WITH_X86=ON ${common_flags}
Y
Yan Chunwei 已提交
18 19
}

Y
Yan Chunwei 已提交
20
function cmake_x86_for_CI {
21
    prepare_for_codegen
Y
Yan Chunwei 已提交
22 23 24
    cmake ..  -DWITH_GPU=OFF -DWITH_MKLDNN=OFF -DLITE_WITH_X86=ON ${common_flags} -DLITE_WITH_PROFILE=ON
}

Y
Yan Chunwei 已提交
25
function cmake_gpu {
26
    prepare_for_codegen
Y
Yan Chunwei 已提交
27 28 29 30
    cmake .. " -DWITH_GPU=ON {common_flags} -DLITE_WITH_GPU=ON"
}

function cmake_arm {
T
tensor-tang 已提交
31 32 33 34 35 36 37 38 39 40 41 42
    # $1: ARM_TARGET_OS in "android" , "armlinux"
    # $2: ARM_TARGET_ARCH_ABI in "arm64-v8a", "armeabi-v7a" ,"armeabi-v7a-hf"
    cmake .. \
        -DWITH_GPU=OFF \
        -DWITH_MKL=OFF \
        -DWITH_LITE=ON \
        -DLITE_WITH_CUDA=OFF \
        -DLITE_WITH_X86=OFF \
        -DLITE_WITH_ARM=ON \
        -DLITE_WITH_LIGHT_WEIGHT_FRAMEWORK=ON \
        -DWITH_TESTING=ON \
        -DARM_TARGET_OS=$1 -DARM_TARGET_ARCH_ABI=$2
Y
Yan Chunwei 已提交
43 44
}

45 46 47 48 49 50
# function build {
#     file=$1
#     for _test in $(cat $file); do
#         make $_test -j$(expr $(nproc) - 2)
#     done
# }
Y
Yan Chunwei 已提交
51 52 53 54 55 56

# It will eagerly test all lite related unittests.
function test_lite {
    local file=$1
    echo "file: ${file}"
    for _test in $(cat $file); do
57
        make $_test -j$(expr $(nproc) - 2)
Y
Yan Chunwei 已提交
58 59 60 61
        ctest -R $_test -V
    done
}

T
tensor-tang 已提交
62 63 64 65 66
port_armv8=5554
port_armv7=5556

# Run test on android
function test_lite_android {
Y
Yan Chunwei 已提交
67
    local file=$1
T
tensor-tang 已提交
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
    local adb_abi=$2
    local port=
    if [[ ${adb_abi} == "armeabi-v7a" ]]; then
        port=${port_armv7}
    fi

    if [[ ${adb_abi} == "arm64-v8a" ]]; then
        port=${port_armv8}
    fi
    if [[ "${port}x" == "x" ]]; then
        echo "Port can not be empty"
        exit 1
    fi

    echo "file: ${file}"
    # push all to adb and test
    adb_work_dir="/data/local/tmp"
    skip_list="test_model_parser_lite"
    for _test in $(cat $file); do
        [[ $skip_list =~ (^|[[:space:]])$_test($|[[:space:]]) ]] && continue || echo 'skip $_test'
        testpath=$(find ./paddle/fluid -name ${_test})
        adb -s emulator-${port} push ${testpath} ${adb_work_dir}
        adb -s emulator-${port} shell chmod +x "${adb_work_dir}/${_test}"
        adb -s emulator-${port} shell "./${adb_work_dir}/${_test}"
    done
Y
Yan Chunwei 已提交
93 94
}

95 96 97 98 99
# Build the code and run lite server tests. This is executed in the CI system.
function build_test_server {
    mkdir -p ./build
    cd ./build
    export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/paddle/build/third_party/install/mklml/lib"
Y
Yan Chunwei 已提交
100
    cmake_x86_for_CI
101
    #build $TESTS_FILE
102 103 104
    test_lite $TESTS_FILE
}

T
tensor-tang 已提交
105 106
# Build the code and run lite server tests. This is executed in the CI system.
function build_test_arm {
T
tensor-tang 已提交
107
    adb kill-server
T
tensor-tang 已提交
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
    adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done
    # start android arm64-v8a armeabi-v7a emulators first
    echo n | avdmanager create avd -f -n paddle-armv8 -k "system-images;android-24;google_apis;arm64-v8a"
    echo -ne '\n' | ${ANDROID_HOME}/emulator/emulator -avd paddle-armv8 -noaudio -no-window -gpu off -verbose -port ${port_armv8} &
    sleep 1m
    echo n | avdmanager create avd -f -n paddle-armv7 -k "system-images;android-24;google_apis;armeabi-v7a"
    echo -ne '\n' | ${ANDROID_HOME}/emulator/emulator -avd paddle-armv7 -noaudio -no-window -gpu off -verbose -port ${port_armv7} &
    sleep 1m

    for os in "android" "armlinux" ; do
        for abi in "arm64-v8a" "armeabi-v7a" "armeabi-v7a-hf" ; do
            if [[ ${abi} == "armeabi-v7a-hf" ]]; then
                echo "armeabi-v7a-hf is not supported on both android and armlinux"
                continue
            fi

            if [[ ${os} == "armlinux" && ${abi} == "armeabi-v7a" ]]; then
                echo "armeabi-v7a is not supported on armlinux yet"
                continue
            fi

            build_dir=build.lite.${os}.${abi}
            mkdir -p $build_dir
            cd $build_dir

            cmake_arm ${os} ${abi}
            build $TESTS_FILE

            if [[ ${os} == "android" ]]; then
                adb_abi=${abi}
                if [[ ${adb_abi} == "armeabi-v7a-hf" ]]; then
                    adb_abi="armeabi-v7a"
                fi
                if [[ ${adb_abi} == "armeabi-v7a" ]]; then
                    # skip v7 tests
                    continue
                fi
                test_lite_android $TESTS_FILE ${adb_abi}
                # armlinux need in another docker
            fi
            cd -
        done
    done
    adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done
    echo "Done"
}

Y
Yan Chunwei 已提交
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
############################# MAIN #################################
function print_usage {
    echo -e "\nUSAGE:"
    echo
    echo "----------------------------------------"
    echo -e "cmake_x86: run cmake with X86 mode"
    echo -e "cmake_cuda: run cmake with CUDA mode"
    echo -e "cmake_arm: run cmake with ARM mode"
    echo
    echo -e "build: compile the tests"
    echo
    echo -e "test_server: run server tests"
    echo -e "test_mobile: run mobile tests"
    echo "----------------------------------------"
    echo
}

function main {
    # Parse command line.
    for i in "$@"; do
        case $i in
            --tests=*)
                TESTS_FILE="${i#*=}"
                shift
                ;;
180 181 182 183
            # build)
            #     build $TESTS_FILE
            #     shift
            #     ;;
Y
Yan Chunwei 已提交
184 185 186 187 188 189 190 191 192
            cmake_x86)
                cmake_x86
                shift
                ;;
            cmake_cuda)
                cmake_cuda
                shift
                ;;
            cmake_arm)
T
tensor-tang 已提交
193
                cmake_arm $2 $3
Y
Yan Chunwei 已提交
194 195 196 197 198 199 200 201 202 203
                shift
                ;;
            test_server)
                test_lite $TESTS_FILE
                shift
                ;;
            test_mobile)
                test_lite $TESTS_FILE
                shift
                ;;
204 205 206 207
            build_test_server)
                build_test_server
                shift
                ;;
T
tensor-tang 已提交
208 209 210 211
            build_test_arm)
                build_test_arm
                shift
                ;;
Y
Yan Chunwei 已提交
212 213 214 215 216 217 218 219 220 221 222 223
            *)
                # unknown option
                print_usage
                exit 1
                ;;
        esac
    done
}

print_usage

main $@