Skip to content

Commit bc8c624

Browse files
committed
samples: tflite_ethosu: support numaker_m55m1
This supports nuvoton numaker_m55m1 board, including: 1. Choosing NPU buffer as cacheable or non-cacheable, dependent on CONFIG_NOCACHE_MEMORY. When cachealbe is chosen, data cache flush/ invalidate weak functions (ethos-u core driver) are also overridden. 2. Add Vela-compiled model which matches this targets's NPU, Ethos-U55 with 256 macs_per_cc Besides, re-organize for new board support, including: 1. Refactor Vela-compiled models which must match target Ethos-U RTL config 2. Add non-Vela-compiled model for evaluation of no-Ethos-U platform Signed-off-by: Chun-Chieh Li <[email protected]>
1 parent 9d85e18 commit bc8c624

File tree

15 files changed

+15376
-5075
lines changed

15 files changed

+15376
-5075
lines changed

samples/modules/tflite-micro/tflm_ethosu/CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
88

99
project(tflm_ethosu_app)
1010

11-
target_include_directories(app PRIVATE src/models/keyword_spotting_cnn_small_int8)
11+
# Choose appropriate model
12+
if(CONFIG_TAINT_BLOBS_TFLM_ETHOSU)
13+
# Vela-compiled model must match Ethos-U RTL config, e.g. MACs per cycle
14+
target_include_directories_ifdef(CONFIG_BOARD_MPS3 app PRIVATE src/models/keyword_spotting_cnn_small_int8_ethos_u55_128)
15+
target_include_directories_ifdef(CONFIG_BOARD_NUMAKER_M55M1 app PRIVATE src/models/keyword_spotting_cnn_small_int8_ethos_u55_256)
16+
elseif(CONFIG_TAINT_BLOBS_TFLM)
17+
target_include_directories(app PRIVATE src/models/keyword_spotting_cnn_small_int8)
18+
endif()
1219

1320
target_sources(app PRIVATE src/main.cpp src/inference_process.cpp)
21+
target_sources_ifdef(CONFIG_BOARD_NUMAKER_M55M1 app PRIVATE src/npu_cache.c)
1422

15-
zephyr_linker_sources(SECTIONS linker.ld)
23+
# Add platform specific linker source snippet
24+
zephyr_linker_sources_ifdef(CONFIG_BOARD_MPS3 SECTIONS linker.ld)
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# Copyright 2022 Arm Limited and/or its affiliates <[email protected]>
22
# SPDX-License-Identifier: Apache-2.0
33

4-
config TFLM_ETHOSU_TAINT_BLOBS
4+
config TAINT_BLOBS_TFLM
55
bool
66
default y
77
select TAINT_BLOBS
88

9+
config TAINT_BLOBS_TFLM_ETHOSU
10+
bool "Choose Vela-compiled model targeting Ethos-U"
11+
default y
12+
depends on TAINT_BLOBS_TFLM
13+
914
source "Kconfig.zephyr"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* SPDX-License-Identifier: Apache-2.0 */
2+
3+
&npu0 {
4+
status = "okay";
5+
};

samples/modules/tflite-micro/tflm_ethosu/src/inference_process.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,16 @@ bool InferenceProcess::runJob(InferenceJob &job)
118118
}
119119

120120
/* Create the TFL micro interpreter */
121+
#ifdef CONFIG_TAINT_BLOBS_TFLM_ETHOSU
121122
tflite::MicroMutableOpResolver <1> resolver;
122123
resolver.AddEthosU();
123-
124+
#else
125+
tflite::MicroMutableOpResolver <4> resolver;
126+
resolver.AddReshape();
127+
resolver.AddConv2D();
128+
resolver.AddFullyConnected();
129+
resolver.AddSoftmax();
130+
#endif
124131
tflite::MicroInterpreter interpreter(model, resolver, tensorArena, tensorArenaSize);
125132

126133
/* Allocate tensors */

samples/modules/tflite-micro/tflm_ethosu/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ volatile int totalCompletedJobs = 0;
9898
/* TensorArena static initialisation */
9999
const size_t arenaSize = TENSOR_ARENA_SIZE_PER_INFERENCE;
100100

101-
__attribute__((section("tflm_arena"), aligned(16)))
101+
TENSOR_ARENA_ATTR
102102
uint8_t inferenceProcessTensorArena[NUM_INFERENCE_TASKS][arenaSize];
103103

104104
/* Allocate and initialize heap */

samples/modules/tflite-micro/tflm_ethosu/src/models/keyword_spotting_cnn_small_int8/input.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
__aligned(4) __attribute__((section("tflm_input"))) uint8_t inputData[] = {
7+
__aligned(4) __attribute__((section(".rodata.tflm_input"))) uint8_t inputData[] = {
88
0x2c, 0x8a, 0xff, 0x0c, 0xaf, 0x2a, 0x44, 0x17, 0xf5, 0x26, 0x96, 0x37, 0x40, 0x4c, 0xa1,
99
0x58, 0xc3, 0x33, 0xce, 0x1a, 0x7b, 0xd2, 0x22, 0x5b, 0x43, 0xf6, 0xfd, 0x0b, 0xe7, 0xfd,
1010
0x65, 0x58, 0x89, 0x24, 0xf4, 0xec, 0x53, 0x5e, 0x21, 0x1f, 0x95, 0xd1, 0xd9, 0x25, 0x72,

samples/modules/tflite-micro/tflm_ethosu/src/models/keyword_spotting_cnn_small_int8/model.h

Lines changed: 4977 additions & 5068 deletions
Large diffs are not rendered by default.

samples/modules/tflite-micro/tflm_ethosu/src/models/keyword_spotting_cnn_small_int8/output.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
__aligned(4) __attribute__((section("tflm_output"))) uint8_t expectedOutputData[] = {
7+
__aligned(4) __attribute__((section(".rodata.tflm_output"))) uint8_t expectedOutputData[] = {
88
0x80, 0x23, 0x80, 0x80, 0x80, 0x80, 0x80, 0x83, 0x80, 0x80, 0x81, 0xd9 };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2022 Arm Limited and/or its affiliates <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
__aligned(4) __attribute__((section("tflm_input"))) uint8_t inputData[] = {
8+
0x2c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