ci_build.sh 6.6 KB
Newer Older
H
hjchen2 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/usr/bin/env bash

# Copyright (c) 2018 PaddlePaddle 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.

17
set -e
18
source ./ci_run_test.sh
H
hjchen2 已提交
19 20 21 22 23 24 25 26 27 28 29

function print_usage() {
  echo "\n${RED}Usage${NONE}:
  ${BOLD}${SCRIPT_NAME}${NONE} [Option] [Network]"

  echo "\n${RED}Option${NONE}: required, specify the target platform
  ${BLUE}android_armv7${NONE}: run build for android armv7 platform
  ${BLUE}android_armv8${NONE}: run build for android armv8 platform
  ${BLUE}ios${NONE}: run build for apple ios platform
  ${BLUE}linux_armv7${NONE}: run build for linux armv7 platform
  ${BLUE}linux_armv8${NONE}: run build for linux armv8 platform
30
  ${BLUE}fpga${NONE}: run build for fpga platform
H
hjchen2 已提交
31
  "
32 33 34 35 36 37 38 39 40 41 42
  echo "\n${RED}Network${NONE}: optional, for deep compressing the framework size
  ${BLUE}googlenet${NONE}: build only googlenet support
  ${BLUE}mobilenet${NONE}: build only mobilenet support
  ${BLUE}yolo${NONE}: build only yolo support
  ${BLUE}squeezenet${NONE}: build only squeezenet support
  ${BLUE}resnet${NONE}: build only resnet support
  ${BLUE}mobilenetssd${NONE}: build only mobilenetssd support
  ${BLUE}nlp${NONE}: build only nlp model support
  ${BLUE}mobilenetfssd${NONE}: build only mobilenetfssd support
  ${BLUE}genet${NONE}: build only genet support
  ${BLUE}super${NONE}: build only super support
H
hjchen2 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
  "
}

function init() {
  RED='\033[0;31m'
  BLUE='\033[0;34m'
  BOLD='\033[1m'
  NONE='\033[0m'

  PADDLE_MOBILE_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}")/../" && pwd )"
  if [ -z "${SCRIPT_NAME}" ]; then
      SCRIPT_NAME=$0
  fi
}

function check_ndk() {
  if [ -z "${NDK_ROOT}" ]; then
    echo "Should set NDK_ROOT as your android ndk path, such as\n"
    echo "  export NDK_ROOT=~/android-ndk-r14b\n"
    exit -1
  fi
}

function build_android_armv7_cpu_only() {
67
#  rm -rf ../build/armeabi-v7a
H
hjchen2 已提交
68 69 70 71 72 73 74 75 76
  cmake .. \
    -B"../build/armeabi-v7a" \
    -DANDROID_ABI="armeabi-v7a with NEON" \
    -DCMAKE_BUILD_TYPE="MinSizeRel" \
    -DCMAKE_TOOLCHAIN_FILE="./tools/android-cmake/android.toolchain.cmake" \
    -DANDROID_PLATFORM="android-22" \
    -DANDROID_STL=c++_static \
    -DANDROID=true \
    -DWITH_LOGGING=OFF \
77
    -DCPU=ON \
H
hjchen2 已提交
78 79 80 81 82 83 84 85
    -DGPU_CL=OFF \
    -DFPGA=OFF

  cd ../build/armeabi-v7a && make -j 8
  cd -
}

function build_android_armv7_gpu() {
H
update  
hjchen2 已提交
86
  rm -rf ../build/armeabi-v7a
H
hjchen2 已提交
87 88 89 90 91 92 93 94 95
  cmake .. \
    -B"../build/armeabi-v7a" \
    -DANDROID_ABI="armeabi-v7a with NEON" \
    -DCMAKE_BUILD_TYPE="MinSizeRel" \
    -DCMAKE_TOOLCHAIN_FILE="./tools/android-cmake/android.toolchain.cmake" \
    -DANDROID_PLATFORM="android-22" \
    -DANDROID_STL=c++_static \
    -DANDROID=true \
    -DWITH_LOGGING=OFF \
96
    -DCPU=ON \
H
hjchen2 已提交
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
    -DGPU_CL=ON \
    -DFPGA=OFF

  cd ../build/armeabi-v7a && make -j 8
  cd -
}

function build_android_armv8_cpu_only() {
  rm -rf ../build/arm64-v8a
  cmake .. \
    -B"../build/arm64-v8a" \
    -DANDROID_ABI="arm64-v8a" \
    -DCMAKE_BUILD_TYPE="MinSizeRel" \
    -DCMAKE_TOOLCHAIN_FILE="./tools/android-cmake/android.toolchain.cmake" \
    -DANDROID_PLATFORM="android-22" \
    -DANDROID_STL=c++_static \
    -DANDROID=true \
    -DWITH_LOGGING=OFF \
115
    -DCPU=ON \
H
hjchen2 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
    -DGPU_CL=OFF \
    -DFPGA=OFF

  cd ../build/arm64-v8a && make -j 1
  cd -
}

