blob: 8ead1469a4e3c61c474c40d0629722571c42e4d3 [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 Sisodiac22e80e2022-03-14 09:26:48 +000023set(ETHOS_U_NPU_INIT_COMPONENT ethos_u_npu)
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +000024project(${ETHOS_U_NPU_INIT_COMPONENT}
25 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
36# Driver needs to know what MAC configuration to build for.
37if(ETHOS_U_NPU_CONFIG_ID MATCHES "^[A-Z]([0-9]+$)")
38 set(ETHOSU_MACS ${CMAKE_MATCH_1})
39else()
40 message(FATAL_ERROR "Couldn't work out Ethos-U number of MACS from ${ETHOS_U_NPU_CONFIG_ID}")
41endif()
42set(ETHOSU_TARGET_NPU_CONFIG
43 "ethos-${ETHOS_U_NPU_ID}-${ETHOSU_MACS}" CACHE STRING "Target Ethos-U configuration for driver.")
44
45## Memory mode target definition
46if (NOT DEFINED ETHOS_U_NPU_ID)
47 set(ETHOS_U_NPU_ID U55)
48endif()
49
50if (NOT DEFINED ETHOS_U_NPU_MEMORY_MODE)
51 set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram)
52endif()
53
54if (ETHOS_U_NPU_MEMORY_MODE STREQUAL Sram_Only)
55 if (ETHOS_U_NPU_ID STREQUAL U55)
56 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEM_MODE_SRAM_ONLY")
57 else ()
58 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.")
59 endif ()
60elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Shared_Sram)
61 # Shared Sram can be used for Ethos-U55 and Ethos-U65
62 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_SHARED_SRAM")
63elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Dedicated_Sram)
64 # Dedicated Sram is used only for Ethos-U65
65 if (ETHOS_U_NPU_ID STREQUAL U65)
66 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}")
67 else ()
68 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.")
69 endif ()
70else ()
71 message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode ${ETHOS_U_NPU_MEMORY_MODE}")
72endif ()
73
Isabella Gottardib0b2bdc2022-03-10 17:08:37 +000074# Include the build for Ethos-U driver
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +000075add_subdirectory(${ETHOS_U_NPU_DRIVER_SRC_PATH} ${CMAKE_BINARY_DIR}/ethos-u-driver)
76
Isabella Gottardib0b2bdc2022-03-10 17:08:37 +000077# For Ethos-U driver, we need to override the default region configs
78# Region numbers are decided by Vela and they do not need to conform to set rules.
79# Traditionally they have been used as:
80#
81# Region 0: Weights and biases (and const tensors)
82# Region 1: IFM/OFM/Calculation buffers (tensor arena)
83# Region 2: Ethos-U'd dedicated cache region (fast cache memory)
84#
85# NOTE: The above scheme is completely dependent on Vela and could potentially
86# change.
87#
88# Common definitions:
89# For Ethos-U55/U65, Region configs are set as:
90# 0 or 1 = AXI0
91# 2 or 3 = AXI1
92target_compile_definitions(ethosu_core_driver PRIVATE
93 NPU_QCONFIG=3 # AXI1=M1 for U55/U65
94 NPU_REGIONCFG_0=3 # AXI1=M1 for U55/U65
95 NPU_REGIONCFG_2=1 # AXI0=M0 for U55/U65
96 NPU_REGIONCFG_3=1 # AXI0=M0 for U55/U65
97 NPU_REGIONCFG_4=1 # AXI0=M0 for U55/U65
98 NPU_REGIONCFG_5=1 # AXI0=M0 for U55/U65
99 NPU_REGIONCFG_6=1 # AXI0=M0 for U55/U65
100 NPU_REGIONCFG_7=1) # AXI0=M0 for U55/U65
101
102# Definitions relevant for all NPUs but depend on memory mode
103if (ETHOS_U_NPU_MEMORY_MODE STREQUAL Dedicated_Sram)
104 target_compile_definitions(ethosu_core_driver PRIVATE
105 NPU_REGIONCFG_1=3) # AXI1=M1 for U55/U65
106else()
107 target_compile_definitions(ethosu_core_driver PRIVATE
108 NPU_REGIONCFG_1=0) # AXI0=M0 for U55/U65
109endif()
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000110# Create static library
111add_library(${ETHOS_U_NPU_INIT_COMPONENT} STATIC)
112
113## Include directories - public
114target_include_directories(${ETHOS_U_NPU_INIT_COMPONENT}
115 PUBLIC
116 include
117 ${SOURCE_GEN_DIR})
118
119## Component sources
120target_sources(${ETHOS_U_NPU_INIT_COMPONENT}
121 PRIVATE
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +0000122 ethosu_npu_init.c
123 ethosu_cpu_cache.c)
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000124
125## Add dependencies:
126target_link_libraries(${ETHOS_U_NPU_INIT_COMPONENT} PUBLIC
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +0000127 cmsis_device_cpu_header
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000128 ethosu_core_driver
129 log)
130
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000131target_compile_definitions(${ETHOS_U_NPU_INIT_COMPONENT}
132 PUBLIC
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +0000133 ARM_NPU
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000134 ${ETHOS_U_NPU_MEMORY_MODE_FLAG})
135
136# Display status
137message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR})
138message(STATUS "*******************************************************")
139message(STATUS "Library : " ${ETHOS_U_NPU_INIT_COMPONENT})
140message(STATUS "*******************************************************")