blob: 299fe4535edf06bcc470543951629d18f5a3c5cb [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
Kshitij Sisodia9c6f9f82022-05-20 14:30:02 +010022cmake_minimum_required(VERSION 3.21.0)
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.
Kshitij Sisodiaea8ce562022-04-12 11:10:11 +010043if (NOT DEFINED ETHOS_U_NPU_CONFIG_ID)
44 set(ETHOS_U_NPU_CONFIG_ID "H128")
45endif()
46
47## Memory mode target definition
48if (NOT DEFINED ETHOS_U_NPU_ID)
49 set(ETHOS_U_NPU_ID U55)
50endif()
51
Richard Burtonf4f240b2022-03-04 14:16:49 +000052if(ETHOS_U_NPU_CONFIG_ID MATCHES "^[A-Z]([0-9]+$)")
53 set(ETHOSU_MACS ${CMAKE_MATCH_1})
54else()
55 message(FATAL_ERROR "Couldn't work out Ethos-U number of MACS from ${ETHOS_U_NPU_CONFIG_ID}")
56endif()
57set(ETHOSU_TARGET_NPU_CONFIG
58 "ethos-${ETHOS_U_NPU_ID}-${ETHOSU_MACS}" CACHE STRING "Target Ethos-U configuration for driver.")
59
Richard Burtonf4f240b2022-03-04 14:16:49 +000060if (NOT DEFINED ETHOS_U_NPU_MEMORY_MODE)
61 set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram)
62endif()
63
64if (ETHOS_U_NPU_MEMORY_MODE STREQUAL Sram_Only)
65 if (ETHOS_U_NPU_ID STREQUAL U55)
66 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEM_MODE_SRAM_ONLY")
67 else ()
68 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.")
69 endif ()
70elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Shared_Sram)
71 # Shared Sram can be used for Ethos-U55 and Ethos-U65
72 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_SHARED_SRAM")
73elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Dedicated_Sram)
74 # Dedicated Sram is used only for Ethos-U65
75 if (ETHOS_U_NPU_ID STREQUAL U65)
76 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}")
77 else ()
78 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.")
79 endif ()
80else ()
81 message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode ${ETHOS_U_NPU_MEMORY_MODE}")
82endif ()
83
Isabella Gottardib0b2bdc2022-03-10 17:08:37 +000084# Include the build for Ethos-U driver
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +000085add_subdirectory(${ETHOS_U_NPU_DRIVER_SRC_PATH} ${CMAKE_BINARY_DIR}/ethos-u-driver)
86
Kshitij Sisodiaea8ce562022-04-12 11:10:11 +010087## Logging utilities:
88if (NOT TARGET log)
89 if (NOT DEFINED LOG_PROJECT_DIR)
90 message(FATAL_ERROR "LOG_PROJECT_DIR needs to be defined.")
91 endif()
92 add_subdirectory(${LOG_PROJECT_DIR} ${CMAKE_BINARY_DIR}/log)
93endif()
94
Isabella Gottardib0b2bdc2022-03-10 17:08:37 +000095# For Ethos-U driver, we need to override the default region configs
96# Region numbers are decided by Vela and they do not need to conform to set rules.
97# Traditionally they have been used as:
98#
99# Region 0: Weights and biases (and const tensors)
100# Region 1: IFM/OFM/Calculation buffers (tensor arena)
101# Region 2: Ethos-U'd dedicated cache region (fast cache memory)
102#
103# NOTE: The above scheme is completely dependent on Vela and could potentially
104# change.
105#
106# Common definitions:
107# For Ethos-U55/U65, Region configs are set as:
108# 0 or 1 = AXI0
109# 2 or 3 = AXI1
110target_compile_definitions(ethosu_core_driver PRIVATE
111 NPU_QCONFIG=3 # AXI1=M1 for U55/U65
112 NPU_REGIONCFG_0=3 # AXI1=M1 for U55/U65
113 NPU_REGIONCFG_2=1 # AXI0=M0 for U55/U65
114 NPU_REGIONCFG_3=1 # AXI0=M0 for U55/U65
115 NPU_REGIONCFG_4=1 # AXI0=M0 for U55/U65
116 NPU_REGIONCFG_5=1 # AXI0=M0 for U55/U65
117 NPU_REGIONCFG_6=1 # AXI0=M0 for U55/U65
118 NPU_REGIONCFG_7=1) # AXI0=M0 for U55/U65
119
120# Definitions relevant for all NPUs but depend on memory mode
121if (ETHOS_U_NPU_MEMORY_MODE STREQUAL Dedicated_Sram)
122 target_compile_definitions(ethosu_core_driver PRIVATE
123 NPU_REGIONCFG_1=3) # AXI1=M1 for U55/U65
124else()
125 target_compile_definitions(ethosu_core_driver PRIVATE
126 NPU_REGIONCFG_1=0) # AXI0=M0 for U55/U65
127endif()
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000128# Create static library
Kshitij Sisodiaf98d0622022-03-18 11:44:48 +0000129add_library(${ETHOS_U_NPU_COMPONENT} STATIC)
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000130
131## Include directories - public
Kshitij Sisodiaf98d0622022-03-18 11:44:48 +0000132target_include_directories(${ETHOS_U_NPU_COMPONENT}
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000133 PUBLIC
134 include
135 ${SOURCE_GEN_DIR})
136
137## Component sources
Kshitij Sisodiaf98d0622022-03-18 11:44:48 +0000138target_sources(${ETHOS_U_NPU_COMPONENT}
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000139 PRIVATE
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +0000140 ethosu_npu_init.c
Kshitij Sisodiada2ec062022-04-01 14:43:53 +0100141 ethosu_cpu_cache.c
142 ethosu_profiler.c)
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000143
144## Add dependencies:
Kshitij Sisodiaf98d0622022-03-18 11:44:48 +0000145target_link_libraries(${ETHOS_U_NPU_COMPONENT} PUBLIC
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000146 ethosu_core_driver
147 log)
148
Kshitij Sisodiaf98d0622022-03-18 11:44:48 +0000149## If the rte_components target has been defined, include it as a dependency here. This component
150## gives access to certain CPU related functions and definitions that should come from the CMSIS
151## or custom system setup and boot implementation files.
152## If the component is not defined as a target, a dependency for this target should be added by
153## the project importing this one.
154if (TARGET rte_components)
155 target_link_libraries(${ETHOS_U_NPU_COMPONENT} PUBLIC
156 rte_components)
157else()
158 message(WARNING
159 "rte_components target not defined."
160 "${ETHOS_U_NPU_COMPONENT} will need to be provided access to"
161 "RTE_Compnents.h header to include CPU specific definitions.")
162endif()
163
164target_compile_definitions(${ETHOS_U_NPU_COMPONENT}
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000165 PUBLIC
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +0000166 ARM_NPU
Kshitij Sisodia8bc863d2022-03-24 17:53:34 +0000167 ${ETHOS_U_NPU_MEMORY_MODE_FLAG}
168 ETHOS_U_BASE_ADDR=${ETHOS_U_BASE_ADDR}
169 ETHOS_U_IRQN=${ETHOS_U_IRQN}
170 ETHOS_U_SEC_ENABLED=${ETHOS_U_SEC_ENABLED}
171 ETHOS_U_PRIV_ENABLED=${ETHOS_U_PRIV_ENABLED})
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000172
173# Display status
174message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR})
175message(STATUS "*******************************************************")
Kshitij Sisodiaf98d0622022-03-18 11:44:48 +0000176message(STATUS "Library : " ${ETHOS_U_NPU_COMPONENT})
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000177message(STATUS "*******************************************************")