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 | f98d062 | 2022-03-18 11:44:48 +0000 | [diff] [blame] | 23 | set(ETHOS_U_NPU_COMPONENT ethos_u_npu) |
| 24 | project(${ETHOS_U_NPU_COMPONENT} |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 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 | |
Kshitij Sisodia | 8bc863d | 2022-03-24 17:53:34 +0000 | [diff] [blame^] | 36 | # Definitions that will be set. |
| 37 | set(ETHOS_U_BASE_ADDR "0x58102000" CACHE STRING "Ethos-U NPU base address") |
| 38 | set(ETHOS_U_IRQN "56" CACHE STRING "Ethos-U NPU Interrupt") |
| 39 | set(ETHOS_U_SEC_ENABLED "1" CACHE STRING "Ethos-U NPU Security enable") |
| 40 | set(ETHOS_U_PRIV_ENABLED "1" CACHE STRING "Ethos-U NPU Privilege enable") |
| 41 | |
Richard Burton | f4f240b | 2022-03-04 14:16:49 +0000 | [diff] [blame] | 42 | # Driver needs to know what MAC configuration to build for. |
| 43 | if(ETHOS_U_NPU_CONFIG_ID MATCHES "^[A-Z]([0-9]+$)") |
| 44 | set(ETHOSU_MACS ${CMAKE_MATCH_1}) |
| 45 | else() |
| 46 | message(FATAL_ERROR "Couldn't work out Ethos-U number of MACS from ${ETHOS_U_NPU_CONFIG_ID}") |
| 47 | endif() |
| 48 | set(ETHOSU_TARGET_NPU_CONFIG |
| 49 | "ethos-${ETHOS_U_NPU_ID}-${ETHOSU_MACS}" CACHE STRING "Target Ethos-U configuration for driver.") |
| 50 | |
| 51 | ## Memory mode target definition |
| 52 | if (NOT DEFINED ETHOS_U_NPU_ID) |
| 53 | set(ETHOS_U_NPU_ID U55) |
| 54 | endif() |
| 55 | |
| 56 | if (NOT DEFINED ETHOS_U_NPU_MEMORY_MODE) |
| 57 | set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram) |
| 58 | endif() |
| 59 | |
| 60 | if (ETHOS_U_NPU_MEMORY_MODE STREQUAL Sram_Only) |
| 61 | if (ETHOS_U_NPU_ID STREQUAL U55) |
| 62 | set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEM_MODE_SRAM_ONLY") |
| 63 | else () |
| 64 | 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.") |
| 65 | endif () |
| 66 | elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Shared_Sram) |
| 67 | # Shared Sram can be used for Ethos-U55 and Ethos-U65 |
| 68 | set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_SHARED_SRAM") |
| 69 | elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Dedicated_Sram) |
| 70 | # Dedicated Sram is used only for Ethos-U65 |
| 71 | if (ETHOS_U_NPU_ID STREQUAL U65) |
| 72 | 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}") |
| 73 | else () |
| 74 | 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.") |
| 75 | endif () |
| 76 | else () |
| 77 | message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode ${ETHOS_U_NPU_MEMORY_MODE}") |
| 78 | endif () |
| 79 | |
Isabella Gottardi | b0b2bdc | 2022-03-10 17:08:37 +0000 | [diff] [blame] | 80 | # Include the build for Ethos-U driver |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 81 | add_subdirectory(${ETHOS_U_NPU_DRIVER_SRC_PATH} ${CMAKE_BINARY_DIR}/ethos-u-driver) |
| 82 | |
Isabella Gottardi | b0b2bdc | 2022-03-10 17:08:37 +0000 | [diff] [blame] | 83 | # For Ethos-U driver, we need to override the default region configs |
| 84 | # Region numbers are decided by Vela and they do not need to conform to set rules. |
| 85 | # Traditionally they have been used as: |
| 86 | # |
| 87 | # Region 0: Weights and biases (and const tensors) |
| 88 | # Region 1: IFM/OFM/Calculation buffers (tensor arena) |
| 89 | # Region 2: Ethos-U'd dedicated cache region (fast cache memory) |
| 90 | # |
| 91 | # NOTE: The above scheme is completely dependent on Vela and could potentially |
| 92 | # change. |
| 93 | # |
| 94 | # Common definitions: |
| 95 | # For Ethos-U55/U65, Region configs are set as: |
| 96 | # 0 or 1 = AXI0 |
| 97 | # 2 or 3 = AXI1 |
| 98 | target_compile_definitions(ethosu_core_driver PRIVATE |
| 99 | NPU_QCONFIG=3 # AXI1=M1 for U55/U65 |
| 100 | NPU_REGIONCFG_0=3 # AXI1=M1 for U55/U65 |
| 101 | NPU_REGIONCFG_2=1 # AXI0=M0 for U55/U65 |
| 102 | NPU_REGIONCFG_3=1 # AXI0=M0 for U55/U65 |
| 103 | NPU_REGIONCFG_4=1 # AXI0=M0 for U55/U65 |
| 104 | NPU_REGIONCFG_5=1 # AXI0=M0 for U55/U65 |
| 105 | NPU_REGIONCFG_6=1 # AXI0=M0 for U55/U65 |
| 106 | NPU_REGIONCFG_7=1) # AXI0=M0 for U55/U65 |
| 107 | |
| 108 | # Definitions relevant for all NPUs but depend on memory mode |
| 109 | if (ETHOS_U_NPU_MEMORY_MODE STREQUAL Dedicated_Sram) |
| 110 | target_compile_definitions(ethosu_core_driver PRIVATE |
| 111 | NPU_REGIONCFG_1=3) # AXI1=M1 for U55/U65 |
| 112 | else() |
| 113 | target_compile_definitions(ethosu_core_driver PRIVATE |
| 114 | NPU_REGIONCFG_1=0) # AXI0=M0 for U55/U65 |
| 115 | endif() |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 116 | # Create static library |
Kshitij Sisodia | f98d062 | 2022-03-18 11:44:48 +0000 | [diff] [blame] | 117 | add_library(${ETHOS_U_NPU_COMPONENT} STATIC) |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 118 | |
| 119 | ## Include directories - public |
Kshitij Sisodia | f98d062 | 2022-03-18 11:44:48 +0000 | [diff] [blame] | 120 | target_include_directories(${ETHOS_U_NPU_COMPONENT} |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 121 | PUBLIC |
| 122 | include |
| 123 | ${SOURCE_GEN_DIR}) |
| 124 | |
| 125 | ## Component sources |
Kshitij Sisodia | f98d062 | 2022-03-18 11:44:48 +0000 | [diff] [blame] | 126 | target_sources(${ETHOS_U_NPU_COMPONENT} |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 127 | PRIVATE |
Kshitij Sisodia | c22e80e | 2022-03-14 09:26:48 +0000 | [diff] [blame] | 128 | ethosu_npu_init.c |
| 129 | ethosu_cpu_cache.c) |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 130 | |
| 131 | ## Add dependencies: |
Kshitij Sisodia | f98d062 | 2022-03-18 11:44:48 +0000 | [diff] [blame] | 132 | target_link_libraries(${ETHOS_U_NPU_COMPONENT} PUBLIC |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 133 | ethosu_core_driver |
| 134 | log) |
| 135 | |
Kshitij Sisodia | f98d062 | 2022-03-18 11:44:48 +0000 | [diff] [blame] | 136 | ## If the rte_components target has been defined, include it as a dependency here. This component |
| 137 | ## gives access to certain CPU related functions and definitions that should come from the CMSIS |
| 138 | ## or custom system setup and boot implementation files. |
| 139 | ## If the component is not defined as a target, a dependency for this target should be added by |
| 140 | ## the project importing this one. |
| 141 | if (TARGET rte_components) |
| 142 | target_link_libraries(${ETHOS_U_NPU_COMPONENT} PUBLIC |
| 143 | rte_components) |
| 144 | else() |
| 145 | message(WARNING |
| 146 | "rte_components target not defined." |
| 147 | "${ETHOS_U_NPU_COMPONENT} will need to be provided access to" |
| 148 | "RTE_Compnents.h header to include CPU specific definitions.") |
| 149 | endif() |
| 150 | |
| 151 | target_compile_definitions(${ETHOS_U_NPU_COMPONENT} |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 152 | PUBLIC |
Kshitij Sisodia | c22e80e | 2022-03-14 09:26:48 +0000 | [diff] [blame] | 153 | ARM_NPU |
Kshitij Sisodia | 8bc863d | 2022-03-24 17:53:34 +0000 | [diff] [blame^] | 154 | ${ETHOS_U_NPU_MEMORY_MODE_FLAG} |
| 155 | ETHOS_U_BASE_ADDR=${ETHOS_U_BASE_ADDR} |
| 156 | ETHOS_U_IRQN=${ETHOS_U_IRQN} |
| 157 | ETHOS_U_SEC_ENABLED=${ETHOS_U_SEC_ENABLED} |
| 158 | ETHOS_U_PRIV_ENABLED=${ETHOS_U_PRIV_ENABLED}) |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 159 | |
| 160 | # Display status |
| 161 | message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR}) |
| 162 | message(STATUS "*******************************************************") |
Kshitij Sisodia | f98d062 | 2022-03-18 11:44:48 +0000 | [diff] [blame] | 163 | message(STATUS "Library : " ${ETHOS_U_NPU_COMPONENT}) |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 164 | message(STATUS "*******************************************************") |