Skip to content

Commit 32ea1a0

Browse files
authored
build-run: Add Ethos NPU ID and MAC configuration option (FreeRTOS#48)
* ml-eval-kit: Make ETHOSU_ARCH configurable in TensorFlow CMake This patch removes the hardcoded value of u55 in tesorflow.cmake. It now uses ETHOS_U_NPU_ID as input and convert it to the format needed by TensorFlow build. This also means the ETHOS_U_NPU_ID variable preserve workaround is no longer needed in SetupMlEmbeddedEvaluationKitLibraries.cmake as it is no longer overwritten in tensorflow.cmake. Signed-off-by: Gabor Abonyi <[email protected]> * ml-eval-kit: Move NPU config from app to bsp These settings are independent from the applications, to reduce duplication, configuration of NPU is moved to bsp layer. Added U65 option and checks for config validity. Signed-off-by: Gabor Abonyi <[email protected]> * ml-eval-kit: Move activation_buf_dram to .bss.NoInit region This is needed to place activation_buf_dram in a no init region, so it does not require space in flash. Signed-off-by: Gabor Abonyi <[email protected]> * build-run: Add support for Ethos NPU ID and MAC cycle configuration * Add option to the build/run scripts to select different Ethos NPU * Add option to the buld script to select number of Ethos NPU MAC unit per cycle Signed-off-by: Gabor Abonyi <[email protected]> * build-run: Use a shell variable to gather CMake arguments This is so some CMake arguments can be excluded more easily depending on the build configuration. It will remove the need to set default values for CMake cache variables from the scripts as CMake cache variables already have default values. This change allows a standard overriding of CMake cache variable in CMake scripts without a check to see if the user input a value for the cache variable. Signed-off-by: Gabor Abonyi <[email protected]> * build: Unify error report format in build.sh Signed-off-by: Gabor Abonyi <[email protected]> --------- Signed-off-by: Gabor Abonyi <[email protected]>
1 parent f79e362 commit 32ea1a0

16 files changed

+241
-43
lines changed

applications/keyword_detection/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,8 @@ set(MCUBOOT_IMAGE_VERSION_NS_UPDATE "0.0.1+20")
3131

3232
# Hardware platform specific setup
3333
if (${ARM_CORSTONE_BSP_TARGET_PLATFORM} STREQUAL "corstone310")
34-
set(ETHOS_U_NPU_ID "U55")
35-
set(ETHOS_U_NPU_CONFIG_ID "H256")
36-
set(ETHOSU_TARGET_NPU_CONFIG "ethos-u55-256")
37-
set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram)
3834
set(TFM_PLATFORM_LOCAL_PATH "arm/mps3/corstone310/fvp")
3935
elseif (${ARM_CORSTONE_BSP_TARGET_PLATFORM} STREQUAL "corstone300")
40-
set(ETHOS_U_NPU_ID "U55")
41-
set(ETHOS_U_NPU_CONFIG_ID "H128")
42-
set(ETHOSU_TARGET_NPU_CONFIG "ethos-u55-128")
43-
set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram)
4436
set(TFM_PLATFORM_LOCAL_PATH "arm/mps3/corstone300/fvp")
4537
else()
4638
message(FATAL_ERROR "Invalid ARM_CORSTONE_BSP_TARGET_PLATFORM (${ARM_CORSTONE_BSP_TARGET_PLATFORM}) set. Supported are corstone300/corstone310")

applications/speech_recognition/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,8 @@ set(MCUBOOT_IMAGE_VERSION_NS_UPDATE "0.0.1+20")
3131

3232
# Hardware platform specific setup
3333
if (${ARM_CORSTONE_BSP_TARGET_PLATFORM} STREQUAL "corstone310")
34-
set(ETHOS_U_NPU_ID "U55")
35-
set(ETHOS_U_NPU_CONFIG_ID "H256")
36-
set(ETHOSU_TARGET_NPU_CONFIG "ethos-u55-256")
37-
set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram)
3834
set(TFM_PLATFORM_LOCAL_PATH "arm/mps3/corstone310/fvp")
3935
elseif (${ARM_CORSTONE_BSP_TARGET_PLATFORM} STREQUAL "corstone300")
40-
set(ETHOS_U_NPU_ID "U55")
41-
set(ETHOS_U_NPU_CONFIG_ID "H128")
42-
set(ETHOSU_TARGET_NPU_CONFIG "ethos-u55-128")
43-
set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram)
4436
set(TFM_PLATFORM_LOCAL_PATH "arm/mps3/corstone300/fvp")
4537
else()
4638
message(FATAL_ERROR "Invalid ARM_CORSTONE_BSP_TARGET_PLATFORM (${ARM_CORSTONE_BSP_TARGET_PLATFORM}) set. Supported are corstone300/corstone310")

