Kristofer Jonsson | 1823930 | 2020-04-17 08:45:38 +0200 | [diff] [blame] | 1 | # |
| 2 | # Copyright (c) 2019-2020 Arm Limited. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the License); you may |
| 7 | # not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | |
| 19 | include(ProcessorCount) |
| 20 | ProcessorCount(J) |
| 21 | |
Per Åstrand | 3f6e07a | 2020-05-12 13:16:37 +0200 | [diff] [blame] | 22 | if (CMAKE_CXX_COMPILER_ID STREQUAL "ARMClang") |
Måns Nilsson | 1aa56dd | 2020-09-17 15:38:58 +0200 | [diff] [blame] | 23 | set(TFLU_TOOLCHAIN "armclang") |
Per Åstrand | 3f6e07a | 2020-05-12 13:16:37 +0200 | [diff] [blame] | 24 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
Måns Nilsson | 1aa56dd | 2020-09-17 15:38:58 +0200 | [diff] [blame] | 25 | set(TFLU_TOOLCHAIN "gcc") |
Per Åstrand | 3f6e07a | 2020-05-12 13:16:37 +0200 | [diff] [blame] | 26 | else () |
| 27 | message(FATAL_ERROR "No compiler ID is set") |
| 28 | endif() |
Kristofer Jonsson | 1823930 | 2020-04-17 08:45:38 +0200 | [diff] [blame] | 29 | |
Måns Nilsson | 1aa56dd | 2020-09-17 15:38:58 +0200 | [diff] [blame] | 30 | |
| 31 | get_filename_component(TFLU_TARGET_TOOLCHAIN_ROOT ${CMAKE_C_COMPILER} DIRECTORY) |
| 32 | |
| 33 | set(TFLU_TARGET_TOOLCHAIN_ROOT "${TFLU_TARGET_TOOLCHAIN_ROOT}/") |
Kristofer Jonsson | 1823930 | 2020-04-17 08:45:38 +0200 | [diff] [blame] | 34 | set(TFLU_PATH "${TENSORFLOW_PATH}/tensorflow/lite/micro") |
| 35 | set(TFLU_GENDIR ${CMAKE_CURRENT_BINARY_DIR}/tensorflow/) |
Måns Nilsson | 1aa56dd | 2020-09-17 15:38:58 +0200 | [diff] [blame] | 36 | set(TFLU_TARGET "cortex_m_generic") |
Kristofer Jonsson | 1823930 | 2020-04-17 08:45:38 +0200 | [diff] [blame] | 37 | set(TFLU_TARGET_ARCH ${CMAKE_SYSTEM_PROCESSOR}${CPU_FEATURES}) |
Henrik Hoglind | 3598ef8 | 2020-05-28 12:09:04 +0200 | [diff] [blame] | 38 | set(TFLU_BUILD_TYPE "release" CACHE STRING "Tensorflow Lite Mirco build type, can be release or debug") |
Jonas Skog | 101ccef | 2020-09-10 08:58:16 +0200 | [diff] [blame] | 39 | set(TFLU_OPTIMIZATION_LEVEL CACHE STRING "Tensorflow Lite Micro optimization level") |
Kristofer Jonsson | 1823930 | 2020-04-17 08:45:38 +0200 | [diff] [blame] | 40 | |
Per Åstrand | 94ca355 | 2020-06-30 10:33:58 +0200 | [diff] [blame] | 41 | if(CORE_SOFTWARE_ACCELERATOR STREQUAL NPU) |
| 42 | set(TFLU_ETHOSU_LIBS $<TARGET_FILE:ethosu_core_driver>) |
Måns Nilsson | 98e379c | 2020-09-14 16:30:56 +0200 | [diff] [blame] | 43 | # Set preference for ethos-u over cmsis-nn |
| 44 | list(APPEND TFLU_TAGS "cmsis-nn") |
Henrik Hoglind | 43fd4de | 2020-05-08 14:18:26 +0200 | [diff] [blame] | 45 | list(APPEND TFLU_TAGS "ethos-u") |
Per Åstrand | 94ca355 | 2020-06-30 10:33:58 +0200 | [diff] [blame] | 46 | elseif(CORE_SOFTWARE_ACCELERATOR STREQUAL CMSIS-NN) |
| 47 | list(APPEND TFLU_TAGS "cmsis-nn") |
Kristofer Jonsson | 1823930 | 2020-04-17 08:45:38 +0200 | [diff] [blame] | 48 | endif() |
| 49 | |
| 50 | string(JOIN TFLU_TAGS " " TFLU_TAGS) |
| 51 | |
| 52 | # Command and target |
| 53 | add_custom_target(tflu_gen ALL |
Kristofer Jonsson | d273d8e | 2020-10-13 09:35:55 +0200 | [diff] [blame] | 54 | COMMAND make -j${J} -f ${TFLU_PATH}/tools/make/Makefile microlite |
Måns Nilsson | 1aa56dd | 2020-09-17 15:38:58 +0200 | [diff] [blame] | 55 | TARGET_TOOLCHAIN_ROOT=${TFLU_TARGET_TOOLCHAIN_ROOT} |
| 56 | TOOLCHAIN=${TFLU_TOOLCHAIN} |
Kristofer Jonsson | d273d8e | 2020-10-13 09:35:55 +0200 | [diff] [blame] | 57 | GENDIR=${TFLU_GENDIR} |
| 58 | TARGET=${TFLU_TARGET} |
| 59 | TARGET_ARCH=${TFLU_TARGET_ARCH} |
| 60 | TAGS="${TFLU_TAGS}" |
Kristofer Jonsson | d273d8e | 2020-10-13 09:35:55 +0200 | [diff] [blame] | 61 | $<$<BOOL:${FLOAT}>:FLOAT=${FLOAT}> |
| 62 | BUILD_TYPE=${TFLU_BUILD_TYPE} |
| 63 | $<$<BOOL:${TFLU_OPTIMIZATION_LEVEL}>:OPTIMIZATION_LEVEL=${TFLU_OPTIMIZATION_LEVEL}> |
| 64 | CMSIS_PATH=${CMSIS_PATH} |
| 65 | ETHOSU_DRIVER_PATH=${CORE_DRIVER_PATH} |
| 66 | ETHOSU_DRIVER_LIBS=${TFLU_ETHOSU_LIBS} |
Per Åstrand | 69c6aa9 | 2020-10-12 10:55:52 +0200 | [diff] [blame] | 67 | BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/tensorflow/lite/micro/tools/make/downloads |
Kristofer Jonsson | 1823930 | 2020-04-17 08:45:38 +0200 | [diff] [blame] | 68 | WORKING_DIRECTORY ${TENSORFLOW_PATH}) |
| 69 | |
| 70 | # Create library and link library to custom target |
| 71 | add_library(tflu STATIC IMPORTED) |
| 72 | set_property(TARGET tflu PROPERTY IMPORTED_LOCATION ${TFLU_GENDIR}/lib/libtensorflow-microlite.a) |
| 73 | add_dependencies(tflu tflu_gen) |
| 74 | target_include_directories(tflu INTERFACE ${TENSORFLOW_PATH}) |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 75 | target_compile_definitions(tflu INTERFACE TF_LITE_STATIC_MEMORY) |
Bhavik Patel | 50aa51d | 2020-07-27 17:23:31 +0200 | [diff] [blame] | 76 | |
Henrik Hoglind | 78f7f94 | 2020-10-29 10:12:15 +0100 | [diff] [blame] | 77 | if(CORE_SOFTWARE_ACCELERATOR STREQUAL NPU) |
| 78 | target_link_libraries(tflu INTERFACE ethosu_core_driver) |
| 79 | endif() |
| 80 | |
Bhavik Patel | 50aa51d | 2020-07-27 17:23:31 +0200 | [diff] [blame] | 81 | # Install libraries and header files |
| 82 | get_target_property(TFLU_IMPORTED_LOCATION tflu IMPORTED_LOCATION) |
| 83 | install(FILES ${TFLU_IMPORTED_LOCATION} DESTINATION "lib") |