Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build-run: Add Ethos NPU ID and MAC configuration option #48

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions applications/keyword_detection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,8 @@ set(MCUBOOT_IMAGE_VERSION_NS_UPDATE "0.0.1+20")

# Hardware platform specific setup
if (${ARM_CORSTONE_BSP_TARGET_PLATFORM} STREQUAL "corstone310")
set(ETHOS_U_NPU_ID "U55")
set(ETHOS_U_NPU_CONFIG_ID "H256")
set(ETHOSU_TARGET_NPU_CONFIG "ethos-u55-256")
set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram)
set(TFM_PLATFORM_LOCAL_PATH "arm/mps3/corstone310/fvp")
elseif (${ARM_CORSTONE_BSP_TARGET_PLATFORM} STREQUAL "corstone300")
set(ETHOS_U_NPU_ID "U55")
set(ETHOS_U_NPU_CONFIG_ID "H128")
set(ETHOSU_TARGET_NPU_CONFIG "ethos-u55-128")
set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram)
set(TFM_PLATFORM_LOCAL_PATH "arm/mps3/corstone300/fvp")
else()
message(FATAL_ERROR "Invalid ARM_CORSTONE_BSP_TARGET_PLATFORM (${ARM_CORSTONE_BSP_TARGET_PLATFORM}) set. Supported are corstone300/corstone310")
Expand Down
8 changes: 0 additions & 8 deletions applications/speech_recognition/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,8 @@ set(MCUBOOT_IMAGE_VERSION_NS_UPDATE "0.0.1+20")

# Hardware platform specific setup
if (${ARM_CORSTONE_BSP_TARGET_PLATFORM} STREQUAL "corstone310")
set(ETHOS_U_NPU_ID "U55")
set(ETHOS_U_NPU_CONFIG_ID "H256")
set(ETHOSU_TARGET_NPU_CONFIG "ethos-u55-256")
set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram)
set(TFM_PLATFORM_LOCAL_PATH "arm/mps3/corstone310/fvp")
elseif (${ARM_CORSTONE_BSP_TARGET_PLATFORM} STREQUAL "corstone300")
set(ETHOS_U_NPU_ID "U55")
set(ETHOS_U_NPU_CONFIG_ID "H128")
set(ETHOSU_TARGET_NPU_CONFIG "ethos-u55-128")
set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram)
set(TFM_PLATFORM_LOCAL_PATH "arm/mps3/corstone300/fvp")
else()
message(FATAL_ERROR "Invalid ARM_CORSTONE_BSP_TARGET_PLATFORM (${ARM_CORSTONE_BSP_TARGET_PLATFORM}) set. Supported are corstone300/corstone310")
Expand Down
43 changes: 43 additions & 0 deletions bsp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
# <[email protected]>
# SPDX-License-Identifier: Apache-2.0

function(build_ethosu_target_npu_config_values id num_macs)
if(id STREQUAL "U55")
set(ETHOS_U_NPU_CONFIG_ID "H${num_macs}" CACHE STRING "Specifies the configuration ID for the NPU." FORCE)
set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram CACHE STRING "Specifies the memory mode used in the Vela command." FORCE)
elseif(id STREQUAL "U65")
set(ETHOS_U_NPU_CONFIG_ID "Y${num_macs}" CACHE STRING "Specifies the configuration ID for the NPU." FORCE)
set(ETHOS_U_NPU_MEMORY_MODE Dedicated_Sram CACHE STRING "Specifies the memory mode used in the Vela command." FORCE)
set(ETHOS_U_NPU_CACHE_SIZE "393216" CACHE STRING "Arm Ethos-U65 NPU Cache Size" FORCE)
endif()
string(TOLOWER "${id}" id)
set(ETHOSU_TARGET_NPU_CONFIG "ethos-${id}-${num_macs}" CACHE STRING "Default NPU configuration" FORCE)
endfunction()

set(ARM_CORSTONE_BSP_TARGET_PLATFORM "corstone310" CACHE STRING "Featured Reference Integration target")

