Skip to content

Commit 30a904b

Browse files
authored
Arm backend: Add support for ETDump of outputs
Differential Revision: D82454608 Pull Request resolved: #14143
1 parent 750cba7 commit 30a904b

File tree

6 files changed

+357
-101
lines changed

6 files changed

+357
-101
lines changed

backends/arm/scripts/build_executor_runner.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ help() {
4444
echo " --memory_mode=<CONFIG> Vela memory mode, used for setting the Timing Adapter parameters of the Corstone platforms."
4545
echo " Valid values are Shared_Sram(for Ethos-U55, Ethos-U65, Ethos-85), Sram_Only(for Ethos-U55, Ethos-U65, Ethos-U85) or Dedicated_Sram(for Ethos-U65, Ethos-U85)."
4646
echo " Default: Shared_Sram for the Ethos-U55 and Sram_Only for the Ethos-U85"
47-
echo " --etdump Adds Devtools etdump support to track timing, etdump area will be base64 encoded in the log"
47+
echo " --etdump Adds Devtools etdump support to track timing and output, etdump area will be base64 encoded in the log"
4848
echo " --extra_build_flags=<FLAGS> Extra flags to pass to cmake like -DET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE=60000 Default: none "
4949
echo " --output=<FOLDER> Output folder Default: <MODEL>/<MODEL>_<TARGET INFO>.pte"
5050
echo " --et_build_root=<FOLDER> Build output root folder to use, defaults to ${et_build_root}"
@@ -161,7 +161,7 @@ if [ "$bundleio" = true ] ; then
161161
fi
162162

163163
if [ "$build_with_etdump" = true ] ; then
164-
build_with_etdump_flags=" -DEXECUTORCH_ENABLE_EVENT_TRACER=ON "
164+
build_with_etdump_flags=" -DEXECUTORCH_ENABLE_EVENT_TRACER=ON -DET_DUMP_INTERMEDIATE_OUTPUTS=ON "
165165
fi
166166

167167
echo "Building with BundleIO/etdump/extra flags: ${build_bundleio_flags} ${build_with_etdump_flags} ${extra_build_flags}"

backends/arm/scripts/run_fvp.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ elf_file=""
2121
data_file=""
2222
target="ethos-u55-128"
2323
timeout="600"
24+
etrecord_file=""
2425

2526
help() {
2627
echo "Usage: $(basename $0) [options]"
@@ -29,6 +30,7 @@ help() {
2930
echo " --data=<FILE>@<ADDRESS> Place a file in memory at this address, useful to emulate a PTE flashed into memory instead as part of the code."
3031
echo " --target=<TARGET> Target to build and run for Default: ${target}"
3132
echo " --timeout=<TIME_IN_SEC> Maximum target runtime, used to detect hanging, might need to be higer on large models Default: ${timeout}"
33+
echo " --etrecord=<FILE> If ETDump is used you can supply a ETRecord file matching the PTE"
3234
exit 0
3335
}
3436

@@ -39,6 +41,7 @@ for arg in "$@"; do
3941
--data=*) data_file="--data ${arg#*=}";;
4042
--target=*) target="${arg#*=}";;
4143
--timeout=*) timeout="${arg#*=}";;
44+
--etrecord=*) etrecord_file="${arg#*=}";;
4245
*)
4346
;;
4447
esac
@@ -115,15 +118,23 @@ echo "Checking for a etdump in log"
115118
! grep "#\[RUN THIS\]" ${log_file} >/dev/null
116119
if [ $? != 0 ]; then
117120
echo "Found ETDump in log!"
121+
devtools_extra_args=""
118122
echo "#!/bin/sh" > etdump_script.sh
119123
sed -n '/^#\[RUN THIS\]$/,/^#\[END\]$/p' ${log_file} >> etdump_script.sh
120124
# You can run etdump_script.sh if you do
121125
# $ chmod a+x etdump_script.sh
122126
# $ ./etdump_script.sh
123127
# But lets not trust the script as a bad patch would run bad code on your machine
124-
grep ">etdump.bin" etdump_script.sh | cut -d\" -f2- | cut -d\" -f1 >etdump.base64
125-
base64 -d etdump.base64 >etdump.bin
126-
python3 -m devtools.inspector.inspector_cli --etdump_path etdump.bin --source_time_scale cycles --target_time_scale cycles
128+
grep ">etdump.bin" etdump_script.sh | cut -d\" -f2- | cut -d\" -f1 | base64 -d >etdump.bin
129+
! grep ">debug_buffer.bin" etdump_script.sh >/dev/null
130+
if [ $? != 0 ]; then
131+
grep ">debug_buffer.bin" etdump_script.sh | cut -d\" -f2- | cut -d\" -f1 | base64 -d >debug_buffer.bin
132+
devtools_extra_args="${devtools_extra_args} --debug_buffer_path debug_buffer.bin"
133+
fi
134+
if [[ ${etrecord_file} != "" ]]; then
135+
devtools_extra_args="${devtools_extra_args} --etrecord_path ${etrecord_file}"
136+
fi
137+
python3 -m devtools.inspector.inspector_cli --etdump_path etdump.bin ${devtools_extra_args} --source_time_scale cycles --target_time_scale cycles
127138
fi
128139

