alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 1 | #---------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2021 Arm Limited. All rights reserved. |
| 3 | # SPDX-License-Identifier: Apache-2.0 |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | #---------------------------------------------------------------------------- |
| 17 | # minimum version of cmake = 3.15 for legit reason: |
| 18 | # armclang support doesn't work work in previous releases |
| 19 | cmake_minimum_required(VERSION 3.15.0) |
| 20 | |
| 21 | # Build in release mode by default |
| 22 | if (NOT CMAKE_BUILD_TYPE STREQUAL Debug) |
| 23 | set(CMAKE_BUILD_TYPE Release CACHE INTERNAL "") |
| 24 | endif() |
| 25 | |
| 26 | message(STATUS "Build type is set to ${CMAKE_BUILD_TYPE}") |
| 27 | |
| 28 | # Set language standards. TensorFlow Lite requires |
| 29 | # std=c++11. |
| 30 | set(CMAKE_C_STANDARD 99) |
| 31 | set(CMAKE_CXX_STANDARD 11) |
| 32 | |
| 33 | # Make the standard a requirement => prevent fallback to previous |
| 34 | # supported standard |
| 35 | set(CMAKE_C_STANDARD_REQUIRED ON) |
| 36 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 37 | |
| 38 | # We want to pass standard C/C++ flags, without gnu extensions |
| 39 | set(CMAKE_C_EXTENSIONS OFF) |
| 40 | set(CMAKE_CXX_EXTENSIONS OFF) |
| 41 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 42 | set(CMAKE_SCRIPTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake) |
| 43 | set(DOWNLOAD_DEP_DIR ${CMAKE_BINARY_DIR}/dependencies) |
| 44 | set(CMAKE_TOOLCHAIN_DIR ${CMAKE_SCRIPTS_DIR}/toolchains) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 45 | |
Kshitij Sisodia | ddcb56d | 2021-05-11 14:46:01 +0100 | [diff] [blame] | 46 | set(RESOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/resources_downloaded |
| 47 | CACHE PATH "Resources directory") |
| 48 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 49 | include(${CMAKE_SCRIPTS_DIR}/source_gen_utils.cmake) |
| 50 | include(${CMAKE_SCRIPTS_DIR}/util_functions.cmake) |
| 51 | |
| 52 | if (${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_SOURCE_DIR}) |
| 53 | message(FATAL_ERROR "Source and build are in the same directory") |
| 54 | else() |
| 55 | message(STATUS "Source directory: ${CMAKE_SOURCE_DIR}") |
| 56 | message(STATUS "Binary directory: ${CMAKE_BINARY_DIR}") |
| 57 | endif() |
| 58 | |
| 59 | USER_OPTION(LOG_LEVEL "Log level for the application" |
| 60 | LOG_LEVEL_INFO |
| 61 | STRING) |
| 62 | |
| 63 | USER_OPTION(TENSORFLOW_SRC_PATH "Path to the root of the tensor flow directory" |
| 64 | "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/tensorflow" |
| 65 | PATH) |
| 66 | |
| 67 | USER_OPTION(TARGET_PLATFORM "Target platform to execute evaluation application: mps3, simple_platform, native" |
| 68 | mps3 |
| 69 | STRING) |
| 70 | |
alexander | d580eee | 2021-05-04 21:24:22 +0100 | [diff] [blame] | 71 | USER_OPTION(TARGET_SUBSYSTEM "Specify platform target subsystem: sse-300 or none" |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 72 | sse-300 |
| 73 | STRING) |
| 74 | |
| 75 | USER_OPTION(ETHOS_U55_ENABLED "Select if Ethos-U55 is available for the platform and subsystem" |
| 76 | ON |
| 77 | BOOL) |
| 78 | |
| 79 | USER_OPTION(USE_CASE_BUILD "Optional. Defines the use-case to build from the available sources. By default, all use-cases are built." |
| 80 | all |
| 81 | STRING) |
| 82 | |
| 83 | USER_OPTION(CPU_PROFILE_ENABLED "Output CPU performance profiling information. Should be used only for MPS3 board." |
| 84 | OFF |
| 85 | BOOL) |
| 86 | |
| 87 | if (TARGET_PLATFORM STREQUAL mps3) |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 88 | message(STATUS "Platform: MPS3 FPGA Prototyping Board or FVP") |
| 89 | set(DEFAULT_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_DIR}/bare-metal-gcc.cmake) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 90 | elseif (TARGET_PLATFORM STREQUAL simple_platform) |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 91 | message(STATUS "Platform: Simple platform with minimal peripherals") |
| 92 | set(DEFAULT_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_DIR}/bare-metal-gcc.cmake) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 93 | elseif (TARGET_PLATFORM STREQUAL native) |
| 94 | message(STATUS "Platform: Native (Linux based x86_64/aarch64 system)") |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 95 | set(DEFAULT_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_DIR}/native-gcc.cmake) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 96 | else () |
| 97 | message(FATAL_ERROR "Invalid platform specified: ${TARGET_PLATFORM}") |
| 98 | endif () |
| 99 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 100 | if (NOT DEFINED CMAKE_TOOLCHAIN_FILE) |
| 101 | set(CMAKE_TOOLCHAIN_FILE ${DEFAULT_TOOLCHAIN_FILE} |
| 102 | CACHE FILEPATH "Toolchain file") |
| 103 | endif() |
| 104 | message(STATUS "Using CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}") |
| 105 | |
| 106 | project(arm_ml_embedded_evaluation_kit |
| 107 | VERSION 21.05 |
| 108 | DESCRIPTION "ARM ML Embedded Evaluation Kit for MPS3 FPGA and FastModel") |
| 109 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 110 | enforce_compiler_version() |
| 111 | setup_source_generator() |
| 112 | |
| 113 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 114 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 115 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
| 116 | set(SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/source) |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 117 | set(TEST_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/tests) |
| 118 | list(APPEND USE_CASES_TESTS_SEARCH_DIR_LIST ${TEST_SRCS}/use_case) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 119 | |
| 120 | if (CPU_PROFILE_ENABLED) |
| 121 | set(PROFILING_OPT "${PROFILING_OPT} -DCPU_PROFILE_ENABLED") |
| 122 | endif() |
| 123 | |
| 124 | # Include platform specific sources |
| 125 | if (TARGET_PLATFORM STREQUAL native) |
| 126 | set(PLATFORM_SOURCES_CMAKE_FILE ${CMAKE_SCRIPTS_DIR}/${TARGET_PLATFORM}-sources.cmake) |
| 127 | else () |
| 128 | set(PLATFORM_SOURCES_CMAKE_FILE ${CMAKE_SCRIPTS_DIR}/bare-metal-sources.cmake) |
| 129 | |
| 130 | USER_OPTION(CMSIS_SRC_PATH |
| 131 | "Path to CMSIS-5 sources" |
| 132 | "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/cmsis" |
| 133 | PATH |
| 134 | ) |
| 135 | |
| 136 | if (CMAKE_BUILD_TYPE STREQUAL Debug AND CMAKE_CXX_COMPILER_ID STREQUAL ARMClang) |
| 137 | USER_OPTION(ARMCLANG_DEBUG_DWARF_LEVEL |
| 138 | "Dwarf conformance level for armclang toolchain" |
| 139 | "4" # Default = 4 (Arm-DS etc). For model debugger specify "3" |
| 140 | STRING |
| 141 | ) |
| 142 | elseif (DEFINED ARMCLANG_DEBUG_DWARF_LEVEL) |
| 143 | message(WARNING "ARMCLANG_DEBUG_DWARF_LEVEL definition is unsupported" |
| 144 | "within current configuration. Removing definition...") |
| 145 | unset(ARMCLANG_DEBUG_DWARF_LEVEL CACHE) |
| 146 | endif() |
| 147 | |
| 148 | endif () |
| 149 | message(STATUS "Including ${PLATFORM_SOURCES_CMAKE_FILE}") |
| 150 | include(${PLATFORM_SOURCES_CMAKE_FILE}) |
| 151 | |
| 152 | if (${CMAKE_CROSSCOMPILING}) |
| 153 | enable_language(ASM) |
| 154 | |
| 155 | # For non-native builds, we build with CMSIS-DSP support. |
| 156 | include(${CMAKE_SCRIPTS_DIR}/cmsis-dsp.cmake) |
| 157 | |
| 158 | # All CMSIS headers to be used: |
| 159 | set(CMSIS_HEADERS |
| 160 | ${CMSIS_DSP_INC_DIR} |
| 161 | ${CMSIS_CORE_INC_DIR} |
| 162 | ${CMSIS_SRC_PATH}/Device/ARM/ARMCM55/Include |
| 163 | ${CMSIS_SRC_PATH}/Device/ARM/ARMCM55/Include/Template) |
| 164 | endif () |
| 165 | |
| 166 | # If we need NPU libraries: |
| 167 | if (ETHOS_U55_ENABLED) |
| 168 | |
| 169 | message(STATUS "Using ARM Ethos-U55 - adding core-driver and timing-adapter-driver includes and libraries") |
| 170 | USER_OPTION(ETHOS_U55_TIMING_ADAPTER_SRC_PATH |
| 171 | "Path to Ethos-U55 timing adapter sources" |
| 172 | "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/core-software/drivers/timing_adapter" |
| 173 | PATH |
| 174 | ) |
| 175 | |
| 176 | USER_OPTION(ETHOS_U55_DRIVER_SRC_PATH |
| 177 | "Path to Ethos-U55 core driver sources" |
| 178 | "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/core_driver" |
| 179 | PATH |
| 180 | ) |
| 181 | |
| 182 | include_directories("${ETHOS_U55_TIMING_ADAPTER_SRC_PATH}/include/") |
| 183 | |
| 184 | add_subdirectory("${ETHOS_U55_TIMING_ADAPTER_SRC_PATH}" ${CMAKE_BINARY_DIR}/timing-adapter) |
| 185 | |
| 186 | set(ETHOSU_INCLUDES ${ETHOS_U55_TIMING_ADAPTER_SRC_PATH}/include |
| 187 | ${ETHOS_U55_DRIVER_SRC_PATH}/include) |
| 188 | |
| 189 | list(APPEND ETHOS_U55_LIBS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libtiming_adapter.a) |
| 190 | endif () |
| 191 | |
| 192 | include(${CMAKE_SCRIPTS_DIR}/tensorflow.cmake) |
| 193 | |
| 194 | set(DEP_TENSORFLOW_LITE_MICRO_SUB_DIR ${TENSORFLOW_SRC_PATH}/tensorflow/lite/micro) |
| 195 | set(DEP_TENSORFLOW_LITE_MICRO_MAKE_DIR ${DEP_TENSORFLOW_LITE_MICRO_SUB_DIR}/tools/make/targets) |
| 196 | set(DEP_FLATBUF_INCLUDE ${DEP_TENSORFLOW_LITE_MICRO_SUB_DIR}/tools/make/downloads/flatbuffers/include) |
| 197 | |
| 198 | set(TENSORFLOW_LIBRARY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME}) |
| 199 | |
| 200 | set(DEP_TF_INCLUDE_DIRS |
| 201 | ${TENSORFLOW_SRC_PATH} |
| 202 | ${DEP_TENSORFLOW_LITE_MICRO_SUB_DIR} |
| 203 | ${ETHOSU_INCLUDES} |
| 204 | ${CMSIS_HEADERS} |
| 205 | ) |
| 206 | |
| 207 | ## All TPIP includes |
| 208 | set(DEP_RUNTIME_INCLUDE_DIRS |
| 209 | ${DEP_TF_INCLUDE_DIRS} |
| 210 | ${DEP_FLATBUF_INCLUDE} |
| 211 | ) |
| 212 | |
| 213 | # Our entry point into tensorflow world: |
| 214 | file(GLOB_RECURSE SRC_TENSORFLOW_LITE_MICRO |
| 215 | ${SRC_PATH}/application/tensorflow-lite-micro/**/*.cc |
| 216 | ${SRC_PATH}/application/tensorflow-lite-micro/*.cc |
| 217 | ) |
| 218 | |
| 219 | set(HAL_DIR ${SRC_PATH}/application/hal) |
| 220 | |
| 221 | # HAL API sources |
| 222 | file(GLOB_RECURSE SRC_HAL |
| 223 | "${HAL_DIR}/hal.c" |
| 224 | ) |
| 225 | |
| 226 | # Set platform specific HAL sources; these should be provided |
| 227 | # by each platform's cmake include file |
| 228 | list(APPEND SRC_HAL ${SRC_PLAT_HAL}) |
| 229 | |
| 230 | # Include directories: |
| 231 | set(APPLICATION_INCLUDE_DIRS |
| 232 | ${HAL_DIR}/include |
| 233 | ${SRC_PATH}/application/tensorflow-lite-micro/include |
| 234 | ${SRC_PATH}/application/main/include |
| 235 | ${PLAT_INCLUDE_DIRS} |
| 236 | ) |
| 237 | |
| 238 | file(GLOB_RECURSE SRC_APPLICATION |
| 239 | "${SRC_PATH}/application/main/*.cc" |
| 240 | "${SRC_PATH}/application/main/*.cpp" |
| 241 | "${SRC_PATH}/application/main/*.c" |
| 242 | "${SRC_PATH}/application/main/**/*.cc" |
| 243 | "${SRC_PATH}/application/main/**/*.cpp" |
| 244 | "${SRC_PATH}/application/main/**/*.c" |
| 245 | ) |
| 246 | list(FILTER SRC_APPLICATION EXCLUDE REGEX ".*main\\.c.*$") |
| 247 | |
| 248 | list(JOIN USE_CASE_BUILD "" USE_CASE_BUILD_STR) |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 249 | list(APPEND USE_CASES_SEARCH_DIR_LIST ${SRC_PATH}/use_case) |
| 250 | message(STATUS "Use-cases source paths: ${USE_CASES_SEARCH_DIR_LIST}.") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 251 | if (${USE_CASE_BUILD_STR} STREQUAL all) |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 252 | foreach(USE_CASES_SEARCH_DIR ${USE_CASES_SEARCH_DIR_LIST}) |
| 253 | SUBDIRLIST(USE_CASES_SUBDIRS ${USE_CASES_SEARCH_DIR}) |
| 254 | list(APPEND USE_CASES ${USE_CASES_SUBDIRS}) |
| 255 | endforeach() |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 256 | else() |
| 257 | set(USE_CASES ${USE_CASE_BUILD}) |
| 258 | endif() |
| 259 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 260 | if (NOT ${CMAKE_CROSSCOMPILING}) |
| 261 | |
| 262 | #Test TPIP |
| 263 | set(TEST_TPIP ${DOWNLOAD_DEP_DIR}/test) |
| 264 | file(MAKE_DIRECTORY ${TEST_TPIP}) |
| 265 | set(TEST_TPIP_INCLUDE ${TEST_TPIP}/include) |
| 266 | file(MAKE_DIRECTORY ${TEST_TPIP_INCLUDE}) |
| 267 | |
| 268 | include(ExternalProject) |
| 269 | |
| 270 | ExternalProject_Add(catch2-headers |
| 271 | URL https://github.com/catchorg/Catch2/releases/download/v2.11.1/catch.hpp |
| 272 | DOWNLOAD_NO_EXTRACT 1 |
| 273 | CONFIGURE_COMMAND "" |
| 274 | BUILD_COMMAND bash -c "cp -R <DOWNLOAD_DIR>/catch.hpp ${TEST_TPIP_INCLUDE}" |
| 275 | INSTALL_COMMAND "" |
| 276 | ) |
| 277 | endif () |
| 278 | |
| 279 | message(STATUS "Building use-cases: ${USE_CASES}.") |
| 280 | foreach(use_case ${USE_CASES}) |
| 281 | |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 282 | set(SRC_USE_CASE "") |
| 283 | foreach(USE_CASES_SEARCH_DIR ${USE_CASES_SEARCH_DIR_LIST}) |
| 284 | if (EXISTS ${USE_CASES_SEARCH_DIR}/${use_case}) |
| 285 | message(STATUS "Found sources for use-case ${use_case}") |
| 286 | set(SRC_USE_CASE ${USE_CASES_SEARCH_DIR}) |
| 287 | break() |
| 288 | endif () |
| 289 | endforeach() |
| 290 | |
| 291 | if (${SRC_USE_CASE} STREQUAL "") |
| 292 | message(FATAL_ERROR "Failed to find sources for ${use_case}!") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 293 | endif () |
| 294 | # Executable application: |
| 295 | set(TARGET_NAME "ethos-u-${use_case}") |
| 296 | |
Kshitij Sisodia | ddcb56d | 2021-05-11 14:46:01 +0100 | [diff] [blame] | 297 | set(DEFAULT_MODEL_DIR ${RESOURCES_DIR}/${use_case}) |
Isabella Gottardi | 2181d0a | 2021-04-07 09:27:38 +0100 | [diff] [blame] | 298 | set(DEFAULT_TEST_DATA_DIR ${DEFAULT_MODEL_DIR}) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 299 | set(SRC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/src) |
| 300 | set(INC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/include) |
| 301 | |
| 302 | # Remove old files and recreate dirs |
| 303 | file(REMOVE_RECURSE ${SRC_GEN_DIR} ${INC_GEN_DIR}) |
| 304 | file(MAKE_DIRECTORY ${SRC_GEN_DIR} ${INC_GEN_DIR}) |
| 305 | |
| 306 | file(GLOB_RECURSE UC_SRC |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 307 | "${SRC_USE_CASE}/${use_case}/src/*.cpp" |
| 308 | "${SRC_USE_CASE}/${use_case}/src/*.cc" |
| 309 | "${SRC_USE_CASE}/${use_case}/src/*.c" |
| 310 | "${SRC_USE_CASE}/${use_case}/src/**/*.cpp" |
| 311 | "${SRC_USE_CASE}/${use_case}/src/**/*.cc" |
| 312 | "${SRC_USE_CASE}/${use_case}/src/**/*.c" |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 313 | ) |
| 314 | |
| 315 | set(UC_INCLUDE |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 316 | ${SRC_USE_CASE}/${use_case}/include |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 317 | ) |
| 318 | |
| 319 | file(GLOB UC_CMAKE_FILE |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 320 | "${SRC_USE_CASE}/${use_case}/*.cmake" |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 321 | ) |
| 322 | |
| 323 | include(${UC_CMAKE_FILE}) |
| 324 | |
| 325 | file(GLOB_RECURSE SRC_GEN |
| 326 | "${SRC_GEN_DIR}/*.cc" |
| 327 | "${SRC_GEN_DIR}/*.cpp" |
| 328 | "${SRC_GEN_DIR}/*.c" |
| 329 | ) |
| 330 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 331 | set(SRC_MAIN "${SRC_PATH}/application/main/Main.cc") |
| 332 | |
| 333 | set_source_files_properties(${SRC_MAIN} |
| 334 | PROPERTIES COMPILE_DEFINITIONS |
| 335 | "PRJ_VER_STR=\"${PROJECT_VERSION}\";PRJ_DES_STR=\"${PROJECT_DESCRIPTION}\"") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 336 | |
| 337 | set(UC_LIB_NAME lib${TARGET_NAME}) |
| 338 | |
| 339 | # Consolidated application static lib: |
| 340 | add_library(${UC_LIB_NAME} STATIC |
| 341 | ${SRC_APPLICATION} |
| 342 | ${SRC_TENSORFLOW_LITE_MICRO} |
| 343 | ${SRC_HAL} |
| 344 | ${UC_SRC} |
| 345 | ${SRC_GEN} |
| 346 | ) |
| 347 | target_include_directories(${UC_LIB_NAME} PUBLIC |
| 348 | ${APPLICATION_INCLUDE_DIRS} |
| 349 | ${DEP_RUNTIME_INCLUDE_DIRS} |
| 350 | ${UC_INCLUDE} |
| 351 | ${INC_GEN_DIR} |
| 352 | ) |
| 353 | |
| 354 | # Set the activation buffer size |
| 355 | target_compile_definitions(${UC_LIB_NAME} PUBLIC |
| 356 | "ACTIVATION_BUF_SZ=${${use_case}_ACTIVATION_BUF_SZ}") |
| 357 | |
| 358 | add_dependencies(${UC_LIB_NAME} tensorflow-lite-micro) |
| 359 | |
| 360 | if (${CMAKE_CROSSCOMPILING}) |
| 361 | # If we are building timing adapter, set the dependency: |
| 362 | if (ETHOS_U55_ENABLED) |
| 363 | message(STATUS "Adding timing_adapter as a dependency to ${UC_LIB_NAME}") |
| 364 | add_dependencies(${UC_LIB_NAME} timing_adapter) |
| 365 | endif() |
| 366 | |
| 367 | # If building with CMSIS-DSP support: |
| 368 | if (DEFINED CMSIS_DSP_TARGET) |
| 369 | message(STATUS "Adding ${CMSIS_DSP_TARGET} as a dependency to ${UC_LIB_NAME}") |
| 370 | add_dependencies(${UC_LIB_NAME} ${CMSIS_DSP_TARGET}) |
| 371 | endif() |
| 372 | endif() |
| 373 | |
| 374 | target_link_libraries(${UC_LIB_NAME} PUBLIC |
| 375 | ${TENSORFLOW_LIBRARY} |
| 376 | $<$<BOOL:${ETHOS_U55_ENABLED}>:${ETHOS_U55_LIBS}> |
| 377 | $<$<BOOL:${CMSIS_DSP_LIB}>:${CMSIS_DSP_LIB}>) |
| 378 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 379 | add_executable(${TARGET_NAME} ${SRC_MAIN} ${PLAT_RETARGET_SOURCE}) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 380 | |
| 381 | target_link_libraries(${TARGET_NAME} ${UC_LIB_NAME}) |
| 382 | |
| 383 | if (${CMAKE_CROSSCOMPILING}) |
| 384 | set_target_properties(${TARGET_NAME} PROPERTIES SUFFIX ".axf") |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 385 | add_target_map_file(${TARGET_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_NAME}.map) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 386 | endif() |
| 387 | |
| 388 | if (${TARGET_PLATFORM} STREQUAL mps3) |
| 389 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 390 | set(SECTORS_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sectors) |
| 391 | set(SECTORS_BIN_DIR ${SECTORS_DIR}/${use_case}) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 392 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 393 | file(REMOVE_RECURSE ${SECTORS_BIN_DIR}) |
| 394 | file(MAKE_DIRECTORY ${SECTORS_BIN_DIR}) |
| 395 | file(COPY ${MPS3_FPGA_CONFIG} DESTINATION ${SECTORS_DIR}) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 396 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 397 | add_bin_generation_command( |
| 398 | TARGET_NAME ${TARGET_NAME} |
| 399 | OUTPUT_DIR ${SECTORS_BIN_DIR} |
| 400 | AXF_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_NAME}.axf |
| 401 | SECTION_PATTERNS "${MPS3_SECTION_PATTERNS}" |
| 402 | OUTPUT_BIN_NAMES "${MPS3_OUTPUT_BIN_NAMES}") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 403 | elseif (${TARGET_PLATFORM} STREQUAL native) |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 404 | |
| 405 | # If native build tests |
| 406 | set(TEST_SRC_USE_CASE "") |
| 407 | foreach(USE_CASES_TESTS_SEARCH_DIR ${USE_CASES_TESTS_SEARCH_DIR_LIST}) |
| 408 | |
| 409 | if (EXISTS ${USE_CASES_TESTS_SEARCH_DIR}/${use_case}) |
| 410 | message(STATUS "Found tests for use-case ${use_case} at ${USE_CASES_TESTS_SEARCH_DIR}/${use_case}.") |
| 411 | set(TEST_SRC_USE_CASE ${USE_CASES_TESTS_SEARCH_DIR}) |
| 412 | break() |
| 413 | endif () |
| 414 | endforeach() |
| 415 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 416 | # Add tests only if they exists for the usecase |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 417 | if (NOT ${TEST_SRC_USE_CASE} STREQUAL "") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 418 | |
| 419 | set(TEST_RESOURCES_INCLUDE |
| 420 | "${TEST_SRCS}/utils/" |
Isabella Gottardi | cce0005 | 2021-04-26 09:24:02 +0100 | [diff] [blame] | 421 | "${TEST_SRC_USE_CASE}/${use_case}/include/" |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 422 | ) |
| 423 | |
| 424 | # Define Test sources and new target to run unit tests |
| 425 | file(GLOB_RECURSE TEST_SOURCES |
| 426 | "${TEST_SRCS}/common/*.cpp" |
| 427 | "${TEST_SRCS}/common/*.cc" |
| 428 | "${TEST_SRCS}/utils/*.cc" |
| 429 | "${TEST_SRCS}/utils/*.cpp" |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 430 | "${TEST_SRC_USE_CASE}/${use_case}/*.cpp" |
| 431 | "${TEST_SRC_USE_CASE}/${use_case}/*.cc" |
| 432 | "${TEST_SRC_USE_CASE}/${use_case}/*.c" |
| 433 | "${TEST_SRC_USE_CASE}/${use_case}/**/*.cpp" |
| 434 | "${TEST_SRC_USE_CASE}/${use_case}/**/*.cc" |
| 435 | "${TEST_SRC_USE_CASE}/${use_case}/**/*.c" |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 436 | ) |
| 437 | |
Isabella Gottardi | 2181d0a | 2021-04-07 09:27:38 +0100 | [diff] [blame] | 438 | set(TEST_SRC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/src) |
| 439 | set(TEST_INC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/include) |
| 440 | file(MAKE_DIRECTORY ${TEST_SRC_GEN_DIR} ${TEST_INC_GEN_DIR}) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 441 | |
alexander | 50a0650 | 2021-05-12 19:06:02 +0100 | [diff] [blame] | 442 | set(${use_case}_DEFAULT_TEST_DATA_DIR ${DEFAULT_TEST_DATA_DIR} CACHE PATH "") |
Isabella Gottardi | 2181d0a | 2021-04-07 09:27:38 +0100 | [diff] [blame] | 443 | # Generate test data files to be included in x86 tests |
| 444 | generate_test_data_code( |
alexander | 50a0650 | 2021-05-12 19:06:02 +0100 | [diff] [blame] | 445 | INPUT_DIR "${${use_case}_DEFAULT_TEST_DATA_DIR}" |
Isabella Gottardi | 2181d0a | 2021-04-07 09:27:38 +0100 | [diff] [blame] | 446 | DESTINATION_SRC ${TEST_SRC_GEN_DIR} |
| 447 | DESTINATION_HDR ${TEST_INC_GEN_DIR} |
| 448 | NAMESPACE "test" |
| 449 | ) |
| 450 | |
| 451 | file(GLOB_RECURSE TEST_SOURCES_GEN |
| 452 | "${TEST_SRC_GEN_DIR}/*.cc" |
| 453 | "${TEST_SRC_GEN_DIR}/**/*.cc" |
| 454 | ) |
| 455 | message(STATUS "Adding ${TEST_SOURCES_GEN} to test sources") |
| 456 | list(APPEND TEST_SOURCES ${TEST_SOURCES_GEN}) |
| 457 | list(APPEND TEST_RESOURCES_INCLUDE ${TEST_INC_GEN_DIR}) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 458 | |
| 459 | set(TEST_TARGET_NAME "${CMAKE_PROJECT_NAME}-${use_case}-tests") |
| 460 | add_executable(${TEST_TARGET_NAME} ${TEST_SOURCES}) |
| 461 | target_include_directories(${TEST_TARGET_NAME} PUBLIC |
| 462 | ${TEST_TPIP_INCLUDE} ${TEST_RESOURCES_INCLUDE}) |
| 463 | target_link_libraries(${TEST_TARGET_NAME} libethos-u-${use_case}) |
| 464 | target_compile_definitions(${TEST_TARGET_NAME} PRIVATE |
| 465 | "ACTIVATION_BUF_SZ=${${use_case}_ACTIVATION_BUF_SZ}" |
| 466 | TESTS) |
| 467 | |
| 468 | add_dependencies( |
| 469 | "${TEST_TARGET_NAME}" |
| 470 | "catch2-headers" |
| 471 | ) |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 472 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 473 | endif () |
| 474 | endif () |
| 475 | endforeach() |
| 476 | |
| 477 | print_useroptions() |