set(arm_corstone_platform_bsp_SOURCE_DIR
Expand Down Expand Up @@ -48,7 +61,18 @@ if(ARM_CORSTONE_BSP_TARGET_PLATFORM STREQUAL "corstone300")
set(ETHOS_U_IRQN "56" CACHE STRING "Ethos-U NPU Interrupt" FORCE)
set(ETHOS_U_SEC_ENABLED "0" CACHE STRING "Ethos-U NPU Security enable" FORCE)
set(ETHOS_U_PRIV_ENABLED "0" CACHE STRING "Ethos-U NPU Privilege enable" FORCE)
set(ETHOS_U_NPU_ID "U55" CACHE STRING "Arm Ethos-U NPU IP (U55 or U65)")
set(DEFAULT_ML_MAC_U55 "128")
set(DEFAULT_ML_MAC_U65 "256")
target_compile_definitions(arm-corstone-platform-bsp PUBLIC CORSTONE300_FVP)
set(VALID_ETHOSU_TARGET_NPU_CONFIGS
"ethos-u55-32"
"ethos-u55-64"
"ethos-u55-128"
"ethos-u55-256"
"ethos-u65-256"
"ethos-u65-512"
)
elseif(ARM_CORSTONE_BSP_TARGET_PLATFORM STREQUAL "corstone310")
set(BL2_IMAGE_LOAD_ADDRESS 0x11000000 CACHE STRING "Bootload image loading address")
set(S_IMAGE_LOAD_ADDRESS 0x38000000 CACHE STRING "Secure TF-M firmware loading address")
Expand All @@ -59,7 +83,26 @@ elseif(ARM_CORSTONE_BSP_TARGET_PLATFORM STREQUAL "corstone310")
set(ETHOS_U_IRQN "16" CACHE STRING "Ethos-U NPU Interrupt" FORCE)
set(ETHOS_U_SEC_ENABLED "0" CACHE STRING "Ethos-U NPU Security enable" FORCE)
set(ETHOS_U_PRIV_ENABLED "0" CACHE STRING "Ethos-U NPU Privilege enable" FORCE)
set(ETHOS_U_NPU_ID "U55" CACHE STRING "Arm Ethos-U NPU IP (U55 or U65)")
set(DEFAULT_ML_MAC_U55 "256")
set(DEFAULT_ML_MAC_U65 "256")
target_compile_definitions(arm-corstone-platform-bsp PUBLIC CORSTONE310_FVP)
set(VALID_ETHOSU_TARGET_NPU_CONFIGS
"ethos-u55-32"
"ethos-u55-64"
"ethos-u55-128"
"ethos-u55-256"
"ethos-u65-256"
"ethos-u65-512"
)
endif()
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")

build_ethosu_target_npu_config_values(${ETHOS_U_NPU_ID} ${ETHOS_U_NPU_NUM_MACS})

if(NOT ETHOSU_TARGET_NPU_CONFIG IN_LIST VALID_ETHOSU_TARGET_NPU_CONFIGS)
message(FATAL_ERROR "Invalid ETHOSU target configuration '${ETHOSU_TARGET_NPU_CONFIG}' for '${ARM_CORSTONE_BSP_TARGET_PLATFORM}'. "
"Choose from: ${VALID_ETHOSU_TARGET_NPU_CONFIGS}")
endif()

if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
Expand Down
7 changes: 7 additions & 0 deletions bsp/corstone300/an552_ns.ld
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ SECTIONS
{
. = ALIGN (16);
*(.bss.NoInit.activation_buf_sram)
*(.bss.NoInit.activation_buf_dram)
} > DDR AT > DDR

.vsibuffer :
Expand All @@ -219,6 +220,12 @@ SECTIONS
*(.bss.NoInit.vsi_audio_buffer)
} > DDR AT > DDR

.ethosucache :
{
. = ALIGN (16);
*(.bss.NoInit.ethos_u_cache)
} > DDR AT > DDR

.bss :
{
. = ALIGN(4);
Expand Down
6 changes: 6 additions & 0 deletions bsp/corstone300/an552_ns.sct
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@ LR_CODE (0x28000000 + ((((0) + (0x40000)) + (0x400)))) {
*.o (activation_buf)

; activation buffers a.k.a tensor arena when memory mode dedicated sram
*.o (.bss.NoInit.activation_buf_dram)

; activation buffers a.k.a tensor arena when
; memory mode sram only or shared sram
*.o (.bss.NoInit.activation_buf_sram)

; Buffer for transferring VSI audio data from S to NS
*.o (.bss.NoInit.vsi_audio_buffer)
; Cache area (if used)
*.o (.bss.NoInit.ethos_u_cache)
}
}
7 changes: 7 additions & 0 deletions bsp/corstone310/an555_ns.ld
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ SECTIONS
{
. = ALIGN (16);
*(.bss.NoInit.activation_buf_sram)
*(.bss.NoInit.activation_buf_dram)
} > DDR AT > DDR