129140
echo "Checking for problems in log:"

backends/arm/test/test_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def build_ethosu_runtime(
184184
"--build_type=Release",
185185
f"--system_config={system_config}",
186186
f"--memory_mode={memory_mode}",
187-
f"--extra_build_flags=-DET_DUMP_OUTPUT=OFF {extra_flags}",
187+
f"--extra_build_flags=-DET_LOG_DUMP_OUTPUT=OFF {extra_flags}",
188188
f"--output={elf_build_path}",
189189
]
190190
)

examples/arm/executor_runner/CMakeLists.txt

Lines changed: 95 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,59 @@
66
cmake_minimum_required(VERSION 3.20)
77
project(arm_executor_runner)
88

9-
option(SEMIHOSTING "Enable semihosting" OFF)
10-
option(
11-
ET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE
12-
"Set ET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE to specify memory alloction pool size"
13-
OFF
14-
)
159
option(
1610
ET_MODEL_PTE_ADDR
1711
"Place in memory that the PTE file is located/flashed, if set to OFF the PTE is built into the code as a big data area."
1812
OFF
1913
)
20-
option(ET_BUNDLE_IO "Set to compile in BundleIO support" OFF)
21-
option(ET_ATOL "Set atol to use for BundleIO testing" OFF)
22-
option(ET_RTOL "Set rtol to use for BundleIO testing" OFF)
23-
option(ET_DUMP_INPUT "Dump input in log" OFF)
24-
option(ET_DUMP_OUTPUT "Dump output in log" ON)
25-
option(FETCH_ETHOS_U_CONTENT
26-
"Fetch ethos_u dependencies instead of relying on pre-downloads" ON
27-
)
14+
2815
set(ET_NUM_INFERENCES
2916
"1"
3017
CACHE STRING "Number of inferences to run"
3118
)
3219

