blob: c53dd0228ed7a8b052a6dea73ffce6d119220b27 [file] [log] [blame]
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +00001#----------------------------------------------------------------------------
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
22cmake_minimum_required(VERSION 3.15.6)
Kshitij Sisodiaf98d0622022-03-18 11:44:48 +000023set(ETHOS_U_NPU_COMPONENT ethos_u_npu)
24project(${ETHOS_U_NPU_COMPONENT}
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +000025 DESCRIPTION "Ethos-U NPU initialization library"
26 LANGUAGES C CXX ASM)
27
28if (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}")
31endif()
32
33# For the driver, we need to provide the CMSIS_PATH variable
34set(CMSIS_PATH ${CMSIS_SRC_PATH} CACHE PATH "Path to CMSIS directory")
Richard Burtonf4f240b2022-03-04 14:16:49 +000035
Kshitij Sisodia8bc863d2022-03-24 17:53:34 +000036# Definitions that will be set.
37set(ETHOS_U_BASE_ADDR "0x58102000" CACHE STRING "Ethos-U NPU base address")
38set(ETHOS_U_IRQN "56" CACHE STRING "Ethos-U NPU Interrupt")
39set(ETHOS_U_SEC_ENABLED "1" CACHE STRING "Ethos-U NPU Security enable")
40set(ETHOS_U_PRIV_ENABLED "1" CACHE STRING "Ethos-U NPU Privilege enable")
41
Richard Burtonf4f240b2022-03-04 14:16:49 +000042# Driver needs to know what MAC configuration to build for.
43if(ETHOS_U_NPU_CONFIG_ID MATCHES "^[A-Z]([0-9]+$)")
44 set(ETHOSU_MACS ${CMAKE_MATCH_1})
45else()
46 message(FATAL_ERROR "Couldn't work out Ethos-U number of MACS from ${ETHOS_U_NPU_CONFIG_ID}")
47endif()
48set(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
52if (NOT DEFINED ETHOS_U_NPU_ID)
53 set(ETHOS_U_NPU_ID U55)
54endif()
55
56if (NOT DEFINED ETHOS_U_NPU_MEMORY_MODE)
57 set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram)
58endif()
59
60if (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 ()
66elseif (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")
69elseif (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 ()
76else ()
77 message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode ${ETHOS_U_NPU_MEMORY_MODE}")
78endif ()
79
Isabella Gottardib0b2bdc2022-03-10 17:08:37 +000080# Include the build for Ethos-U driver
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +000081add_subdirectory(${ETHOS_U_NPU_DRIVER_SRC_PATH} ${CMAKE_BINARY_DIR}/ethos-u-driver)
82
Isabella Gottardib0b2bdc2022-03-10 17:08:37 +000083# 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
98target_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
109if (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
112else()
113 target_compile_definitions(ethosu_core_driver PRIVATE
114 NPU_REGIONCFG_1=0) # AXI0=M0 for U55/U65
115endif()
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000116# Create static library
Kshitij Sisodiaf98d0622022-03-18 11:44:48 +0000117add_library(${ETHOS_U_NPU_COMPONENT} STATIC)
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000118
119## Include directories - public
Kshitij Sisodiaf98d0622022-03-18 11:44:48 +0000120target_include_directories(${ETHOS_U_NPU_COMPONENT}
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000121 PUBLIC
122 include
123 ${SOURCE_GEN_DIR})
124
125## Component sources
Kshitij Sisodiaf98d0622022-03-18 11:44:48 +0000126target_sources(${ETHOS_U_NPU_COMPONENT}
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000127 PRIVATE
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +0000128 ethosu_npu_init.c
129 ethosu_cpu_cache.c)
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000130
131## Add dependencies:
Kshitij Sisodiaf98d0622022-03-18 11:44:48 +0000132target_link_libraries(${ETHOS_U_NPU_COMPONENT} PUBLIC
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000133 ethosu_core_driver
134 log)
135
Kshitij Sisodiaf98d0622022-03-18 11:44:48 +0000136## 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.
141if (TARGET rte_components)
142 target_link_libraries(${ETHOS_U_NPU_COMPONENT} PUBLIC
143 rte_components)
144else()
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.")
149endif()
150
151target_compile_definitions(${ETHOS_U_NPU_COMPONENT}
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000152 PUBLIC
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +0000153 ARM_NPU
Kshitij Sisodia8bc863d2022-03-24 17:53:34 +0000154 ${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 Sisodiad5679cc2022-03-03 16:30:07 +0000159
160# Display status
161message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR})
162message(STATUS "*******************************************************")
Kshitij Sisodiaf98d0622022-03-18 11:44:48 +0000163message(STATUS "Library : " ${ETHOS_U_NPU_COMPONENT})
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000164message(STATUS "*******************************************************")