bsp/CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
33
# SPDX-License-Identifier: Apache-2.0
44

5+
function(build_ethosu_target_npu_config_values id num_macs)
6+
if(id STREQUAL "U55")
7+
set(ETHOS_U_NPU_CONFIG_ID "H${num_macs}" CACHE STRING "Specifies the configuration ID for the NPU." FORCE)
8+
set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram CACHE STRING "Specifies the memory mode used in the Vela command." FORCE)
9+
elseif(id STREQUAL "U65")
10+
set(ETHOS_U_NPU_CONFIG_ID "Y${num_macs}" CACHE STRING "Specifies the configuration ID for the NPU." FORCE)
11+
set(ETHOS_U_NPU_MEMORY_MODE Dedicated_Sram CACHE STRING "Specifies the memory mode used in the Vela command." FORCE)
12+
set(ETHOS_U_NPU_CACHE_SIZE "393216" CACHE STRING "Arm Ethos-U65 NPU Cache Size" FORCE)
13+
endif()
14+
string(TOLOWER "${id}" id)
15+
set(ETHOSU_TARGET_NPU_CONFIG "ethos-${id}-${num_macs}" CACHE STRING "Default NPU configuration" FORCE)
16+
endfunction()
17+
518
set(ARM_CORSTONE_BSP_TARGET_PLATFORM "corstone310" CACHE STRING "Featured Reference Integration target")
619

720
set(arm_corstone_platform_bsp_SOURCE_DIR
@@ -48,7 +61,18 @@ if(ARM_CORSTONE_BSP_TARGET_PLATFORM STREQUAL "corstone300")
4861
set(ETHOS_U_IRQN "56" CACHE STRING "Ethos-U NPU Interrupt" FORCE)
4962
set(ETHOS_U_SEC_ENABLED "0" CACHE STRING "Ethos-U NPU Security enable" FORCE)
5063
set(ETHOS_U_PRIV_ENABLED "0" CACHE STRING "Ethos-U NPU Privilege enable" FORCE)
64+
set(ETHOS_U_NPU_ID "U55" CACHE STRING "Arm Ethos-U NPU IP (U55 or U65)")
65+
set(DEFAULT_ML_MAC_U55 "128")
66+
set(DEFAULT_ML_MAC_U65 "256")
5167
target_compile_definitions(arm-corstone-platform-bsp PUBLIC CORSTONE300_FVP)
68+
set(VALID_ETHOSU_TARGET_NPU_CONFIGS
69+
"ethos-u55-32"
70+
"ethos-u55-64"
71+
"ethos-u55-128"
72+
"ethos-u55-256"
73+
"ethos-u65-256"
74+
"ethos-u65-512"
75+
)
5276
elseif(ARM_CORSTONE_BSP_TARGET_PLATFORM STREQUAL "corstone310")
5377
set(BL2_IMAGE_LOAD_ADDRESS 0x11000000 CACHE STRING "Bootload image loading address")
5478
set(S_IMAGE_LOAD_ADDRESS 0x38000000 CACHE STRING "Secure TF-M firmware loading address")
@@ -59,7 +83,26 @@ elseif(ARM_CORSTONE_BSP_TARGET_PLATFORM STREQUAL "corstone310")
5983
set(ETHOS_U_IRQN "16" CACHE STRING "Ethos-U NPU Interrupt" FORCE)
6084
set(ETHOS_U_SEC_ENABLED "0" CACHE STRING "Ethos-U NPU Security enable" FORCE)
6185
set(ETHOS_U_PRIV_ENABLED "0" CACHE STRING "Ethos-U NPU Privilege enable" FORCE)
86+
set(ETHOS_U_NPU_ID "U55" CACHE STRING "Arm Ethos-U NPU IP (U55 or U65)")
87+
set(DEFAULT_ML_MAC_U55 "256")
88+
set(DEFAULT_ML_MAC_U65 "256")
6289
target_compile_definitions(arm-corstone-platform-bsp PUBLIC CORSTONE310_FVP)
90+
set(VALID_ETHOSU_TARGET_NPU_CONFIGS
91+
"ethos-u55-32"
92+
"ethos-u55-64"
93+
"ethos-u55-128"
94+
"ethos-u55-256"
95+
"ethos-u65-256"
96+
"ethos-u65-512"
97+
)
98+
endif()
99+
set(ETHOS_U_NPU_NUM_MACS ${DEFAULT_ML_MAC_${ETHOS_U_NPU_ID}} CACHE STRING "Number of 8x8 MACs performed per cycle by the NPU")
100+
101+
build_ethosu_target_npu_config_values(${ETHOS_U_NPU_ID} ${ETHOS_U_NPU_NUM_MACS})
102+
103+
if(NOT ETHOSU_TARGET_NPU_CONFIG IN_LIST VALID_ETHOSU_TARGET_NPU_CONFIGS)
104+
message(FATAL_ERROR "Invalid ETHOSU target configuration '${ETHOSU_TARGET_NPU_CONFIG}' for '${ARM_CORSTONE_BSP_TARGET_PLATFORM}'. "
105+
"Choose from: ${VALID_ETHOSU_TARGET_NPU_CONFIGS}")
63106
endif()
64107

65108
if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")

bsp/corstone300/an552_ns.ld

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ SECTIONS
210210
{
211211
. = ALIGN (16);
212212
*(.bss.NoInit.activation_buf_sram)
213+
*(.bss.NoInit.activation_buf_dram)
213214
} > DDR AT > DDR
214215

215216
.vsibuffer :
@@ -219,6 +220,12 @@ SECTIONS
219220
*(.bss.NoInit.vsi_audio_buffer)
220221
} > DDR AT > DDR
221222

