blob: 804fb45ee9ad4da9d20be50513eea0c64fa0391a [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
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +000074add_subdirectory(${ETHOS_U_NPU_DRIVER_SRC_PATH} ${CMAKE_BINARY_DIR}/ethos-u-driver)
75
76# Create static library
77add_library(${ETHOS_U_NPU_INIT_COMPONENT} STATIC)
78
79## Include directories - public
80target_include_directories(${ETHOS_U_NPU_INIT_COMPONENT}
81 PUBLIC
82 include
83 ${SOURCE_GEN_DIR})
84
85## Component sources
86target_sources(${ETHOS_U_NPU_INIT_COMPONENT}
87 PRIVATE
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +000088 ethosu_npu_init.c
89 ethosu_cpu_cache.c)
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +000090
91## Add dependencies:
92target_link_libraries(${ETHOS_U_NPU_INIT_COMPONENT} PUBLIC
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +000093 cmsis_device_cpu_header
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +000094 ethosu_core_driver
95 log)
96
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +000097target_compile_definitions(${ETHOS_U_NPU_INIT_COMPONENT}
98 PUBLIC
Kshitij Sisodiac22e80e2022-03-14 09:26:48 +000099 ARM_NPU
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +0000100 ${ETHOS_U_NPU_MEMORY_MODE_FLAG})
101
102# Display status
103message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR})
104message(STATUS "*******************************************************")
105message(STATUS "Library : " ${ETHOS_U_NPU_INIT_COMPONENT})
106message(STATUS "*******************************************************")