From 9cffbb69dd02f0163024f97a13d406afafd0b2b7 Mon Sep 17 00:00:00 2001 From: hjchen2 Date: Wed, 16 Jan 2019 17:28:12 +0800 Subject: [PATCH] Add ci build script --- CMakeLists.txt | 44 +++---- tools/paddle_mobile_build.sh | 248 +++++++++++++++++++++++++++++++++++ 2 files changed, 269 insertions(+), 23 deletions(-) create mode 100755 tools/paddle_mobile_build.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e33b71509..9f956960fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,20 +1,20 @@ cmake_minimum_required(VERSION 3.0.0) -option(USE_OPENMP "openmp support" ON) -option(DEBUGING "enable debug mode" ON) -option(USE_EXCEPTION "use std exception" ON) -option(SYMBOL_HIDDEN "symbol hidden" OFF) # on when use jni or ios io -option(LOG_PROFILE "log profile" OFF) +option(USE_OPENMP "build with openmp support" ON) +option(USE_EXCEPTION "build with exception" ON) +option(WITH_LOGGING "print logging for debug" ON) +option(WITH_SYMBOL "build with all symbols" ON) # turn off if use jni or ios io +option(WITH_PROFILE "print op profile for debug" OFF) +option(WITH_TEST "build with unit tests" ON) # select the platform to build -option(CPU "armv7 with neon" ON) -option(GPU_MALI "mali gpu" OFF) -option(GPU_CL "opencl gpu" OFF) - -option(FPGA "fpga" OFF) +option(CPU "build with arm CPU support" ON) +option(GPU_MALI "build with arm mali GPU support" OFF) +option(GPU_CL "build with OpenCL support" OFF) +option(FPGA "build with FPGA support" OFF) if(FPGA) - option(FPGAV1 "fpga v1" ON) - option(FPGAV2 "fpga v2" OFF) + option(FPGAV1 "build with fpga v1 support" ON) + option(FPGAV2 "build with fpga v2 support" OFF) endif() project(paddle-mobile) @@ -23,7 +23,6 @@ file(GLOB_RECURSE PADDLE_MOBILE_CC src/*.cc src/*.cpp src/*.c src/*.mm) file(GLOB_RECURSE PADDLE_MOBILE_H src/*.h) include_directories(src/) -set(CMAKE_BUILD_TYPE Release) set(CMAKE_CXX_FLAGS "-O3 -s -DNDEBUG ${CMAKE_CXX_FLAGS}") if(IS_IOS) set(CMAKE_CXX_FLAGS "-mfpu=neon -marm -fobjc-abi-version=2 -fobjc-arc \ @@ -33,13 +32,18 @@ else() set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}") endif() -if(DEBUGING) +if(USE_OPENMP) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp") + add_definitions(-DPADDLE_MOBILE_USE_OPENMP) +endif() + +if(WITH_LOGGING) message(STATUS "debugging mode") add_definitions(-DPADDLE_MOBILE_DEBUG) else() endif() -if(SYMBOL_HIDDEN) +if(NOT WITH_SYMBOL) add_definitions(-fvisibility=hidden -fvisibility-inlines-hidden) endif() @@ -50,15 +54,10 @@ else() add_definitions(-fno-exceptions) endif() -if(LOG_PROFILE) +if(WITH_PROFILE) add_definitions(-DPADDLE_MOBILE_PROFILE) endif() -if(USE_OPENMP) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp") - add_definitions(-DPADDLE_MOBILE_USE_OPENMP) -endif() - # platform control if(ARM_LINUX) include("${CMAKE_CURRENT_LIST_DIR}/tools/arm-platform.cmake") @@ -217,7 +216,6 @@ endif() set_property(CACHE NET PROPERTY STRINGS "default" "googlenet" "mobilenet" "yolo" "squeezenet" "FPGA_NET_V1" "FPGA_NET_V2" "NLP") include("${CMAKE_CURRENT_LIST_DIR}/tools/op.cmake") - # build library if(ANDROID_NDK_TOOLCHAIN_INCLUDED) list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS) @@ -239,7 +237,7 @@ else() endif() # unit test -if(DEBUGING) +if(WITH_TEST AND WITH_SYMBOL) if(IS_IOS) else() add_subdirectory(test) diff --git a/tools/paddle_mobile_build.sh b/tools/paddle_mobile_build.sh new file mode 100755 index 0000000000..068164fe46 --- /dev/null +++ b/tools/paddle_mobile_build.sh @@ -0,0 +1,248 @@ +#!/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. + +#set -ex + +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 + " + echo "\n${RED}Network${NONE}: optional, only for compressing framework size + ${BLUE}googlenet${NONE}: build only googlenet supported + ${BLUE}mobilenet${NONE}: build only mobilenet supported + ${BLUE}yolo${NONE}: build only yolo supported + ${BLUE}squeezenet${NONE}: build only squeezenet supported + ${BLUE}resnet${NONE}: build only resnet supported + ${BLUE}mobilenetssd${NONE}: build only mobilenetssd supported + ${BLUE}nlp${NONE}: build only nlp model supported + ${BLUE}mobilenetfssd${NONE}: build only mobilenetfssd supported + ${BLUE}genet${NONE}: build only genet supported + ${BLUE}super${NONE}: build only super supported + " +} + +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() { + rm -rf ../build/armeabi-v7a + 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 \ + -DGPU_MALI=OFF \ + -DGPU_CL=OFF \ + -DFPGA=OFF + + cd ../build/armeabi-v7a && make -j 8 + cd - +} + +function build_android_armv7_gpu() { + rm -rf ../build/armeabi-v7a + 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 \ + -DGPU_MALI=ON \ + -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 \ + -DGPU_MALI=OFF \ + -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 \ + -DGPU_MALI=ON \ + -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 \ + -DGPU_MALI=OFF \ + -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 \ + -DGPU_MALI=OFF \ + -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" \ + -DGPU_MALI=OFF \ + -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" \ + -DGPU_MALI=ON \ + -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() { + check_ndk + build_linux_armv7_cpu_only + # build_linux_armv7_gpu +} + +function main() { + local CMD=$1 + init + case $CMD in + android_armv7) + build_android_armv7 + ;; + android_armv8) + build_android_armv8 + ;; + ios) + build_ios + ;; + linux_armv7) + build_linux_armv7 + ;; + *) + print_usage + exit 0 + ;; + esac +} + +main $@ -- GitLab