blob: eebf2354fcfb05522ae5bf4692a5c3fcdd171dbb [file] [log] [blame]
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +00001#----------------------------------------------------------------------------
Kshitij Sisodia5385a642024-01-17 13:29:43 +00002# SPDX-FileCopyrightText: Copyright 2022, 2024 Arm Limited and/or its
3# affiliates <open-source-office@arm.com>
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +00004# 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 Sisodia9c6f9f82022-05-20 14:30:02 +010023cmake_minimum_required(VERSION 3.21.0)
Kshitij Sisodiaf98d0622022-03-18 11:44:48 +000024set(ETHOS_U_NPU_COMPONENT ethos_u_npu)
25project(${ETHOS_U_NPU_COMPONENT}
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +000026 DESCRIPTION "Ethos-U NPU initialization library"
27 LANGUAGES C CXX ASM)
28
29if (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}")
32endif()
33
34# For the driver, we need to provide the CMSIS_PATH variable
35set(CMSIS_PATH ${CMSIS_SRC_PATH} CACHE PATH "Path to CMSIS directory")
Richard Burtonf4f240b2022-03-04 14:16:49 +000036
Kshitij Sisodia5385a642024-01-17 13:29:43 +000037# Definitions that should be overridden by the platform wrapping this project.
38# Otherwise, these defaults will be used.
Kshitij Sisodia8bc863d2022-03-24 17:53:34 +000039set(ETHOS_U_BASE_ADDR "0x58102000" CACHE STRING "Ethos-U NPU base address")
40set(ETHOS_U_IRQN "56" CACHE STRING "Ethos-U NPU Interrupt")
41set(ETHOS_U_SEC_ENABLED "1" CACHE STRING "Ethos-U NPU Security enable")
42set(ETHOS_U_PRIV_ENABLED "1" CACHE STRING "Ethos-U NPU Privilege enable")
43
Richard Burtonf4f240b2022-03-04 14:16:49 +000044# Driver needs to know what MAC configuration to build for.
Kshitij Sisodiaea8ce562022-04-12 11:10:11 +010045if (NOT DEFINED ETHOS_U_NPU_CONFIG_ID)
46 set(ETHOS_U_NPU_CONFIG_ID "H128")
47endif()
48
49## Memory mode target definition
50if (NOT DEFINED ETHOS_U_NPU_ID)
51 set(ETHOS_U_NPU_ID U55)
52endif()
53
Richard Burtonf4f240b2022-03-04 14:16:49 +000054if(ETHOS_U_NPU_CONFIG_ID MATCHES "^[A-Z]([0-9]+$)")
55 set(ETHOSU_MACS ${CMAKE_MATCH_1})
56else()
57 message(FATAL_ERROR "Couldn't work out Ethos-U number of MACS from ${ETHOS_U_NPU_CONFIG_ID}")
58endif()
59set(ETHOSU_TARGET_NPU_CONFIG
60 "ethos-${ETHOS_U_NPU_ID}-${ETHOSU_MACS}" CACHE STRING "Target Ethos-U configuration for driver.")
61
Richard Burtonf4f240b2022-03-04 14:16:49 +000062if (NOT DEFINED ETHOS_U_NPU_MEMORY_MODE)
63 set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram)
64endif()
65
66if (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 ()
72elseif (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")
75elseif (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 ()
82else ()
83 message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode ${ETHOS_U_NPU_MEMORY_MODE}")
84endif ()
85
Isabella Gottardib0b2bdc2022-03-10 17:08:37 +000086# Include the build for Ethos-U driver
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +000087add_subdirectory(${ETHOS_U_NPU_DRIVER_SRC_PATH} ${CMAKE_BINARY_DIR}/ethos-u-driver)
88
Kshitij Sisodiaea8ce562022-04-12 11:10:11 +010089## Logging utilities:
90if (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)
95endif()
96
Isabella Gottardib0b2bdc2022-03-10 17:08:37 +000097# 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
112target_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
123if (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
126else()
127 target_compile_definitions(ethosu_core_driver PRIVATE
128 NPU_REGIONCFG_1=0) # AXI0=M0 for U55/U65
129endif()
Eanna O Cathaind1fd6982022-07-01 17:27:12 +0100130
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.
134if (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
140endif()
141
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000142# Create static library
Kshitij Sisodiaf98d0622022-03-18 11:44:48 +0000143add_library(${ETHOS_U_NPU_COMPONENT} STATIC)
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000144
145## Include directories - public
Kshitij Sisodiaf98d0622022-03-18 11:44:48 +0000146target_include_directories(${ETHOS_U_NPU_COMPONENT}
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000147 PUBLIC
148 include
149 ${SOURCE_GEN_DIR})
150
151## Component sources
Kshitij Sisodiaf98d0622022-03-18 11:44:48 +0000152target_sources(${ETHOS_U_NPU_COMPONENT}
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000153 PRIVATE
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +0000154 ethosu_npu_init.c
Kshitij Sisodiada2ec062022-04-01 14:43:53 +0100155 ethosu_profiler.c)
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000156
Kshitij Sisodiab06bba92022-11-02 14:11:32 +0000157target_sources(${ETHOS_U_NPU_COMPONENT}
158 PUBLIC
159 ethosu_cpu_cache.c)
160
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000161## Add dependencies:
Kshitij Sisodiaf98d0622022-03-18 11:44:48 +0000162target_link_libraries(${ETHOS_U_NPU_COMPONENT} PUBLIC
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000163 ethosu_core_driver
164 log)
165
Kshitij Sisodiaf98d0622022-03-18 11:44:48 +0000166## 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.
171if (TARGET rte_components)
172 target_link_libraries(${ETHOS_U_NPU_COMPONENT} PUBLIC
173 rte_components)
174else()
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.")
179endif()
180
181target_compile_definitions(${ETHOS_U_NPU_COMPONENT}
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000182 PUBLIC
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +0000183 ARM_NPU
Kshitij Sisodia8bc863d2022-03-24 17:53:34 +0000184 ${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 Sisodiad5679cc2022-03-03 16:30:07 +0000189
190# Display status
191message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR})
192message(STATUS "*******************************************************")
Kshitij Sisodiaf98d0622022-03-18 11:44:48 +0000193message(STATUS "Library : " ${ETHOS_U_NPU_COMPONENT})
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000194message(STATUS "*******************************************************")