npu.cmake 2.8 KB
Newer Older
Y
Yan Chunwei 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# 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_NPU)
  return()
endif()

if(NOT DEFINED NPU_DDK_ROOT)
20 21 22 23
  set(NPU_DDK_ROOT $ENV{NPU_DDK_ROOT})
  if(NOT NPU_DDK_ROOT)
    message(FATAL_ERROR "Must set NPU_DDK_ROOT or env NPU_DDK_ROOT when LITE_WITH_NPU=ON")
  endif()
Y
Yan Chunwei 已提交
24 25 26 27
endif()

message(STATUS "NPU_DDK_ROOT: ${NPU_DDK_ROOT}")
find_path(NPU_DDK_INC NAMES HiAiModelManagerService.h
28 29
  PATHS ${NPU_DDK_ROOT}/include
  NO_DEFAULT_PATH)
Y
Yan Chunwei 已提交
30 31 32 33
if(NOT NPU_DDK_INC)
  message(FATAL_ERROR "Can not find HiAiModelManagerService.h in ${NPU_DDK_ROOT}/include")
endif()

34
include_directories("${NPU_DDK_ROOT}/include")
Y
Yan Chunwei 已提交
35

36 37
set(NPU_SUB_LIB_PATH "lib64")
if(ARM_TARGET_ARCH_ABI STREQUAL "armv8")
38
  set(NPU_SUB_LIB_PATH "lib64")
39 40 41
endif()

if(ARM_TARGET_ARCH_ABI STREQUAL "armv7")
42
  set(NPU_SUB_LIB_PATH "lib")
43 44
endif()

Y
Yan Chunwei 已提交
45
find_library(NPU_DDK_HIAI_FILE NAMES hiai
46 47
  PATHS ${NPU_DDK_ROOT}/${NPU_SUB_LIB_PATH}
  NO_DEFAULT_PATH)
Y
Yan Chunwei 已提交
48 49

find_library(NPU_DDK_IR_FILE NAMES hiai_ir
50 51
  PATHS ${NPU_DDK_ROOT}/${NPU_SUB_LIB_PATH}
  NO_DEFAULT_PATH)
Y
Yan Chunwei 已提交
52 53

find_library(NPU_DDK_IR_BUILD_FILE NAMES hiai_ir_build
54 55
  PATHS ${NPU_DDK_ROOT}/${NPU_SUB_LIB_PATH}
  NO_DEFAULT_PATH)
56

Y
Yan Chunwei 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
if(NOT NPU_DDK_HIAI_FILE)
  message(FATAL_ERROR "Can not find NPU_DDK_HIAI_FILE in ${NPU_DDK_ROOT}")
else()
  message(STATUS "Found NPU_DDK HIAI Library: ${NPU_DDK_HIAI_FILE}")
  add_library(npu_ddk_hiai SHARED IMPORTED GLOBAL)
  set_property(TARGET npu_ddk_hiai PROPERTY IMPORTED_LOCATION ${NPU_DDK_HIAI_FILE})
endif()

if(NOT NPU_DDK_IR_FILE)
  message(FATAL_ERROR "Can not find NPU_DDK_IR_FILE in ${NPU_DDK_ROOT}")
else()
  message(STATUS "Found NPU_DDK IR Library: ${NPU_DDK_IR_FILE}")
  add_library(npu_ddk_ir SHARED IMPORTED GLOBAL)
  set_property(TARGET npu_ddk_ir PROPERTY IMPORTED_LOCATION ${NPU_DDK_IR_FILE})
endif()

if(NOT NPU_DDK_IR_BUILD_FILE)
  message(FATAL_ERROR "Can not find NPU_DDK_IR_BUILD_FILE in ${NPU_DDK_ROOT}")
else()
  message(STATUS "Found NPU_DDK IR_BUILD Library: ${NPU_DDK_IR_BUILD_FILE}")
  add_library(npu_ddk_ir_build SHARED IMPORTED GLOBAL)
  set_property(TARGET npu_ddk_ir_build PROPERTY IMPORTED_LOCATION ${NPU_DDK_IR_BUILD_FILE})
endif()

81 82
set(npu_runtime_libs npu_ddk_hiai CACHE INTERNAL "npu ddk runtime libs")
set(npu_builder_libs npu_ddk_ir npu_ddk_ir_build CACHE INTERNAL "npu ddk builder libs")