bm.cmake 2.9 KB
Newer Older
B
baolei.an 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
# 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/bmruntime")
include_directories("${BM_SDK_ROOT}/include/bmlib")
R
root 已提交
35 36
include_directories("${BM_SDK_ROOT}/include/bmcompiler")
include_directories("${BM_SDK_ROOT}/include/bmcpu")
B
baolei.an 已提交
37 38

find_library(BM_SDK_RT_LIB NAMES bmrt
R
root 已提交
39
  PATHS ${BM_SDK_ROOT}/lib/bmnn/pcie)
B
baolei.an 已提交
40 41 42 43 44 45 46 47 48
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
R
root 已提交
49
  PATHS ${BM_SDK_ROOT}/lib/bmnn/pcie)
B
baolei.an 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
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
R
root 已提交
69
  PATHS ${BM_SDK_ROOT}/lib/bmnn/pcie)
B
baolei.an 已提交
70 71 72 73 74 75 76
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()
C
cen.li 已提交
77 78 79

set(bm_runtime_libs bmrt bmlib bmcompiler bmcpu CACHE INTERNAL "bm runtime libs")
set(bm_builder_libs bmrt bmlib bmcompiler bmcpu CACHE INTERNAL "bm builder libs")