Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 1 | #---------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2022 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 | |
| 18 | ######################################################### |
| 19 | # Ethos-U NPU initialization library # |
| 20 | ######################################################### |
| 21 | |
| 22 | cmake_minimum_required(VERSION 3.15.6) |
Kshitij Sisodia | c22e80e | 2022-03-14 09:26:48 +0000 | [diff] [blame^] | 23 | set(ETHOS_U_NPU_INIT_COMPONENT ethos_u_npu) |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 24 | project(${ETHOS_U_NPU_INIT_COMPONENT} |
| 25 | DESCRIPTION "Ethos-U NPU initialization library" |
| 26 | LANGUAGES C CXX ASM) |
| 27 | |
| 28 | if (NOT DEFINED ETHOS_U_NPU_DRIVER_SRC_PATH) |
| 29 | message(FATAL_ERROR "ETHOS_U_NPU_DRIVER_SRC_PATH should" |
| 30 | " be defined when ETHOS_U_NPU_ENABLED=${ETHOS_U_NPU_ENABLED}") |
| 31 | endif() |
| 32 | |
| 33 | # For the driver, we need to provide the CMSIS_PATH variable |
| 34 | set(CMSIS_PATH ${CMSIS_SRC_PATH} CACHE PATH "Path to CMSIS directory") |
Richard Burton | f4f240b | 2022-03-04 14:16:49 +0000 | [diff] [blame] | 35 | |
| 36 | # Driver needs to know what MAC configuration to build for. |
| 37 | if(ETHOS_U_NPU_CONFIG_ID MATCHES "^[A-Z]([0-9]+$)") |
| 38 | set(ETHOSU_MACS ${CMAKE_MATCH_1}) |
| 39 | else() |
| 40 | message(FATAL_ERROR "Couldn't work out Ethos-U number of MACS from ${ETHOS_U_NPU_CONFIG_ID}") |
| 41 | endif() |
| 42 | set(ETHOSU_TARGET_NPU_CONFIG |
| 43 | "ethos-${ETHOS_U_NPU_ID}-${ETHOSU_MACS}" CACHE STRING "Target Ethos-U configuration for driver.") |
| 44 | |
| 45 | ## Memory mode target definition |
| 46 | if (NOT DEFINED ETHOS_U_NPU_ID) |
| 47 | set(ETHOS_U_NPU_ID U55) |
| 48 | endif() |
| 49 | |
| 50 | if (NOT DEFINED ETHOS_U_NPU_MEMORY_MODE) |
| 51 | set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram) |
| 52 | endif() |
| 53 | |
| 54 | if (ETHOS_U_NPU_MEMORY_MODE STREQUAL Sram_Only) |
| 55 | if (ETHOS_U_NPU_ID STREQUAL U55) |
| 56 | set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEM_MODE_SRAM_ONLY") |
| 57 | else () |
| 58 | message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode and processor ${ETHOS_U_NPU_MEMORY_MODE} - ${ETHOS_U_NPU_ID}. `sram_only` can be used only for Ethos-U55.") |
| 59 | endif () |
| 60 | elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Shared_Sram) |
| 61 | # Shared Sram can be used for Ethos-U55 and Ethos-U65 |
| 62 | set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_SHARED_SRAM") |
| 63 | elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Dedicated_Sram) |
| 64 | # Dedicated Sram is used only for Ethos-U65 |
| 65 | if (ETHOS_U_NPU_ID STREQUAL U65) |
| 66 | list(APPEND ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_DEDICATED_SRAM" "-DETHOS_U_NPU_CACHE_SIZE=${ETHOS_U_NPU_CACHE_SIZE}") |
| 67 | else () |
| 68 | message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode and processor ${ETHOS_U_NPU_MEMORY_MODE} - ${ETHOS_U_NPU_ID}. `dedicated_sram` can be used only for Ethos-U65.") |
| 69 | endif () |
| 70 | else () |
| 71 | message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode ${ETHOS_U_NPU_MEMORY_MODE}") |
| 72 | endif () |
| 73 | |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 74 | add_subdirectory(${ETHOS_U_NPU_DRIVER_SRC_PATH} ${CMAKE_BINARY_DIR}/ethos-u-driver) |
| 75 | |
| 76 | # Create static library |
| 77 | add_library(${ETHOS_U_NPU_INIT_COMPONENT} STATIC) |
| 78 | |
| 79 | ## Include directories - public |
| 80 | target_include_directories(${ETHOS_U_NPU_INIT_COMPONENT} |
| 81 | PUBLIC |
| 82 | include |
| 83 | ${SOURCE_GEN_DIR}) |
| 84 | |
| 85 | ## Component sources |
| 86 | target_sources(${ETHOS_U_NPU_INIT_COMPONENT} |
| 87 | PRIVATE |
Kshitij Sisodia | c22e80e | 2022-03-14 09:26:48 +0000 | [diff] [blame^] | 88 | ethosu_npu_init.c |
| 89 | ethosu_cpu_cache.c) |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 90 | |
| 91 | ## Add dependencies: |
| 92 | target_link_libraries(${ETHOS_U_NPU_INIT_COMPONENT} PUBLIC |
Kshitij Sisodia | c22e80e | 2022-03-14 09:26:48 +0000 | [diff] [blame^] | 93 | cmsis_device_cpu_header |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 94 | ethosu_core_driver |
| 95 | log) |
| 96 | |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 97 | target_compile_definitions(${ETHOS_U_NPU_INIT_COMPONENT} |
| 98 | PUBLIC |
Kshitij Sisodia | c22e80e | 2022-03-14 09:26:48 +0000 | [diff] [blame^] | 99 | ARM_NPU |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 100 | ${ETHOS_U_NPU_MEMORY_MODE_FLAG}) |
| 101 | |
| 102 | # Display status |
| 103 | message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR}) |
| 104 | message(STATUS "*******************************************************") |
| 105 | message(STATUS "Library : " ${ETHOS_U_NPU_INIT_COMPONENT}) |
| 106 | message(STATUS "*******************************************************") |