diff --git a/cmake/bm.cmake b/cmake/bm.cmake new file mode 100644 index 0000000000000000000000000000000000000000..567cee077e19126c8f986bc7b1b759dd43a379c1 --- /dev/null +++ b/cmake/bm.cmake @@ -0,0 +1,75 @@ +# 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 LITE_WITH_BM) + return() +endif() + +if(NOT DEFINED BM_SDK_ROOT) + set(BM_SDK_ROOT $ENV{BM_SDK_ROOT}) + if(NOT BM_SDK_ROOT) + message(FATAL_ERROR "Must set BM_SDK_ROOT or env BM_SDK_ROOT when LITE_WITH_BM=ON") + endif() +endif() + +message(STATUS "BM_SDK_ROOT: ${BM_SDK_ROOT}") +find_path(BM_SDK_INC NAMES bmruntime_interface.h + PATHS ${BM_SDK_ROOT}/include/bmruntime NO_DEFAULT_PATH) +if(NOT BM_SDK_INC) + message(FATAL_ERROR "Can not find bmruntime_interface.h in ${BM_SDK_ROOT}/include") +endif() + +include_directories("${BM_SDK_ROOT}/include") +include_directories("${BM_SDK_ROOT}/include/bmruntime") +include_directories("${BM_SDK_ROOT}/include/bmlib") + +find_library(BM_SDK_RT_LIB NAMES bmrt + PATHS ${BM_SDK_ROOT}/lib/app) +if(NOT BM_SDK_RT_LIB) + message(FATAL_ERROR "Can not find bmrt Library in ${BM_SDK_ROOT}") +else() + message(STATUS "Found bmrt Library: ${BM_SDK_RT_LIB}") + add_library(bmrt SHARED IMPORTED GLOBAL) + set_property(TARGET bmrt PROPERTY IMPORTED_LOCATION ${BM_SDK_RT_LIB}) +endif() + +find_library(BM_SDK_BM_LIB NAMES bmlib + PATHS ${BM_SDK_ROOT}/lib/app) +if(NOT BM_SDK_BM_LIB) + message(FATAL_ERROR "Can not find bmlib Library in ${BM_SDK_ROOT}") +else() + message(STATUS "Found bmlib Library: ${BM_SDK_BM_LIB}") + add_library(bmlib SHARED IMPORTED GLOBAL) + set_property(TARGET bmlib PROPERTY IMPORTED_LOCATION ${BM_SDK_BM_LIB}) +endif() + +find_library(BM_SDK_COMPILER_LIB NAMES bmcompiler + PATHS ${BM_SDK_ROOT}/lib/bmcompiler) +if(NOT BM_SDK_COMPILER_LIB) + message(FATAL_ERROR "Can not find bmcompiler Library in ${BM_SDK_ROOT}") +else() + message(STATUS "Found bmcompiler Library: ${BM_SDK_COMPILER_LIB}") + add_library(bmcompiler SHARED IMPORTED GLOBAL) + set_property(TARGET bmcompiler PROPERTY IMPORTED_LOCATION ${BM_SDK_COMPILER_LIB}) +endif() + +find_library(BM_SDK_CPU_LIB NAMES bmcpu + PATHS ${BM_SDK_ROOT}/lib/bmcpu) +if(NOT BM_SDK_CPU_LIB) + message(FATAL_ERROR "Can not find bmcpu Library in ${BM_SDK_ROOT}") +else() + message(STATUS "Found bmcpu Library: ${BM_SDK_CPU_LIB}") + add_library(bmcpu SHARED IMPORTED GLOBAL) + set_property(TARGET bmcpu PROPERTY IMPORTED_LOCATION ${BM_SDK_CPU_LIB}) +endif() diff --git a/lite/tools/build_bm.sh b/lite/tools/build_bm.sh index cec934738c8d9877e18e1aba0fb39e534987e9f6..c3a7287b6ee06eb08b72baced710e115460394f2 100755 --- a/lite/tools/build_bm.sh +++ b/lite/tools/build_bm.sh @@ -2,10 +2,10 @@ set -ex # global variables with default value -XPU_SDK_ROOT="$(pwd)/../BM_SDK" # BM SDK -TARGET_NAME="lite_compile_deps" # default target -BUILD_EXTRA=ON # ON(with sequence ops)/OFF -WITH_TESTING=ON # ON/OFF +BM_SDK_ROOT="$(pwd)/../BM_SDK" # BM SDK +TARGET_NAME="BM1682" # default target +BUILD_EXTRA=OFF # ON(with sequence ops)/OFF +WITH_TESTING=OFF # ON/OFF function print_usage { echo -e "\nUSAGE:" @@ -23,7 +23,7 @@ readonly CMAKE_COMMON_OPTIONS="-DWITH_LITE=ON \ -DWITH_PYTHON=OFF \ -DLITE_WITH_ARM=OFF" -readonly NUM_CORES_FOR_COMPILE=${LITE_BUILD_THREADS:-1} +readonly NUM_CORES_FOR_COMPILE=${LITE_BUILD_THRLITE_BUILD_THREADSEADS:-1} readonly THIRDPARTY_TAR=https://paddle-inference-dist.bj.bcebos.com/PaddleLite/third-party-05b862.tar.gz readonly workspace=$(pwd) @@ -74,8 +74,9 @@ function build_bm { -DWITH_MKL=OFF \ -DLITE_BUILD_EXTRA=OFF \ -DLITE_WITH_XPU=OFF \ + -DLITE_WITH_BM=ON \ -DWITH_TESTING=${WITH_TESTING} \ - -DXPU_SDK_ROOT=${XPU_SDK_ROOT} + -DBM_SDK_ROOT=${BM_SDK_ROOT} make $TARGET_NAME -j$NUM_CORES_FOR_COMPILE @@ -91,15 +92,11 @@ function main { TARGET_NAME="${i#*=}" shift ;; - --build_extra=*) - BUILD_EXTRA="${i#*=}" - shift - ;; - --xpu_sdk_root=*) + --bm_sdk_root=*) BM_SDK_ROOT="${i#*=}" shift ;; - build) + bm) build_bm shift ;;