.vsibuffer :
Expand All @@ -236,6 +237,12 @@ SECTIONS
*(.bss.NoInit.vsi_audio_buffer)
} > DDR AT > DDR

.ethosucache :
{
. = ALIGN (16);
*(.bss.NoInit.ethos_u_cache)
} > DDR AT > DDR

.bss :
{
. = ALIGN(4);
Expand Down
6 changes: 6 additions & 0 deletions bsp/corstone310/an555_ns.sct
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,15 @@ LR_CODE (ROM_START + ((((0) + (FLASH_S_PARTITION_SIZE)) + BL2_HEADER_SIZE))) {
*.o (activation_buf)

; activation buffers a.k.a tensor arena when memory mode dedicated sram
*.o (.bss.NoInit.activation_buf_dram)

; activation buffers a.k.a tensor arena when
; memory mode sram only or shared sram
*.o (.bss.NoInit.activation_buf_sram)

; Buffer for transferring VSI audio data from S to NS
*.o (.bss.NoInit.vsi_audio_buffer)
; Cache area (if used)
*.o (.bss.NoInit.ethos_u_cache)
}
}
2 changes: 2 additions & 0 deletions components/ai/ml_embedded_evaluation_kit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ set(PATCH_FILES_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/integration/patches")
set(PATCH_FILES
"${PATCH_FILES_DIRECTORY}/0001-resources-Replace-model-wav2letter-with-tiny_wav2let.patch"
"${PATCH_FILES_DIRECTORY}/0002-Use-CMSIS_device_header-instead-of-RTE_Components.h.patch"
"${PATCH_FILES_DIRECTORY}/0003-Make-ETHOSU_ARCH-configurable-in-TensorFlow-CMake.patch"
"${PATCH_FILES_DIRECTORY}/0004-Move-activation_buf_dram-to-.bss.NoInit-region.patch"
)
iot_reference_arm_corstone3xx_apply_patches("${ml_embedded_evaluation_kit_SOURCE_DIR}" "${PATCH_FILES}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ function(assert_defined var_name)
endif()
endfunction()

# Preserve the content of `ETHOS_U_NPU_ID` before including
# the `tensorflow.cmake` CMake module which overrides it.
set(TEMP_ETHOS_U_NPU_ID ${ETHOS_U_NPU_ID})
include(${CMAKE_SCRIPTS_DIR}/tensorflow.cmake)
set(ETHOS_U_NPU_ID ${TEMP_ETHOS_U_NPU_ID})

# Manually add libs
add_subdirectory(${ml_embedded_evaluation_kit_SOURCE_DIR}/source/log ${CMAKE_BINARY_DIR}/log)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 202176ddd60d709372bd4dd05fd5d6490fc2559e Mon Sep 17 00:00:00 2001
From 9ff3fa2ade014893d5406680db6dac8d79d9ef96 Mon Sep 17 00:00:00 2001
From: Gabor Abonyi <[email protected]>
Date: Mon, 22 Jan 2024 14:55:03 +0100
Subject: [PATCH 1/2] resources: Replace model wav2letter with tiny_wav2letter
Subject: [PATCH 1/4] resources: Replace model wav2letter with tiny_wav2letter

`wav2letter` model needs singificant amount of memory (around 14Mb),
where as `tiny_wav2letter` needs around 4Mb.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From ba95da37dcc0b41a14e7c8bc1ea707e0b1d99a79 Mon Sep 17 00:00:00 2001
From d0f5349dcdaba01a656f421adf2c21596290a9c8 Mon Sep 17 00:00:00 2001
From: Gabor Abonyi <[email protected]>
Date: Tue, 16 Jan 2024 14:48:44 +0100
Subject: [PATCH 2/2] Use CMSIS_device_header instead of RTE_Components.h
Subject: [PATCH 2/4] Use CMSIS_device_header instead of RTE_Components.h

Signed-off-by: Gabor Abonyi <[email protected]>
---
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
From f8afc14a716a88dfe27b9d62bbda79434f5245bb Mon Sep 17 00:00:00 2001
From: Gabor Abonyi <[email protected]>
Date: Mon, 29 Jan 2024 15:20:36 +0100
Subject: [PATCH 3/4] Make ETHOSU_ARCH configurable in TensorFlow CMake

Remove hardcoded value of u55 in tensorflow.cmake. Use ETHOS_U_NPU_ID
as input and convert it to the format needed by TensorFlow build.

Signed-off-by: Gabor Abonyi <[email protected]>
---
scripts/cmake/tensorflow.cmake | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/scripts/cmake/tensorflow.cmake b/scripts/cmake/tensorflow.cmake
index 0fa0f8c..e96eeac 100644
--- a/scripts/cmake/tensorflow.cmake
+++ b/scripts/cmake/tensorflow.cmake
@@ -68,9 +68,9 @@ else()
endif()

if(ETHOS_U_NPU_ENABLED)
- # Arm Ethos-U55 NPU is the co-processor for ML workload:
+ # Convert ETHOS_U_NPU_ID to match the format required by TensorFlow build:
set(TENSORFLOW_LITE_MICRO_CO_PROCESSOR "ethos_u")
- set(ETHOS_U_NPU_ID "u55") # Currently only u55 is supported by TFLite Micro.
+ string(TOLOWER "${ETHOS_U_NPU_ID}" TENSORFLOW_ETHOS_U_NPU_ID)
endif()

set(TENSORFLOW_LITE_MICRO_OPTIMIZED_KERNEL "cmsis_nn")
@@ -114,7 +114,7 @@ add_custom_target(tensorflow_build ALL
CMSIS_PATH=${CMSIS_SRC_PATH}
CMSIS_NN_PATH=${CMSIS_NN_SRC_PATH}
# Conditional arguments
- $<$<BOOL:${ETHOS_U_NPU_ENABLED}>:ETHOSU_ARCH=${ETHOS_U_NPU_ID}>
+ $<$<BOOL:${ETHOS_U_NPU_ENABLED}>:ETHOSU_ARCH=${TENSORFLOW_ETHOS_U_NPU_ID}>
$<$<BOOL:${ETHOS_U_NPU_ENABLED}>:ETHOSU_DRIVER_PATH=${ETHOS_U_NPU_DRIVER_SRC_PATH}>
$<$<BOOL:${ETHOS_U_NPU_ENABLED}>:ETHOSU_DRIVER_LIBS=$<TARGET_FILE:ethosu_core_driver>>

--
2.40.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
From 87e02e93935d2dcc7d48da6ddeed4eb893701610 Mon Sep 17 00:00:00 2001
From: Gabor Abonyi <[email protected]>
Date: Wed, 31 Jan 2024 11:56:52 +0100
Subject: [PATCH 4/4] 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]>
---
source/hal/source/components/npu/include/ethosu_mem_config.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source/hal/source/components/npu/include/ethosu_mem_config.h b/source/hal/source/components/npu/include/ethosu_mem_config.h
index 2cec141..f9ec205 100644
--- a/source/hal/source/components/npu/include/ethosu_mem_config.h
+++ b/source/hal/source/components/npu/include/ethosu_mem_config.h
@@ -49,7 +49,7 @@
#define ACTIVATION_BUF_SECTION section(".bss.NoInit.activation_buf_sram")
#define ACTIVATION_BUF_SECTION_NAME ("SRAM")
#elif (ETHOS_U_NPU_MEMORY_MODE==ETHOS_U_NPU_MEMORY_MODE_DEDICATED_SRAM)
- #define ACTIVATION_BUF_SECTION section("activation_buf_dram")
+ #define ACTIVATION_BUF_SECTION section(".bss.NoInit.activation_buf_dram")
#define CACHE_BUF_SECTION section(".bss.NoInit.ethos_u_cache")
#define ACTIVATION_BUF_SECTION_NAME ("DDR/DRAM")
#define CACHE_BUF_ATTRIBUTE __attribute__((aligned(ETHOS_U_MEM_BYTE_ALIGNMENT), CACHE_BUF_SECTION))
--
2.40.1

1 change: 1 addition & 0 deletions release_changes/202401311312.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ml-eval-kit: Add configurable NPU and MAC support
Loading
Loading