20+
option(ET_LOG_DUMP_INPUT "Dump input in log" OFF)
21+
option(ET_LOG_DUMP_OUTPUT "Dump output in log" ON)
22+
23+
option(ET_BUNDLE_IO "Set to compile in BundleIO support" OFF)
24+
set(ET_ATOL
25+
"0.01"
26+
CACHE STRING "Set atol to use for BundleIO testing (Requires ET_BUNDLE_IO)"
27+
)
28+
set(ET_RTOL
29+
"0.01"
30+
CACHE STRING "Set atol to use for BundleIO testing (Requires ET_BUNDLE_IO)"
31+
)
32+
33+
option(
34+
ET_DUMP_OUTPUTS
35+
"Collect and print outputs as a base64 buffer in the log (Requires EXECUTORCH_ENABLE_EVENT_TRACER)"
36+
OFF
37+
)
38+
option(
39+
ET_DUMP_INTERMEDIATE_OUTPUTS
40+
"Collect and print intermediate outputs as a base64 buffer in the log (Requires EXECUTORCH_ENABLE_EVENT_TRACER)"
41+
OFF
42+
)
43+
set(ET_DEBUG_BUFFER_SIZE
44+
"2097152"
45+
CACHE
46+
STRING
47+
"Size of buffer to collect intermediate outputs/outputs buffers (Requires EXECUTORCH_ENABLE_EVENT_TRACER and ET_DUMP_OUTPUTS or ET_DUMP_INTERMEDIATE_OUTPUTS)"
48+
)
49+
50+
option(SEMIHOSTING "Enable semihosting" OFF)
51+
52+
option(
53+
ET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE
54+
"Set ET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE to specify memory alloction pool size"
55+
OFF
56+
)
57+
58+
option(FETCH_ETHOS_U_CONTENT
59+
"Fetch ethos_u dependencies instead of relying on pre-downloads" ON
60+
)
61+
3362
if(NOT DEFINED ET_MODEL_PTE_ADDR
3463
AND NOT DEFINED ET_PTE_FILE_PATH
3564
AND NOT DEFINED SEMIHOSTING
@@ -322,37 +351,29 @@ if(NOT ${ET_MODEL_PTE_ADDR} AND NOT SEMIHOSTING)
322351
add_dependencies(arm_executor_runner gen_model_header)
323352
endif()
324353

325-
if(SEMIHOSTING)
326-
target_compile_definitions(arm_executor_runner PUBLIC SEMIHOSTING)
327-
endif()
328-
329-
if(ET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE)
354+
if(ET_MODEL_PTE_ADDR)
330355
target_compile_definitions(
331-
arm_executor_runner
332-
PUBLIC
333-
ET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE=${ET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE}
356+
arm_executor_runner PUBLIC -DET_MODEL_PTE_ADDR=${ET_MODEL_PTE_ADDR}
334357
)
335358
endif()
336359

337-
target_compile_definitions(
338-
arm_executor_runner
339-
PUBLIC
340-
ET_ARM_BAREMETAL_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE=${ET_ARM_BAREMETAL_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE}
341-
)
342-
if(DEFINED ET_ARM_BAREMETAL_FAST_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE)
360+
if(ET_NUM_INFERENCES)
343361
target_compile_definitions(
344-
arm_executor_runner
345-
PUBLIC
346-
ET_ARM_BAREMETAL_FAST_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE=${ET_ARM_BAREMETAL_FAST_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE}
362+
arm_executor_runner PUBLIC ET_NUM_INFERENCES=${ET_NUM_INFERENCES}
347363
)
348364
endif()
349365

350-
if(ET_MODEL_PTE_ADDR)
351-
target_compile_definitions(
352-
arm_executor_runner PUBLIC -DET_MODEL_PTE_ADDR=${ET_MODEL_PTE_ADDR}
353-
)
366+
if(ET_LOG_DUMP_INPUT)
367+
target_compile_definitions(arm_executor_runner PUBLIC -DET_LOG_DUMP_INPUT)
368+
endif()
369+
370+
if(ET_LOG_DUMP_OUTPUT)
371+
target_compile_definitions(arm_executor_runner PUBLIC -DET_LOG_DUMP_OUTPUT)
354372
endif()
355373

374+
# Devtool BundleIO: Use Bundle PTE with input and reference output included to
375+
# check if it matches.
376+
356377
if(ET_BUNDLE_IO)
357378
target_compile_definitions(arm_executor_runner PUBLIC -DET_BUNDLE_IO)
358379
endif()
@@ -365,17 +386,50 @@ if(ET_RTOL)
365386
target_compile_definitions(arm_executor_runner PUBLIC ET_RTOL=${ET_RTOL})
366387
endif()
367388

368-
if(ET_DUMP_INPUT)
369-
target_compile_definitions(arm_executor_runner PUBLIC -DET_DUMP_INPUT)
389+
# Devtools ETDump: Speed and dumping output
390+
391+
if(ET_DUMP_OUTPUTS)
392+
target_compile_definitions(arm_executor_runner PUBLIC -DET_DUMP_OUTPUTS)
370393
endif()
371394

372-
if(ET_DUMP_OUTPUT)
373-
target_compile_definitions(arm_executor_runner PUBLIC -DET_DUMP_OUTPUT)
395+
if(ET_DUMP_INTERMEDIATE_OUTPUTS)
396+
target_compile_definitions(
397+
arm_executor_runner PUBLIC -DET_DUMP_INTERMEDIATE_OUTPUTS
398+
)
374399
endif()
375400

376-
if(ET_NUM_INFERENCES)
401+
if(ET_DEBUG_BUFFER_SIZE)
377402
target_compile_definitions(
378-
arm_executor_runner PUBLIC ET_NUM_INFERENCES=${ET_NUM_INFERENCES}
403+
arm_executor_runner PUBLIC ET_DEBUG_BUFFER_SIZE=${ET_DEBUG_BUFFER_SIZE}
404+
)
405+
endif()
406+
407+
# Semihosting FVP (FVP Simulator can access host filesystem)
408+
409+
if(SEMIHOSTING)
410+
target_compile_definitions(arm_executor_runner PUBLIC SEMIHOSTING)
411+
endif()
412+
413+
# Memory buffer sizes for Executorch flow
414+
415+
if(ET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE)
416+
target_compile_definitions(
417+
arm_executor_runner
418+
PUBLIC
419+
ET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE=${ET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE}
420+
)
421+
endif()
422+
423+
target_compile_definitions(
424+
arm_executor_runner
425+
PUBLIC
426+
ET_ARM_BAREMETAL_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE=${ET_ARM_BAREMETAL_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE}
427+
)
428+
if(DEFINED ET_ARM_BAREMETAL_FAST_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE)
429+
target_compile_definitions(
430+
arm_executor_runner
431+
PUBLIC
432+
ET_ARM_BAREMETAL_FAST_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE=${ET_ARM_BAREMETAL_FAST_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE}
379433
)
380434
endif()
381435

0 commit comments

Comments
 (0)