Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 1 | #---------------------------------------------------------------------------- |
Kshitij Sisodia | 5385a64 | 2024-01-17 13:29:43 +0000 | [diff] [blame^] | 2 | # SPDX-FileCopyrightText: Copyright 2022, 2024 Arm Limited and/or its |
| 3 | # affiliates <open-source-office@arm.com> |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://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, |
| 14 | # WITHOUT 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 | ######################################################### |
| 20 | # Ethos-U NPU initialization library # |
| 21 | ######################################################### |
| 22 | |
Kshitij Sisodia | 9c6f9f8 | 2022-05-20 14:30:02 +0100 | [diff] [blame] | 23 | cmake_minimum_required(VERSION 3.21.0) |
Kshitij Sisodia | f98d062 | 2022-03-18 11:44:48 +0000 | [diff] [blame] | 24 | set(ETHOS_U_NPU_COMPONENT ethos_u_npu) |
| 25 | project(${ETHOS_U_NPU_COMPONENT} |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 26 | DESCRIPTION "Ethos-U NPU initialization library" |
| 27 | LANGUAGES C CXX ASM) |
| 28 | |
| 29 | if (NOT DEFINED ETHOS_U_NPU_DRIVER_SRC_PATH) |
| 30 | message(FATAL_ERROR "ETHOS_U_NPU_DRIVER_SRC_PATH should" |
| 31 | " be defined when ETHOS_U_NPU_ENABLED=${ETHOS_U_NPU_ENABLED}") |
| 32 | endif() |
| 33 | |
| 34 | # For the driver, we need to provide the CMSIS_PATH variable |
| 35 | set(CMSIS_PATH ${CMSIS_SRC_PATH} CACHE PATH "Path to CMSIS directory") |
Richard Burton | f4f240b | 2022-03-04 14:16:49 +0000 | [diff] [blame] | 36 | |
Kshitij Sisodia | 5385a64 | 2024-01-17 13:29:43 +0000 | [diff] [blame^] | 37 | # Definitions that should be overridden by the platform wrapping this project. |
| 38 | # Otherwise, these defaults will be used. |
Kshitij Sisodia | 8bc863d | 2022-03-24 17:53:34 +0000 | [diff] [blame] | 39 | set(ETHOS_U_BASE_ADDR "0x58102000" CACHE STRING "Ethos-U NPU base address") |
| 40 | set(ETHOS_U_IRQN "56" CACHE STRING "Ethos-U NPU Interrupt") |
| 41 | set(ETHOS_U_SEC_ENABLED "1" CACHE STRING "Ethos-U NPU Security enable") |
| 42 | set(ETHOS_U_PRIV_ENABLED "1" CACHE STRING "Ethos-U NPU Privilege enable") |
| 43 | |
Richard Burton | f4f240b | 2022-03-04 14:16:49 +0000 | [diff] [blame] | 44 | # Driver needs to know what MAC configuration to build for. |
Kshitij Sisodia | ea8ce56 | 2022-04-12 11:10:11 +0100 | [diff] [blame] | 45 | if (NOT DEFINED ETHOS_U_NPU_CONFIG_ID) |
| 46 | set(ETHOS_U_NPU_CONFIG_ID "H128") |
| 47 | endif() |
| 48 | |
| 49 | ## Memory mode target definition |
| 50 | if (NOT DEFINED ETHOS_U_NPU_ID) |
| 51 | set(ETHOS_U_NPU_ID U55) |
| 52 | endif() |
| 53 | |
Richard Burton | f4f240b | 2022-03-04 14:16:49 +0000 | [diff] [blame] | 54 | if(ETHOS_U_NPU_CONFIG_ID MATCHES "^[A-Z]([0-9]+$)") |
| 55 | set(ETHOSU_MACS ${CMAKE_MATCH_1}) |
| 56 | else() |
| 57 | message(FATAL_ERROR "Couldn't work out Ethos-U number of MACS from ${ETHOS_U_NPU_CONFIG_ID}") |
| 58 | endif() |
| 59 | set(ETHOSU_TARGET_NPU_CONFIG |
| 60 | "ethos-${ETHOS_U_NPU_ID}-${ETHOSU_MACS}" CACHE STRING "Target Ethos-U configuration for driver.") |
| 61 | |
Richard Burton | f4f240b | 2022-03-04 14:16:49 +0000 | [diff] [blame] | 62 | if (NOT DEFINED ETHOS_U_NPU_MEMORY_MODE) |
| 63 | set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram) |
| 64 | endif() |
| 65 | |
| 66 | if (ETHOS_U_NPU_MEMORY_MODE STREQUAL Sram_Only) |
| 67 | if (ETHOS_U_NPU_ID STREQUAL U55) |
| 68 | set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEM_MODE_SRAM_ONLY") |
| 69 | else () |
| 70 | 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.") |
| 71 | endif () |
| 72 | elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Shared_Sram) |
| 73 | # Shared Sram can be used for Ethos-U55 and Ethos-U65 |
| 74 | set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_SHARED_SRAM") |
| 75 | elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Dedicated_Sram) |
| 76 | # Dedicated Sram is used only for Ethos-U65 |
| 77 | if (ETHOS_U_NPU_ID STREQUAL U65) |
| 78 | 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}") |
| 79 | else () |
| 80 | 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.") |
| 81 | endif () |
| 82 | else () |
| 83 | message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode ${ETHOS_U_NPU_MEMORY_MODE}") |
| 84 | endif () |
| 85 | |
Isabella Gottardi | b0b2bdc | 2022-03-10 17:08:37 +0000 | [diff] [blame] | 86 | # Include the build for Ethos-U driver |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 87 | add_subdirectory(${ETHOS_U_NPU_DRIVER_SRC_PATH} ${CMAKE_BINARY_DIR}/ethos-u-driver) |
| 88 | |
Kshitij Sisodia | ea8ce56 | 2022-04-12 11:10:11 +0100 | [diff] [blame] | 89 | ## Logging utilities: |
| 90 | if (NOT TARGET log) |
| 91 | if (NOT DEFINED LOG_PROJECT_DIR) |
| 92 | message(FATAL_ERROR "LOG_PROJECT_DIR needs to be defined.") |
| 93 | endif() |
| 94 | add_subdirectory(${LOG_PROJECT_DIR} ${CMAKE_BINARY_DIR}/log) |
| 95 | endif() |
| 96 | |
Isabella Gottardi | b0b2bdc | 2022-03-10 17:08:37 +0000 | [diff] [blame] | 97 | # For Ethos-U driver, we need to override the default region configs |
| 98 | # Region numbers are decided by Vela and they do not need to conform to set rules. |
| 99 | # Traditionally they have been used as: |
| 100 | # |
| 101 | # Region 0: Weights and biases (and const tensors) |
| 102 | # Region 1: IFM/OFM/Calculation buffers (tensor arena) |
| 103 | # Region 2: Ethos-U'd dedicated cache region (fast cache memory) |
| 104 | # |
| 105 | # NOTE: The above scheme is completely dependent on Vela and could potentially |
| 106 | # change. |
| 107 | # |
| 108 | # Common definitions: |
| 109 | # For Ethos-U55/U65, Region configs are set as: |
| 110 | # 0 or 1 = AXI0 |
| 111 | # 2 or 3 = AXI1 |
| 112 | target_compile_definitions(ethosu_core_driver PRIVATE |
| 113 | NPU_QCONFIG=3 # AXI1=M1 for U55/U65 |
| 114 | NPU_REGIONCFG_0=3 # AXI1=M1 for U55/U65 |
| 115 | NPU_REGIONCFG_2=1 # AXI0=M0 for U55/U65 |
| 116 | NPU_REGIONCFG_3=1 # AXI0=M0 for U55/U65 |
| 117 | NPU_REGIONCFG_4=1 # AXI0=M0 for U55/U65 |
| 118 | NPU_REGIONCFG_5=1 # AXI0=M0 for U55/U65 |
| 119 | NPU_REGIONCFG_6=1 # AXI0=M0 for U55/U65 |
| 120 | NPU_REGIONCFG_7=1) # AXI0=M0 for U55/U65 |
| 121 | |
| 122 | # Definitions relevant for all NPUs but depend on memory mode |
| 123 | if (ETHOS_U_NPU_MEMORY_MODE STREQUAL Dedicated_Sram) |
| 124 | target_compile_definitions(ethosu_core_driver PRIVATE |
| 125 | NPU_REGIONCFG_1=3) # AXI1=M1 for U55/U65 |
| 126 | else() |
| 127 | target_compile_definitions(ethosu_core_driver PRIVATE |
| 128 | NPU_REGIONCFG_1=0) # AXI0=M0 for U55/U65 |
| 129 | endif() |
Eanna O Cathain | d1fd698 | 2022-07-01 17:27:12 +0100 | [diff] [blame] | 130 | |
| 131 | # Ethos-U55 supports a maximum burst length of 64 bytes while Ethos-U65 supports up to 128 bytes. |
| 132 | # Although, this is system implementation dependent the platforms we build for should support the |
| 133 | # maximum burst length for both NPU configurations. |
| 134 | if (ETHOS_U_NPU_ID STREQUAL U65) |
| 135 | target_compile_definitions(ethosu_core_driver PRIVATE |
| 136 | AXI_LIMIT0_MAX_BEATS_BYTES=1 |
| 137 | AXI_LIMIT1_MAX_BEATS_BYTES=1 |
| 138 | AXI_LIMIT2_MAX_BEATS_BYTES=1 |
| 139 | AXI_LIMIT3_MAX_BEATS_BYTES=1) # 0 = 64 byte burst & 1 = 128 byte burst |
| 140 | endif() |
| 141 | |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 142 | # Create static library |
Kshitij Sisodia | f98d062 | 2022-03-18 11:44:48 +0000 | [diff] [blame] | 143 | add_library(${ETHOS_U_NPU_COMPONENT} STATIC) |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 144 | |
| 145 | ## Include directories - public |
Kshitij Sisodia | f98d062 | 2022-03-18 11:44:48 +0000 | [diff] [blame] | 146 | target_include_directories(${ETHOS_U_NPU_COMPONENT} |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 147 | PUBLIC |
| 148 | include |
| 149 | ${SOURCE_GEN_DIR}) |
| 150 | |
| 151 | ## Component sources |
Kshitij Sisodia | f98d062 | 2022-03-18 11:44:48 +0000 | [diff] [blame] | 152 | target_sources(${ETHOS_U_NPU_COMPONENT} |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 153 | PRIVATE |
Kshitij Sisodia | c22e80e | 2022-03-14 09:26:48 +0000 | [diff] [blame] | 154 | ethosu_npu_init.c |
Kshitij Sisodia | da2ec06 | 2022-04-01 14:43:53 +0100 | [diff] [blame] | 155 | ethosu_profiler.c) |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 156 | |
Kshitij Sisodia | b06bba9 | 2022-11-02 14:11:32 +0000 | [diff] [blame] | 157 | target_sources(${ETHOS_U_NPU_COMPONENT} |
| 158 | PUBLIC |
| 159 | ethosu_cpu_cache.c) |
| 160 | |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 161 | ## Add dependencies: |
Kshitij Sisodia | f98d062 | 2022-03-18 11:44:48 +0000 | [diff] [blame] | 162 | target_link_libraries(${ETHOS_U_NPU_COMPONENT} PUBLIC |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 163 | ethosu_core_driver |
| 164 | log) |
| 165 | |
Kshitij Sisodia | f98d062 | 2022-03-18 11:44:48 +0000 | [diff] [blame] | 166 | ## If the rte_components target has been defined, include it as a dependency here. This component |
| 167 | ## gives access to certain CPU related functions and definitions that should come from the CMSIS |
| 168 | ## or custom system setup and boot implementation files. |
| 169 | ## If the component is not defined as a target, a dependency for this target should be added by |
| 170 | ## the project importing this one. |
| 171 | if (TARGET rte_components) |
| 172 | target_link_libraries(${ETHOS_U_NPU_COMPONENT} PUBLIC |
| 173 | rte_components) |
| 174 | else() |
| 175 | message(WARNING |
| 176 | "rte_components target not defined." |
| 177 | "${ETHOS_U_NPU_COMPONENT} will need to be provided access to" |
| 178 | "RTE_Compnents.h header to include CPU specific definitions.") |
| 179 | endif() |
| 180 | |
| 181 | target_compile_definitions(${ETHOS_U_NPU_COMPONENT} |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 182 | PUBLIC |
Kshitij Sisodia | c22e80e | 2022-03-14 09:26:48 +0000 | [diff] [blame] | 183 | ARM_NPU |
Kshitij Sisodia | 8bc863d | 2022-03-24 17:53:34 +0000 | [diff] [blame] | 184 | ${ETHOS_U_NPU_MEMORY_MODE_FLAG} |
| 185 | ETHOS_U_BASE_ADDR=${ETHOS_U_BASE_ADDR} |
| 186 | ETHOS_U_IRQN=${ETHOS_U_IRQN} |
| 187 | ETHOS_U_SEC_ENABLED=${ETHOS_U_SEC_ENABLED} |
| 188 | ETHOS_U_PRIV_ENABLED=${ETHOS_U_PRIV_ENABLED}) |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 189 | |
| 190 | # Display status |
| 191 | message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR}) |
| 192 | message(STATUS "*******************************************************") |
Kshitij Sisodia | f98d062 | 2022-03-18 11:44:48 +0000 | [diff] [blame] | 193 | message(STATUS "Library : " ${ETHOS_U_NPU_COMPONENT}) |
Kshitij Sisodia | d5679cc | 2022-03-03 16:30:07 +0000 | [diff] [blame] | 194 | message(STATUS "*******************************************************") |