Skip to content

Commit 7c6d2f3

Browse files
authored
[ExecuTorch] Arm Ethos:Make get_compile_spec() configurable (#9403)
Allow users to generate different compile specs based on the Args. Preserve the behavior. Differential Revision: [D70351486](https://our.internmc.facebook.com/intern/diff/D70351486/) ghstack-source-id: 269599016 Pull Request resolved: #9323
1 parent 0daa347 commit 7c6d2f3

File tree

1 file changed

+47
-14
lines changed

1 file changed

+47
-14
lines changed

backends/arm/test/common.py

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from datetime import datetime
1111

1212
from pathlib import Path
13-
from typing import Any
13+
from typing import Any, Optional
1414

1515
import pytest
1616
from executorch.backends.arm.arm_backend import ArmCompileSpecBuilder
@@ -91,63 +91,96 @@ def get_tosa_compile_spec_unbuilt(
9191

9292

9393
def get_u55_compile_spec(
94-
custom_path=None,
94+
macs: int = 128,
95+
system_config: str = "Ethos_U55_High_End_Embedded",
96+
memory_mode: str = "Shared_Sram",
97+
extra_flags: str = "--debug-force-regor --output-format=raw",
98+
custom_path: Optional[str] = None,
9599
) -> list[CompileSpec]:
96100
"""
97-
Default compile spec for Ethos-U55 tests.
101+
Compile spec for Ethos-U55.
98102
"""
99103
return get_u55_compile_spec_unbuilt(
104+
macs=macs,
105+
system_config=system_config,
106+
memory_mode=memory_mode,
107+
extra_flags=extra_flags,
100108
custom_path=custom_path,
101109
).build()
102110

103111

104112
def get_u85_compile_spec(
113+
macs: int = 128,
114+
system_config="Ethos_U85_SYS_DRAM_Mid",
115+
memory_mode="Shared_Sram",
116+
extra_flags="--output-format=raw",
105117
custom_path=None,
106118
) -> list[CompileSpec]:
107119
"""
108-
Default compile spec for Ethos-U85 tests.
120+
Compile spec for Ethos-U85.
109121
"""
110122
return get_u85_compile_spec_unbuilt( # type: ignore[attr-defined]
123+
macs=macs,
124+
system_config=system_config,
125+
memory_mode=memory_mode,
126+
extra_flags=extra_flags,
111127
custom_path=custom_path,
112128
).build()
113129

114130

115131
def get_u55_compile_spec_unbuilt(
116-
custom_path=None,
132+
macs: int,
133+
system_config: str,
134+
memory_mode: str,
135+
extra_flags: str,
136+
custom_path: Optional[str],
117137
) -> ArmCompileSpecBuilder:
118138
"""Get the ArmCompileSpecBuilder for the Ethos-U55 tests, to modify
119139
the compile spec before calling .build() to finalize it.
120140
"""
121141
artifact_path = custom_path or tempfile.mkdtemp(prefix="arm_u55_")
122142
if not os.path.exists(artifact_path):
123143
os.makedirs(artifact_path, exist_ok=True)
144+
145+
# https://gitlab.arm.com/artificial-intelligence/ethos-u/ethos-u-vela/-/blob/main/OPTIONS.md
146+
assert macs in [32, 64, 128, 256], "Unsupported MACs value"
147+
124148
compile_spec = (
125149
ArmCompileSpecBuilder()
126150
.ethosu_compile_spec(
127-
"ethos-u55-128",
128-
system_config="Ethos_U55_High_End_Embedded",
129-
memory_mode="Shared_Sram",
130-
extra_flags="--debug-force-regor --output-format=raw",
151+
f"ethos-u55-{macs}",
152+
system_config=system_config,
153+
memory_mode=memory_mode,
154+
extra_flags=extra_flags,
131155
)
132156
.dump_intermediate_artifacts_to(artifact_path)
133157
)
134158
return compile_spec
135159

136160

137161
def get_u85_compile_spec_unbuilt(
138-
custom_path=None,
162+
macs: int,
163+
system_config: str,
164+
memory_mode: str,
165+
extra_flags: str,
166+
custom_path: Optional[str],
139167
) -> list[CompileSpec]:
140168
"""Get the ArmCompileSpecBuilder for the Ethos-U85 tests, to modify
141169
the compile spec before calling .build() to finalize it.
142170
"""
143171
artifact_path = custom_path or tempfile.mkdtemp(prefix="arm_u85_")
172+
if not os.path.exists(artifact_path):
173+
os.makedirs(artifact_path, exist_ok=True)
174+
175+
assert macs in [128, 256, 512, 1024, 2048], "Unsupported MACs value"
176+
144177
compile_spec = (
145178
ArmCompileSpecBuilder()
146179
.ethosu_compile_spec(
147-
"ethos-u85-128",
148-
system_config="Ethos_U85_SYS_DRAM_Mid",
149-
memory_mode="Shared_Sram",
150-
extra_flags="--output-format=raw",
180+
f"ethos-u85-{macs}",
181+
system_config=system_config,
182+
memory_mode=memory_mode,
183+
extra_flags=extra_flags,
151184
)
152185
.dump_intermediate_artifacts_to(artifact_path)
153186
)

0 commit comments

Comments
 (0)