223+
.ethosucache :
224+
{
225+
. = ALIGN (16);
226+
*(.bss.NoInit.ethos_u_cache)
227+
} > DDR AT > DDR
228+
222229
.bss :
223230
{
224231
. = ALIGN(4);

bsp/corstone300/an552_ns.sct

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,15 @@ LR_CODE (0x28000000 + ((((0) + (0x40000)) + (0x400)))) {
4242
*.o (activation_buf)
4343

4444
; activation buffers a.k.a tensor arena when memory mode dedicated sram
45+
*.o (.bss.NoInit.activation_buf_dram)
46+
47+
; activation buffers a.k.a tensor arena when
48+
; memory mode sram only or shared sram
4549
*.o (.bss.NoInit.activation_buf_sram)
4650

4751
; Buffer for transferring VSI audio data from S to NS
4852
*.o (.bss.NoInit.vsi_audio_buffer)
53+
; Cache area (if used)
54+
*.o (.bss.NoInit.ethos_u_cache)
4955
}
5056
}

bsp/corstone310/an555_ns.ld

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ SECTIONS
227227
{
228228
. = ALIGN (16);
229229
*(.bss.NoInit.activation_buf_sram)
230+
*(.bss.NoInit.activation_buf_dram)
230231
} > DDR AT > DDR
231232

232233
.vsibuffer :
@@ -236,6 +237,12 @@ SECTIONS
236237
*(.bss.NoInit.vsi_audio_buffer)
237238
} > DDR AT > DDR
238239

240+
.ethosucache :
241+
{
242+
. = ALIGN (16);
243+
*(.bss.NoInit.ethos_u_cache)
244+
} > DDR AT > DDR
245+
239246
.bss :
240247
{
241248
. = ALIGN(4);

bsp/corstone310/an555_ns.sct

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,15 @@ LR_CODE (ROM_START + ((((0) + (FLASH_S_PARTITION_SIZE)) + BL2_HEADER_SIZE))) {
6767
*.o (activation_buf)
6868

6969
; activation buffers a.k.a tensor arena when memory mode dedicated sram
70+
*.o (.bss.NoInit.activation_buf_dram)
71+
72+
; activation buffers a.k.a tensor arena when
73+
; memory mode sram only or shared sram
7074
*.o (.bss.NoInit.activation_buf_sram)
7175

7276
; Buffer for transferring VSI audio data from S to NS
7377
*.o (.bss.NoInit.vsi_audio_buffer)
78+
; Cache area (if used)
79+
*.o (.bss.NoInit.ethos_u_cache)
7480
}
7581
}

