Colm Donelan | 0aef653 | 2023-10-02 17:01:37 +0100 | [diff] [blame] | 1 | # |
| 2 | # Copyright © 2023 Arm Ltd and Contributors. All rights reserved. |
| 3 | # SPDX-License-Identifier: MIT |
| 4 | # |
| 5 | # Usage: cmake -DARMNN_ROOT=<path to armnn library and includes> |
| 6 | |
| 7 | cmake_minimum_required (VERSION 3.7.0) |
| 8 | project(InterfaceTests) |
| 9 | set(CMAKE_CXX_STANDARD 17) |
| 10 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 11 | |
| 12 | # Reusing the TfLite cmake module from Arm NN. This module should have no |
| 13 | # external dependencies on other parts of Arm NN. Its only required |
| 14 | # parameter is TFLITE_LIB_ROOT |
| 15 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/../../delegate/cmake/Modules/") |
| 16 | |
| 17 | # This is the base path for the Arm NN binary build. The root directory |
| 18 | # contains the library files and also an include directory. |
| 19 | option(ARMNN_ROOT "Location where the Arm NN libraries and 'include' directory can be found" Off) |
| 20 | |
| 21 | # TfLite needs flatbuffers. |
| 22 | option(FLATBUFFERS_ROOT "Location where Flatbuffers include files can be found." Off) |
| 23 | |
| 24 | # To test both delegates we need TfLite. |
| 25 | option(TFLITE_INCLUDE_ROOT "Location where the TfLite includes can be found." Off) |
| 26 | option(TFLITE_LIB_ROOT "Location where the built TfLite libraries can be found." Off) |
| 27 | |
| 28 | |
| 29 | # Locate the Arm NN libraries and includes. |
| 30 | message(STATUS "Arm NN root is set to \"${ARMNN_ROOT}\"") |
| 31 | # Exclude default paths to ensure only the specified path is used. |
| 32 | find_path(ARMNN_LIB_INCLUDE armnn/ArmNN.hpp PATHS ${ARMNN_ROOT}/include NO_DEFAULT_PATH) |
| 33 | message(STATUS "Arm NN library include directory located at: ${ARMNN_LIB_INCLUDE}") |
| 34 | find_library(ARMNN_LIB |
| 35 | NAMES armnn |
| 36 | HINTS ${ARMNN_ROOT}) |
| 37 | message(STATUS "Arm NN library location set to ${ARMNN_LIB}") |
| 38 | |
| 39 | # Arm NN uses pthreads. |
| 40 | find_package(Threads) |
| 41 | |
| 42 | # First test is the use of the Arm NN graph interface. We compile |
| 43 | # SimpleSample into a binary based on the libraries and includes we have |
| 44 | # found. |
| 45 | add_executable(SimpleSample ../../samples/SimpleSample.cpp) |
| 46 | # We're using BEFORE here to ensure no stray system libraries get used first. |
| 47 | target_include_directories(SimpleSample BEFORE PUBLIC ${ARMNN_LIB_INCLUDE}) |
| 48 | target_link_libraries(SimpleSample ${ARMNN_LIB} ${CMAKE_THREAD_LIBS_INIT}) |
| 49 | |
| 50 | # TfLite parser. |
| 51 | find_library(ARMNN_TFLITE_LIB |
| 52 | NAMES armnnTfLiteParser |
| 53 | HINTS ${ARMNN_ROOT}) |
| 54 | add_executable(TfLiteParserTest ./TfLiteParserTest.cpp) |
| 55 | target_include_directories(TfLiteParserTest BEFORE PUBLIC ${ARMNN_LIB_INCLUDE}) |
| 56 | target_link_libraries(TfLiteParserTest ${ARMNN_LIB} ${ARMNN_TFLITE_LIB} ${CMAKE_THREAD_LIBS_INIT}) |
| 57 | |
| 58 | # Onnx parser |
| 59 | find_library(ARMNN_ONNX_LIB |
| 60 | NAMES armnnOnnxParser |
| 61 | HINTS ${ARMNN_ROOT}) |
| 62 | add_executable(OnnxParserTest ./OnnxParserTest.cpp) |
| 63 | target_include_directories(OnnxParserTest BEFORE PUBLIC ${ARMNN_LIB_INCLUDE}) |
| 64 | target_link_libraries(OnnxParserTest ${ARMNN_LIB} ${ARMNN_ONNX_LIB} ${CMAKE_THREAD_LIBS_INIT}) |
| 65 | |
| 66 | |
| 67 | # These next two targets are for our TfLite delegates. The machanism used to |
| 68 | # compile and use them does not confirm to how Tf intends delegates to be |
| 69 | # used. We include these tests to highlight potential missing, or awkwrd, |
| 70 | # includes that could occur. |
| 71 | |
| 72 | # Find Flatbuffers dependency |
| 73 | find_package(Flatbuffers REQUIRED MODULE) |
| 74 | |
| 75 | # Find TfLite libraries and includes. |
| 76 | find_package(TfLite REQUIRED MODULE) |
| 77 | find_path(TFLITE_INCLUDE tensorflow/c/c_api.h PATHS ${TFLITE_INCLUDE_ROOT} NO_DEFAULT_PATH) |
| 78 | |
| 79 | # Classic delegate |
| 80 | find_library(ARMNN_CLASSIC_DELEGATE_LIB |
| 81 | NAMES armnnDelegate |
| 82 | HINTS ${ARMNN_ROOT}) |
| 83 | add_executable(ClassicDelegateTest ./ClassicDelegateTest.cpp) |
| 84 | find_path(ARMNN_COMMON_DELEGATE_INCLUDE DelegateOptions.hpp PATHS ${ARMNN_ROOT}/include/armnnDelegate/armnn/delegate/common/include/ NO_DEFAULT_PATH) |
| 85 | find_path(ARMNN_CLASSIC_DELEGATE_INCLUDE armnn_delegate.hpp PATHS ${ARMNN_ROOT}/include/armnnDelegate/armnn/delegate/classic/include/ NO_DEFAULT_PATH) |
| 86 | target_include_directories(ClassicDelegateTest BEFORE PUBLIC ${ARMNN_LIB_INCLUDE} |
| 87 | ${Flatbuffers_INCLUDE_DIR} |
| 88 | ${TFLITE_INCLUDE} |
| 89 | ${ARMNN_COMMON_DELEGATE_INCLUDE} |
| 90 | ${ARMNN_CLASSIC_DELEGATE_INCLUDE}) |
| 91 | target_link_libraries(ClassicDelegateTest ${TfLite_LIB} |
| 92 | ${ARMNN_CLASSIC_DELEGATE_LIB} |
| 93 | ${ARMNN_LIB} |
| 94 | ${Flatbuffers_LIB} |
| 95 | ${CMAKE_THREAD_LIBS_INIT} |
| 96 | ${CMAKE_DL_LIBS}) |
| 97 | |
| 98 | # Opaque delegate |
| 99 | find_library(ARMNN_OPAQUE_DELEGATE_LIB |
| 100 | NAMES armnnOpaqueDelegate |
| 101 | HINTS ${ARMNN_ROOT}) |
| 102 | # Additional Absl Sync for Opaque Delegate |
| 103 | find_package(TfLiteAbsl REQUIRED MODULE) |
| 104 | |
| 105 | add_executable(OpaqueDelegateTest ./OpaqueDelegateTest.cpp) |
| 106 | find_path(ARMNN_OPAQUE_DELEGATE_INCLUDE armnn_delegate.hpp PATHS ${ARMNN_ROOT}/include/armnnDelegate/armnn/delegate/opaque/include/ NO_DEFAULT_PATH) |
| 107 | # delegate_registry.h happens to use a ABSL mutex. We need to find and add its path too. |
| 108 | find_path(TFLITE_ABSL_INCLUDE absl/synchronization/mutex.h PATHS ${TFLITE_LIB_ROOT}/abseil-cpp/ NO_DEFAULT_PATH) |
| 109 | target_include_directories(OpaqueDelegateTest BEFORE PUBLIC ${ARMNN_LIB_INCLUDE} |
| 110 | ${Flatbuffers_INCLUDE_DIR} |
| 111 | ${TFLITE_INCLUDE} |
| 112 | ${TFLITE_ABSL_INCLUDE} |
| 113 | ${ARMNN_COMMON_DELEGATE_INCLUDE} |
| 114 | ${ARMNN_OPAQUE_DELEGATE_INCLUDE}) |
| 115 | target_link_libraries(OpaqueDelegateTest ${ARMNN_OPAQUE_DELEGATE_LIB} |
| 116 | ${ARMNN_LIB} |
| 117 | ${TfLite_Extra_Absl_LIB} |
| 118 | ${TfLite_LIB} |
| 119 | ${Flatbuffers_LIB} |
| 120 | ${CMAKE_THREAD_LIBS_INIT} |
| 121 | ${CMAKE_DL_LIBS}) |