function build_android_armv8_gpu() {
  rm -rf ../build/arm64-v8a
  cmake .. \
    -B"../build/arm64-v8a" \
    -DANDROID_ABI="arm64-v8a" \
    -DCMAKE_BUILD_TYPE="MinSizeRel" \
    -DCMAKE_TOOLCHAIN_FILE="./tools/android-cmake/android.toolchain.cmake" \
    -DANDROID_PLATFORM="android-22" \
    -DANDROID_STL=c++_static \
    -DANDROID=true \
    -DWITH_LOGGING=OFF \
134
    -DCPU=ON \
H
hjchen2 已提交
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
    -DGPU_CL=ON \
    -DFPGA=OFF

  cd ../build/arm64-v8a && make -j 8
  cd -
}

function build_ios_armv8_cpu_only() {
  rm -rf ../build/ios
  cmake .. \
    -B"../build/ios" \
    -DCMAKE_BUILD_TYPE="MinSizeRel" \
    -DCMAKE_TOOLCHAIN_FILE="./tools/ios-cmake/ios.toolchain.cmake" \
    -DIOS_PLATFORM=OS \
    -DIOS_ARCH="${IOS_ARCH}" \
    -DIS_IOS=true \
151
    -DUSE_OPENMP=OFF \
152
    -DCPU=ON \
H
hjchen2 已提交
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
    -DGPU_CL=OFF \
    -DFPGA=OFF

  cd ../build/ios && make -j 8
  cd -
}

function build_ios_armv8_gpu() {
  rm -rf ../build/ios
  cmake .. \
    -B"../build/ios" \
    -DCMAKE_BUILD_TYPE="MinSizeRel" \
    -DCMAKE_TOOLCHAIN_FILE="./tools/ios-cmake/ios.toolchain.cmake" \
    -DIOS_PLATFORM=OS \
    -DIOS_ARCH="${IOS_ARCH}" \
    -DIS_IOS=true \
169
    -DUSE_OPENMP=OFF \
170
    -DCPU=ON \
H
hjchen2 已提交
171 172 173 174 175 176 177 178 179 180 181 182 183
    -DGPU_CL=ON \
    -DFPGA=OFF

  cd ../build/ios && make -j 8
  cd -
}

function build_linux_armv7_cpu_only() {
  rm -rf ../build/armv7_linux
  cmake .. \
    -B"../build/armv7_linux" \
    -DCMAKE_BUILD_TYPE="MinSizeRel" \
    -DCMAKE_TOOLCHAIN_FILE="./tools/toolchains/arm-linux-gnueabihf.cmake" \
184
    -DCPU=ON \
H
hjchen2 已提交
185 186 187 188 189 190 191 192 193 194 195 196 197
    -DGPU_CL=OFF \
    -DFPGA=OFF

  cd ../build/armv7_linux && make -j 8
  cd -
}

function build_linux_armv7_gpu() {
  rm -rf ../build/armv7_linux
  cmake .. \
    -B"../build/armv7_linux" \
    -DCMAKE_BUILD_TYPE="MinSizeRel" \
    -DCMAKE_TOOLCHAIN_FILE="./tools/toolchains/arm-linux-gnueabihf.cmake" \
198
    -DCPU=ON \
H
hjchen2 已提交
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
    -DGPU_CL=ON \
    -DFPGA=OFF

  cd ../build/armv7_linux && make -j 8
  cd -
}

function build_android_armv7() {
  check_ndk
  build_android_armv7_cpu_only
  # build_android_armv7_gpu
}

function build_android_armv8() {
  check_ndk
  build_android_armv8_cpu_only
  # build_android_armv8_gpu
}

function build_ios() {
  build_ios_armv8_cpu_only
  # build_ios_armv8_gpu
}

function build_linux_armv7() {
  build_linux_armv7_cpu_only
  # build_linux_armv7_gpu
}

228 229 230 231 232 233 234
function build_linux_fpga() {
  cd ..
  image=`docker images paddle-mobile:dev | grep 'paddle-mobile'`
  if [[ "x"$image == "x" ]]; then
    docker build -t paddle-mobile:dev - < Dockerfile
  fi
  docker run --rm -v `pwd`:/workspace paddle-mobile:dev bash /workspace/tools/docker_build_fpga.sh
235 236 237 238
  cd -
}

function run_android_test() {
H
update  
hjchen2 已提交
239
  ExecuteAndroidTests $1
240 241
}

H
hjchen2 已提交
242 243 244 245 246 247
function main() {
  local CMD=$1
  init
  case $CMD in
    android_armv7)
      build_android_armv7
248
      run_android_test armeabi-v7a 
H
hjchen2 已提交
249 250 251
      ;;
    android_armv8)
      build_android_armv8
252
      run_android_test arm64-v8a
H
hjchen2 已提交
253 254 255 256 257 258 259
      ;;
    ios)
      build_ios
      ;;
    linux_armv7)
      build_linux_armv7
      ;;
260 261 262
    fpga)
      build_linux_fpga
      ;;
H
hjchen2 已提交
263 264 265 266 267 268 269 270
    *)
      print_usage
      exit 0
      ;;
    esac
}

main $@