components/ai/ml_embedded_evaluation_kit/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ set(PATCH_FILES_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/integration/patches")
1414
set(PATCH_FILES
1515
"${PATCH_FILES_DIRECTORY}/0001-resources-Replace-model-wav2letter-with-tiny_wav2let.patch"
1616
"${PATCH_FILES_DIRECTORY}/0002-Use-CMSIS_device_header-instead-of-RTE_Components.h.patch"
17+
"${PATCH_FILES_DIRECTORY}/0003-Make-ETHOSU_ARCH-configurable-in-TensorFlow-CMake.patch"
18+
"${PATCH_FILES_DIRECTORY}/0004-Move-activation_buf_dram-to-.bss.NoInit-region.patch"
1719
)
1820
iot_reference_arm_corstone3xx_apply_patches("${ml_embedded_evaluation_kit_SOURCE_DIR}" "${PATCH_FILES}")
1921

components/ai/ml_embedded_evaluation_kit/integration/cmake/SetupMlEmbeddedEvaluationKitLibraries.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@ function(assert_defined var_name)
5959
endif()
6060
endfunction()
6161

62-
# Preserve the content of `ETHOS_U_NPU_ID` before including
63-
# the `tensorflow.cmake` CMake module which overrides it.
64-
set(TEMP_ETHOS_U_NPU_ID ${ETHOS_U_NPU_ID})
6562
include(${CMAKE_SCRIPTS_DIR}/tensorflow.cmake)
66-
set(ETHOS_U_NPU_ID ${TEMP_ETHOS_U_NPU_ID})
6763

6864
# Manually add libs
6965
add_subdirectory(${ml_embedded_evaluation_kit_SOURCE_DIR}/source/log ${CMAKE_BINARY_DIR}/log)

components/ai/ml_embedded_evaluation_kit/integration/patches/0001-resources-Replace-model-wav2letter-with-tiny_wav2let.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From 202176ddd60d709372bd4dd05fd5d6490fc2559e Mon Sep 17 00:00:00 2001
1+
From 9ff3fa2ade014893d5406680db6dac8d79d9ef96 Mon Sep 17 00:00:00 2001
22
From: Gabor Abonyi <[email protected]>
33
Date: Mon, 22 Jan 2024 14:55:03 +0100
4-
Subject: [PATCH 1/2] resources: Replace model wav2letter with tiny_wav2letter
4+
Subject: [PATCH 1/4] resources: Replace model wav2letter with tiny_wav2letter
55

66
`wav2letter` model needs singificant amount of memory (around 14Mb),
77
where as `tiny_wav2letter` needs around 4Mb.

components/ai/ml_embedded_evaluation_kit/integration/patches/0002-Use-CMSIS_device_header-instead-of-RTE_Components.h.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From ba95da37dcc0b41a14e7c8bc1ea707e0b1d99a79 Mon Sep 17 00:00:00 2001
1+
From d0f5349dcdaba01a656f421adf2c21596290a9c8 Mon Sep 17 00:00:00 2001
22
From: Gabor Abonyi <[email protected]>
33
Date: Tue, 16 Jan 2024 14:48:44 +0100
4-
Subject: [PATCH 2/2] Use CMSIS_device_header instead of RTE_Components.h
4+
Subject: [PATCH 2/4] Use CMSIS_device_header instead of RTE_Components.h
55

66
Signed-off-by: Gabor Abonyi <[email protected]>
77
---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
From f8afc14a716a88dfe27b9d62bbda79434f5245bb Mon Sep 17 00:00:00 2001
2+
From: Gabor Abonyi <[email protected]>
3+
Date: Mon, 29 Jan 2024 15:20:36 +0100
4+
Subject: [PATCH 3/4] Make ETHOSU_ARCH configurable in TensorFlow CMake
5+
6+
Remove hardcoded value of u55 in tensorflow.cmake. Use ETHOS_U_NPU_ID
7+
as input and convert it to the format needed by TensorFlow build.
8+
9+
Signed-off-by: Gabor Abonyi <[email protected]>
10+
---
11+
scripts/cmake/tensorflow.cmake | 6 +++---
12+
1 file changed, 3 insertions(+), 3 deletions(-)
13+
14+
diff --git a/scripts/cmake/tensorflow.cmake b/scripts/cmake/tensorflow.cmake
15+
index 0fa0f8c..e96eeac 100644
16+
--- a/scripts/cmake/tensorflow.cmake
17+
+++ b/scripts/cmake/tensorflow.cmake
18+
@@ -68,9 +68,9 @@ else()
19+
endif()
20+
21+
if(ETHOS_U_NPU_ENABLED)
22+
- # Arm Ethos-U55 NPU is the co-processor for ML workload:
23+
+ # Convert ETHOS_U_NPU_ID to match the format required by TensorFlow build:
24+
set(TENSORFLOW_LITE_MICRO_CO_PROCESSOR "ethos_u")
25+
- set(ETHOS_U_NPU_ID "u55") # Currently only u55 is supported by TFLite Micro.
26+
+ string(TOLOWER "${ETHOS_U_NPU_ID}" TENSORFLOW_ETHOS_U_NPU_ID)
27+
endif()
28+
29+
set(TENSORFLOW_LITE_MICRO_OPTIMIZED_KERNEL "cmsis_nn")
30+
@@ -114,7 +114,7 @@ add_custom_target(tensorflow_build ALL
31+
CMSIS_PATH=${CMSIS_SRC_PATH}
32+
CMSIS_NN_PATH=${CMSIS_NN_SRC_PATH}
33+
# Conditional arguments
34+
- $<$<BOOL:${ETHOS_U_NPU_ENABLED}>:ETHOSU_ARCH=${ETHOS_U_NPU_ID}>
35+
+ $<$<BOOL:${ETHOS_U_NPU_ENABLED}>:ETHOSU_ARCH=${TENSORFLOW_ETHOS_U_NPU_ID}>
36+
$<$<BOOL:${ETHOS_U_NPU_ENABLED}>:ETHOSU_DRIVER_PATH=${ETHOS_U_NPU_DRIVER_SRC_PATH}>
37+
$<$<BOOL:${ETHOS_U_NPU_ENABLED}>:ETHOSU_DRIVER_LIBS=$<TARGET_FILE:ethosu_core_driver>>
38+
39+
--
40+
2.40.1
41+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
From 87e02e93935d2dcc7d48da6ddeed4eb893701610 Mon Sep 17 00:00:00 2001
2+
From: Gabor Abonyi <[email protected]>
3+
Date: Wed, 31 Jan 2024 11:56:52 +0100
4+
Subject: [PATCH 4/4] Move activation_buf_dram to .bss.NoInit region
5+
6+
This is needed to place activation_buf_dram in a no init region, so
7+
it does not require space in flash.
8+
9+
Signed-off-by: Gabor Abonyi <[email protected]>
10+
---
11+
source/hal/source/components/npu/include/ethosu_mem_config.h | 2 +-
12+
1 file changed, 1 insertion(+), 1 deletion(-)
13+
14+
diff --git a/source/hal/source/components/npu/include/ethosu_mem_config.h b/source/hal/source/components/npu/include/ethosu_mem_config.h
15+
index 2cec141..f9ec205 100644
16+
--- a/source/hal/source/components/npu/include/ethosu_mem_config.h
17+
+++ b/source/hal/source/components/npu/include/ethosu_mem_config.h
18+
@@ -49,7 +49,7 @@
19+
#define ACTIVATION_BUF_SECTION section(".bss.NoInit.activation_buf_sram")
20+
#define ACTIVATION_BUF_SECTION_NAME ("SRAM")
21+
#elif (ETHOS_U_NPU_MEMORY_MODE==ETHOS_U_NPU_MEMORY_MODE_DEDICATED_SRAM)
22+
- #define ACTIVATION_BUF_SECTION section("activation_buf_dram")
23+
+ #define ACTIVATION_BUF_SECTION section(".bss.NoInit.activation_buf_dram")
24+
#define CACHE_BUF_SECTION section(".bss.NoInit.ethos_u_cache")
25+
#define ACTIVATION_BUF_SECTION_NAME ("DDR/DRAM")
26+
#define CACHE_BUF_ATTRIBUTE __attribute__((aligned(ETHOS_U_MEM_BYTE_ALIGNMENT), CACHE_BUF_SECTION))
27+
--
28+
2.40.1
29+

release_changes/202401311312.change

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ml-eval-kit: Add configurable NPU and MAC support

0 commit comments

Comments
 (0)