Skip to content

Commit 359631d

Browse files
committed
Move some required and default compile_spec properties into the builder
Signed-off-by: Rob Elliott <[email protected]> Change-Id: Id96933b727015502cced3c4dcc48535895c55cf7
1 parent 9efb909 commit 359631d

File tree

2 files changed

+28
-31
lines changed

2 files changed

+28
-31
lines changed

backends/arm/arm_backend.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ def __init__(self):
2929

3030
def ethosu_compile_spec(
3131
self,
32-
config: str,
33-
system_config: str,
34-
memory_mode: str,
32+
target: str,
33+
system_config: Optional[str] = None,
34+
memory_mode: Optional[str] = None,
3535
extra_flags: Optional[str] = None,
3636
config_ini: Optional[str] = "Arm/vela.ini",
3737
) -> "ArmCompileSpecBuilder":
3838
"""
3939
Generate compile spec for Ethos-U NPU
4040
4141
Args:
42-
config: Ethos-U accelerator configuration, e.g. ethos-u55-128
42+
target: Ethos-U accelerator configuration, e.g. ethos-u55-128
4343
system_config: System configuration to select from the Vel
4444
configuration file
4545
memory_mode: Memory mode to select from the Vela configuration file
@@ -52,18 +52,38 @@ def ethosu_compile_spec(
5252
), f"Output format already set to f{self.output_format}"
5353
self.output_format = "vela"
5454
self.compiler_flags = [
55-
f"--accelerator-config={config}",
55+
f"--accelerator-config={target}",
5656
f"--config={config_ini}",
5757
]
58+
59+
# default system config and memory mode
60+
if "ethos-u55" in target:
61+
if system_config is None:
62+
system_config = "Ethos_U55_High_End_Embedded"
63+
if memory_mode is None:
64+
memory_mode = "Shared_Sram"
65+
elif "ethos-u85" in target:
66+
if system_config is None:
67+
system_config = "Ethos_U85_SYS_DRAM_Mid"
68+
if memory_mode is None:
69+
memory_mode = "Sram_Only"
70+
else:
71+
raise RuntimeError(f"Unknown ethos target: {target}")
72+
5873
if system_config is not None:
5974
self.compiler_flags.append(f"--system-config={system_config}")
6075
if memory_mode is not None:
6176
self.compiler_flags.append(f"--memory-mode={memory_mode}")
6277
if extra_flags is not None:
6378
self.compiler_flags.append(extra_flags)
6479

80+
# We require raw output and regor, so add these flags if absent. This
81+
# overrides any other output setting.
82+
self.compiler_flags.append("--output-format=raw")
83+
self.compiler_flags.append("--debug-force-regor")
84+
6585
base_tosa_version = "TOSA-0.80+BI"
66-
if "u55" in config:
86+
if "u55" in target:
6787
# Add the Ethos-U55 extension marker
6888
base_tosa_version += "+u55"
6989
self.tosa_spec = TosaSpecification.create_from_string(base_tosa_version)

examples/arm/aot_arm_compiler.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -317,19 +317,12 @@ def get_compile_spec(
317317
except:
318318
tosa_spec = TosaSpecification.create_from_string("TOSA-0.80+BI")
319319
spec_builder = ArmCompileSpecBuilder().tosa_compile_spec(tosa_spec)
320-
elif "ethos-u55" in target:
320+
elif "ethos-u" in target:
321321
spec_builder = ArmCompileSpecBuilder().ethosu_compile_spec(
322322
target,
323323
system_config=system_config,
324324
memory_mode=memory_mode,
325-
extra_flags="--debug-force-regor --output-format=raw --verbose-operators --verbose-cycle-estimate",
326-
)
327-
elif "ethos-u85" in target:
328-
spec_builder = ArmCompileSpecBuilder().ethosu_compile_spec(
329-
target,
330-
system_config=system_config,
331-
memory_mode=memory_mode,
332-
extra_flags="--output-format=raw --verbose-operators --verbose-cycle-estimate",
325+
extra_flags="--verbose-operators --verbose-cycle-estimate",
333326
)
334327

335328
if intermediates is not None:
@@ -527,22 +520,6 @@ def get_args():
527520
):
528521
raise RuntimeError(f"Model {args.model_name} cannot be delegated.")
529522

530-
if "ethos-u" in args.target and args.system_config is None:
531-
if "u55" in args.target:
532-
args.system_config = "Ethos_U55_High_End_Embedded"
533-
elif "u85" in args.target:
534-
args.system_config = "Ethos_U85_SYS_DRAM_Mid"
535-
else:
536-
raise RuntimeError(f"Invalid target name {args.target}")
537-
538-
if "ethos-u" in args.target and args.memory_mode is None:
539-
if "u55" in args.target:
540-
args.memory_mode = "Shared_Sram"
541-
elif "u85" in args.target:
542-
args.memory_mode = "Sram_Only"
543-
else:
544-
raise RuntimeError(f"Invalid target name {args.target}")
545-
546523
return args
547524

548525

0 commit comments

Comments
 (0)