-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build-run: Add Ethos NPU ID and MAC configuration option (#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]>
- Loading branch information
1 parent
f79e362
commit 32ea1a0
Showing
16 changed files
with
241 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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") | ||
|
@@ -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") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...n_kit/integration/patches/0001-resources-Replace-model-wav2letter-with-tiny_wav2let.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
4 changes: 2 additions & 2 deletions
4
...on_kit/integration/patches/0002-Use-CMSIS_device_header-instead-of-RTE_Components.h.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]> | ||
--- | ||
|
41 changes: 41 additions & 0 deletions
41
...tion_kit/integration/patches/0003-Make-ETHOSU_ARCH-configurable-in-TensorFlow-CMake.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
29 changes: 29 additions & 0 deletions
29
...luation_kit/integration/patches/0004-Move-activation_buf_dram-to-.bss.NoInit-region.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ml-eval-kit: Add configurable NPU and MAC support |
Oops, something went wrong.