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