提交 b17b41ad 编写于 作者: T tensor-tang

Merge branch 'tangjian/lite/clang' into 'incubate/lite'

support clang compile on arm

See merge request inference/paddlelite!29
...@@ -42,7 +42,17 @@ if(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK) ...@@ -42,7 +42,17 @@ if(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK)
message(FATAL_ERROR "ARM_TARGET_ARCH_ABI must be in one of ${ARM_TARGET_ARCH_ABI_LIST}") message(FATAL_ERROR "ARM_TARGET_ARCH_ABI must be in one of ${ARM_TARGET_ARCH_ABI_LIST}")
endif() endif()
message(STATUS "Lite ARM Compile ${ARM_TARGET_OS} with ${ARM_TARGET_ARCH_ABI}") # check arch abi
if(NOT DEFINED ARM_TARGET_LANG)
set(ARM_TARGET_LANG "clang" CACHE STRING "Choose ARM Target Language")
endif()
set(ARM_TARGET_LANG_LIST "gcc" "clang")
set_property(CACHE ARM_TARGET_LANG PROPERTY STRINGS ${ARM_TARGET_LANG_LIST})
if (NOT ARM_TARGET_LANG IN_LIST ARM_TARGET_LANG_LIST)
message(FATAL_ERROR "ARM_TARGET_LANG must be in one of ${ARM_TARGET_LANG_LIST}")
endif()
message(STATUS "Lite ARM Compile ${ARM_TARGET_OS} with ${ARM_TARGET_ARCH_ABI} ${ARM_TARGET_LANG}")
include(cross_compiling/host) include(cross_compiling/host)
include(cross_compiling/armlinux) include(cross_compiling/armlinux)
include(cross_compiling/android) include(cross_compiling/android)
...@@ -158,6 +168,9 @@ include_directories("${PADDLE_SOURCE_DIR}") ...@@ -158,6 +168,9 @@ include_directories("${PADDLE_SOURCE_DIR}")
# for mobile # for mobile
if (WITH_LITE AND LITE_WITH_LIGHT_WEIGHT_FRAMEWORK) if (WITH_LITE AND LITE_WITH_LIGHT_WEIGHT_FRAMEWORK)
message(STATUS "Building the mobile framework") message(STATUS "Building the mobile framework")
if (ANDROID)
include(cross_compiling/findar)
endif()
# include the necessary thirdparty dependencies # include the necessary thirdparty dependencies
include(external/gflags) # download, build, install gflags include(external/gflags) # download, build, install gflags
include(external/glog) # download, build, install glog include(external/glog) # download, build, install glog
......
...@@ -31,7 +31,7 @@ if(NOT DEFINED ANDROID_API_LEVEL) ...@@ -31,7 +31,7 @@ if(NOT DEFINED ANDROID_API_LEVEL)
endif() endif()
if(NOT DEFINED ANDROID_STL_TYPE) if(NOT DEFINED ANDROID_STL_TYPE)
set(ANDROID_STL_TYPE "c++_static" CACHE STRING "stl type") set(ANDROID_STL_TYPE "c++_static" CACHE STRING "stl type") # can also use shared
endif() endif()
if(ARM_TARGET_ARCH_ABI STREQUAL "armv7hf") if(ARM_TARGET_ARCH_ABI STREQUAL "armv7hf")
...@@ -71,8 +71,31 @@ if (NOT ANDROID_STL_TYPE IN_LIST ANDROID_STL_TYPE_LITS) ...@@ -71,8 +71,31 @@ if (NOT ANDROID_STL_TYPE IN_LIST ANDROID_STL_TYPE_LITS)
message(FATAL_ERROR "ANDROID_STL_TYPE must be in one of ${ANDROID_STL_TYPE_LITS}") message(FATAL_ERROR "ANDROID_STL_TYPE must be in one of ${ANDROID_STL_TYPE_LITS}")
endif() endif()
if(ARM_TARGET_LANG STREQUAL "gcc")
# gcc do not need set lang
set(ARM_TARGET_LANG "")
endif()
set(CMAKE_SYSTEM_NAME Android) set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION ${ANDROID_API_LEVEL}) set(CMAKE_SYSTEM_VERSION ${ANDROID_API_LEVEL})
set(CMAKE_ANDROID_ARCH_ABI ${ANDROID_ARCH_ABI}) set(CMAKE_ANDROID_ARCH_ABI ${ANDROID_ARCH_ABI})
set(CMAKE_ANDROID_NDK ${ANDROID_NDK}) set(CMAKE_ANDROID_NDK ${ANDROID_NDK})
set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION ${ARM_TARGET_LANG})
set(CMAKE_ANDROID_STL_TYPE ${ANDROID_STL_TYPE}) set(CMAKE_ANDROID_STL_TYPE ${ANDROID_STL_TYPE})
if (ARM_TARGET_LANG STREQUAL "clang")
if(ARM_TARGET_ARCH_ABI STREQUAL "armv8")
set(triple aarch64-v8a-linux-android)
elseif(ARM_TARGET_ARCH_ABI STREQUAL "armv7")
set(triple arm-v7a-linux-android)
else()
message(FATAL_ERROR "Clang do not support this ${ARM_TARGET_ARCH_ABI}, use armv8 or armv7")
endif()
set(CMAKE_C_COMPILER clang)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_COMPILER_TARGET ${triple})
message(STATUS "CMAKE_CXX_COMPILER_TARGET: ${CMAKE_CXX_COMPILER_TARGET}")
endif()
# Copyright (c) 2019 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.
if(NOT ARM_TARGET_LANG STREQUAL "clang")
# only clang need find ar tool
return()
endif()
if(NOT EXISTS "${CMAKE_CXX_COMPILER}")
message(ERROR "Can not find CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER}")
endif()
get_filename_component(AR_PATH ${CMAKE_CXX_COMPILER} PATH)
find_file(AR_TOOL NAMES llvm-ar PATHS ${AR_PATH})
if(NOT AR_TOOL)
message(ERROR "Failed to find AR_TOOL in ${AR_PATH}")
else()
set(CMAKE_AR ${AR_TOOL})
message(STATUS "Found CMAKE_AR : " ${CMAKE_AR})
endif()
...@@ -40,7 +40,8 @@ if(ANDROID) ...@@ -40,7 +40,8 @@ if(ANDROID)
"-DCMAKE_SYSTEM_VERSION=${CMAKE_SYSTEM_VERSION}" "-DCMAKE_SYSTEM_VERSION=${CMAKE_SYSTEM_VERSION}"
"-DCMAKE_ANDROID_ARCH_ABI=${CMAKE_ANDROID_ARCH_ABI}" "-DCMAKE_ANDROID_ARCH_ABI=${CMAKE_ANDROID_ARCH_ABI}"
"-DCMAKE_ANDROID_NDK=${CMAKE_ANDROID_NDK}" "-DCMAKE_ANDROID_NDK=${CMAKE_ANDROID_NDK}"
"-DCMAKE_ANDROID_STL_TYPE=${CMAKE_ANDROID_STL_TYPE}") "-DCMAKE_ANDROID_STL_TYPE=${CMAKE_ANDROID_STL_TYPE}"
"-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=${CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION}" )
endif() endif()
ExternalProject_Add( ExternalProject_Add(
......
...@@ -46,7 +46,8 @@ if(ANDROID) ...@@ -46,7 +46,8 @@ if(ANDROID)
"-DCMAKE_SYSTEM_VERSION=${CMAKE_SYSTEM_VERSION}" "-DCMAKE_SYSTEM_VERSION=${CMAKE_SYSTEM_VERSION}"
"-DCMAKE_ANDROID_ARCH_ABI=${CMAKE_ANDROID_ARCH_ABI}" "-DCMAKE_ANDROID_ARCH_ABI=${CMAKE_ANDROID_ARCH_ABI}"
"-DCMAKE_ANDROID_NDK=${CMAKE_ANDROID_NDK}" "-DCMAKE_ANDROID_NDK=${CMAKE_ANDROID_NDK}"
"-DCMAKE_ANDROID_STL_TYPE=${CMAKE_ANDROID_STL_TYPE}") "-DCMAKE_ANDROID_STL_TYPE=${CMAKE_ANDROID_STL_TYPE}"
"-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=${CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION}")
endif() endif()
ExternalProject_Add( ExternalProject_Add(
......
...@@ -58,7 +58,9 @@ IF(WITH_TESTING OR (WITH_DISTRIBUTE AND NOT WITH_GRPC)) ...@@ -58,7 +58,9 @@ IF(WITH_TESTING OR (WITH_DISTRIBUTE AND NOT WITH_GRPC))
"-DCMAKE_SYSTEM_VERSION=${CMAKE_SYSTEM_VERSION}" "-DCMAKE_SYSTEM_VERSION=${CMAKE_SYSTEM_VERSION}"
"-DCMAKE_ANDROID_ARCH_ABI=${CMAKE_ANDROID_ARCH_ABI}" "-DCMAKE_ANDROID_ARCH_ABI=${CMAKE_ANDROID_ARCH_ABI}"
"-DCMAKE_ANDROID_NDK=${CMAKE_ANDROID_NDK}" "-DCMAKE_ANDROID_NDK=${CMAKE_ANDROID_NDK}"
"-DCMAKE_ANDROID_STL_TYPE=${CMAKE_ANDROID_STL_TYPE}") "-DCMAKE_ANDROID_STL_TYPE=${CMAKE_ANDROID_STL_TYPE}"
"-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=${CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION}"
)
endif() endif()
ExternalProject_Add( ExternalProject_Add(
......
...@@ -199,6 +199,7 @@ FUNCTION(build_protobuf TARGET_NAME BUILD_FOR_HOST) ...@@ -199,6 +199,7 @@ FUNCTION(build_protobuf TARGET_NAME BUILD_FOR_HOST)
"-DCMAKE_ANDROID_ARCH_ABI=${CMAKE_ANDROID_ARCH_ABI}" "-DCMAKE_ANDROID_ARCH_ABI=${CMAKE_ANDROID_ARCH_ABI}"
"-DCMAKE_ANDROID_NDK=${CMAKE_ANDROID_NDK}" "-DCMAKE_ANDROID_NDK=${CMAKE_ANDROID_NDK}"
"-DCMAKE_ANDROID_STL_TYPE=${CMAKE_ANDROID_STL_TYPE}" "-DCMAKE_ANDROID_STL_TYPE=${CMAKE_ANDROID_STL_TYPE}"
"-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=${CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION}"
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}" "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
"-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}" "-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}"
......
if (WITH_TESTING) if (WITH_TESTING)
cc_library(lite_gtest_main SRCS lite_gtest_main.cc DEPS gtest) cc_library(lite_gtest_main SRCS lite_gtest_main.cc DEPS gtest gflags)
endif() endif()
lite_cc_library(target_wrapper_lite SRCS target_wrapper.cc lite_cc_library(target_wrapper_lite SRCS target_wrapper.cc
DEPS target_wrapper_host DEPS target_wrapper_host
......
...@@ -57,6 +57,7 @@ function check_style { ...@@ -57,6 +57,7 @@ function check_style {
function cmake_arm { function cmake_arm {
# $1: ARM_TARGET_OS in "android" , "armlinux" # $1: ARM_TARGET_OS in "android" , "armlinux"
# $2: ARM_TARGET_ARCH_ABI in "armv8", "armv7" ,"armv7hf" # $2: ARM_TARGET_ARCH_ABI in "armv8", "armv7" ,"armv7hf"
# $3: ARM_TARGET_LANG in "gcc" "clang"
cmake .. \ cmake .. \
-DWITH_GPU=OFF \ -DWITH_GPU=OFF \
-DWITH_MKL=OFF \ -DWITH_MKL=OFF \
...@@ -66,7 +67,7 @@ function cmake_arm { ...@@ -66,7 +67,7 @@ function cmake_arm {
-DLITE_WITH_ARM=ON \ -DLITE_WITH_ARM=ON \
-DLITE_WITH_LIGHT_WEIGHT_FRAMEWORK=ON \ -DLITE_WITH_LIGHT_WEIGHT_FRAMEWORK=ON \
-DWITH_TESTING=ON \ -DWITH_TESTING=ON \
-DARM_TARGET_OS=$1 -DARM_TARGET_ARCH_ABI=$2 -DARM_TARGET_OS=$1 -DARM_TARGET_ARCH_ABI=$2 -DARM_TARGET_LANG=$3
} }
function build_single { function build_single {
...@@ -125,31 +126,36 @@ function test_arm_android { ...@@ -125,31 +126,36 @@ function test_arm_android {
function build_test_arm { function build_test_arm {
# 1. Build goes first # 1. Build goes first
cur_dir=$(pwd) cur_dir=$(pwd)
for os in "android" "armlinux" ; do for lang in "gcc" "clang"; do
for abi in "armv8" "armv7" "armv7hf"; do for os in "android" "armlinux" ; do
# TODO(hongming): enable compile armv7 and armv7hf on armlinux if [[ ${os} == "armlinux" && ${lang} == "clang" ]]; then
if [[ ${abi} == "armv7hf" ]]; then
echo "armv7hf is not supported on both android and armlinux yet"
continue continue
fi fi
for abi in "armv8" "armv7" "armv7hf"; do
# TODO(hongming): enable armv7 on armlinux # TODO(hongming): enable compile armv7 and armv7hf on armlinux
if [[ ${os} == "armlinux" && ${abi} == "armv7" ]]; then if [[ ${abi} == "armv7hf" ]]; then
echo "armv7 is not supported on armlinux yet" echo "armv7hf is not supported on both android and armlinux yet"
continue continue
fi fi
if [[ ${os} == "android" && ${abi} == "armv7hf" ]]; then # TODO(hongming): enable armv7 on armlinux
echo "android do not need armv7hf" if [[ ${os} == "armlinux" && ${abi} == "armv7" ]]; then
continue echo "armv7 is not supported on armlinux yet"
fi continue
fi
build_dir=$cur_dir/build.lite.${os}.${abi}
mkdir -p $build_dir if [[ ${os} == "android" && ${abi} == "armv7hf" ]]; then
cd $build_dir echo "android do not need armv7hf"
continue
cmake_arm ${os} ${abi} fi
build $TESTS_FILE
build_dir=$cur_dir/build.lite.${os}.${abi}.${lang}
mkdir -p $build_dir
cd $build_dir
cmake_arm ${os} ${abi} ${lang}
build $TESTS_FILE
done
done done
done done
...@@ -168,26 +174,28 @@ function build_test_arm { ...@@ -168,26 +174,28 @@ function build_test_arm {
sleep 1m sleep 1m
# now can only test android. # now can only test android.
for abi in "armv8" "armv7" ; do for lang in "gcc" "clang"; do
# TODO(yuanshuai): enable armv7 on android for abi in "armv8" "armv7" ; do
if [[ ${abi} == "armv7" ]]; then # TODO(yuanshuai): enable armv7 on android
continue if [[ ${abi} == "armv7" ]]; then
fi continue
fi
build_dir=$cur_dir/build.lite.android.${abi}
cd $build_dir build_dir=$cur_dir/build.lite.android.${abi}.${lang}
cd $build_dir
local port=
if [[ ${abi} == "armv7" ]]; then local port=
port=${port_armv7} if [[ ${abi} == "armv7" ]]; then
fi port=${port_armv7}
fi
if [[ ${abi} == "armv8" ]]; then
port=${port_armv8} if [[ ${abi} == "armv8" ]]; then
fi port=${port_armv8}
echo "test file: ${TESTS_FILE}" fi
for _test in $(cat $TESTS_FILE); do echo "test file: ${TESTS_FILE}"
test_arm_android $_test $port for _test in $(cat $TESTS_FILE); do
test_arm_android $_test $port
done
done done
done done
......
...@@ -26,6 +26,7 @@ $ git checkout incubate/lite ...@@ -26,6 +26,7 @@ $ git checkout incubate/lite
- "armv8", 等效于 "arm64"。 default值为这个。 - "armv8", 等效于 "arm64"。 default值为这个。
- "armv7hf", 等效于使用`eabihf``-march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 ` - "armv7hf", 等效于使用`eabihf``-march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 `
- "armv7", 等效于使用`eabi``-march=armv7-a -mfloat-abi=softfp -mfpu=neon-vfpv4` - "armv7", 等效于使用`eabi``-march=armv7-a -mfloat-abi=softfp -mfpu=neon-vfpv4`
- `ARM_TARGET_LANG` 代表目标编译的语言, 默认为gcc,支持 gcc和clang两种。
### 编译 ### 编译
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册