Skip to content

Commit 7409fd4

Browse files
authored
Arm backend: Set REGIONCFG registers of the Ethos-U (#10388)
The REGIONCFG registers need to be set differently depending on the memory mode for optimal performance. Minor fix to how we create the base64 encoded binary file when using etdump. The new command is more portable and works on Ubuntu & Mac
1 parent 334af4a commit 7409fd4

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

examples/arm/executor_runner/CMakeLists.txt

+48
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ elseif(SYSTEM_CONFIG STREQUAL "Ethos_U55_Deep_Embedded")
221221
)
222222
elseif(MEMORY_MODE STREQUAL "Sram_Only")
223223
target_compile_definitions(ethosu_target_common INTERFACE
224+
ETHOSU_MODEL=1
224225
# Configure NPU architecture timing adapters
225226
# This is just example numbers and you should make this match your hardware
226227
# SRAM
@@ -411,6 +412,53 @@ else()
411412
message(FATAL_ERROR "Unsupported SYSTEM_CONFIG: ${SYSTEM_CONFIG}")
412413
endif()
413414

415+
# The REGIONCFG registers of the Ethos-U control whether the NPU
416+
# reads/writes data through the SRAM or the external memory.
417+
# By default, the Ethos-U driver provides REGIONCFG configuration for Shared Sram memory mode.
418+
# For Sram_Only and Dedicated_Sram memory modes, we need to change the settings for optimal performance.
419+
#
420+
# Currently, the convention used by Vela and the Ethos-U driver is that the NPU uses:
421+
# Region 0 for traffic of the Read-Only data(weights & biases)
422+
# Region 1 for traffic of of the intermediate Read/Write buffers required for the computation
423+
# Region 2 for traffic of of the cache in Dedicated_Sram memory mode(not applicable in Sram_Only or Shared_Sram)
424+
#
425+
# NOTE: The above convention is determined by the Vela compiler and the Ethos-U driver and can change in the future.
426+
#
427+
# Common definitions:
428+
# For Ethos-U55/U65/U85, region configs are set as:
429+
# 0 or 1 = AXI0 (Ethos-U55 or Ethos-U65) or AXI_SRAM(Ethos-U85)
430+
# 2 or 3 = AXI1 (Ethos-U55 or Ethos-U65) or AXI_EXT(Ethos-U85)
431+
#
432+
# When we compile a model for Sram_Only, the memory traffic for Region 0 and Region 1 should pass via the SRAM(hence regioncfg = 1)
433+
# When we compile a model for Dedicated_Sram, the memory traffic for Region 0 should pass via the external memory(3),
434+
# the memory traffic of Region 1 should pass via the external memory(3) and the traffic for Region 2 should pass via the SRAM(0)
435+
#
436+
437+
if(MEMORY_MODE STREQUAL "Sram_Only")
438+
target_compile_definitions(ethosu_core_driver PRIVATE
439+
NPU_QCONFIG=1
440+
NPU_REGIONCFG_0=1
441+
NPU_REGIONCFG_1=0
442+
NPU_REGIONCFG_2=0
443+
NPU_REGIONCFG_3=0
444+
NPU_REGIONCFG_4=0
445+
NPU_REGIONCFG_5=0
446+
NPU_REGIONCFG_6=0
447+
NPU_REGIONCFG_7=0)
448+
elseif(MEMORY_MODE STREQUAL "Dedicated_Sram")
449+
target_compile_definitions(ethosu_core_driver PRIVATE
450+
NPU_QCONFIG=3
451+
NPU_REGIONCFG_0=3
452+
NPU_REGIONCFG_1=3
453+
NPU_REGIONCFG_2=0
454+
NPU_REGIONCFG_3=0
455+
NPU_REGIONCFG_4=0
456+
NPU_REGIONCFG_5=0
457+
NPU_REGIONCFG_6=0
458+
NPU_REGIONCFG_7=0)
459+
endif()
460+
461+
414462
# Dependencies from the ExecuTorch build
415463
add_library(executorch STATIC IMPORTED)
416464
set_property(

examples/arm/executor_runner/arm_executor_runner.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ int main(int argc, const char* argv[]) {
766766
encoded_buf[encoded_len] = 0x00; // Ensure null termination
767767
ET_LOG(Info, "Writing etdump.bin [base64]");
768768
printf(
769-
"#---\nbase64 -i -d <<<\"\\\n%s\\\n\" >etdump.bin\npython3 -m devtools.inspector.inspector_cli --etdump_path etdump.bin --source_time_scale cycles --target_time_scale cycles\n#---\n",
769+
"#---\necho \"%s\" | base64 -d >etdump.bin\npython3 -m devtools.inspector.inspector_cli --etdump_path etdump.bin --source_time_scale cycles --target_time_scale cycles\n#---\n",
770770
encoded_buf);
771771
} else {
772772
ET_LOG(

0 commit comments

Comments
 (0)