Skip to content

Commit 12ce0ce

Browse files
Erik-Lundellfreddan80
authored andcommitted
Figure out target-board from compile spec
Reduces boilerplate in FVP tests Signed-off-by: Erik Lundell <[email protected]> Change-Id: I7b4cdec6ba3da91e9f510830d6d817acaf18c53e
1 parent 3f1b085 commit 12ce0ce

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

backends/arm/test/common.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,14 @@ def _clean_dir(dir: Path, filter: str, num_save=10):
330330
for remove in sorted_files[0 : len(sorted_files) - num_save]:
331331
file = remove[1]
332332
file.unlink()
333+
334+
335+
def get_target_board(compile_spec: list[CompileSpec]) -> str | None:
336+
for spec in compile_spec:
337+
if spec.key == "compile_flags":
338+
flags = spec.value.decode()
339+
if "u55" in flags:
340+
return "corstone-300"
341+
elif "u85" in flags:
342+
return "corstone-320"
343+
return None

backends/arm/test/ops/test_add.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ def _test_add_ethos_BI_pipeline(
115115
.to_executorch()
116116
.serialize()
117117
)
118+
if common.is_option_enabled("corstone300"):
119+
tester.run_method_and_compare_outputs(qtol=1, inputs=test_data)
118120

119121
return tester
120122

@@ -131,28 +133,20 @@ def test_add_tosa_BI(self, test_data: torch.Tensor):
131133
@parameterized.expand(Add.test_parameters)
132134
def test_add_u55_BI(self, test_data: torch.Tensor):
133135
test_data = (test_data,)
134-
tester = self._test_add_ethos_BI_pipeline(
136+
self._test_add_ethos_BI_pipeline(
135137
self.Add(),
136138
common.get_u55_compile_spec(permute_memory_to_nhwc=True),
137139
test_data,
138140
)
139-
if common.is_option_enabled("corstone300"):
140-
tester.run_method_and_compare_outputs(
141-
qtol=1, inputs=test_data, target_board="corstone-300"
142-
)
143141

144142
@parameterized.expand(Add.test_parameters)
145143
def test_add_u85_BI(self, test_data: torch.Tensor):
146144
test_data = (test_data,)
147-
tester = self._test_add_ethos_BI_pipeline(
145+
self._test_add_ethos_BI_pipeline(
148146
self.Add(),
149147
common.get_u85_compile_spec(permute_memory_to_nhwc=True),
150148
test_data,
151149
)
152-
if common.is_option_enabled("corstone300"):
153-
tester.run_method_and_compare_outputs(
154-
qtol=1, inputs=test_data, target_board="corstone-320"
155-
)
156150

157151
@parameterized.expand(Add2.test_parameters)
158152
def test_add2_tosa_MI(self, operand1: torch.Tensor, operand2: torch.Tensor):
@@ -167,21 +161,13 @@ def test_add2_tosa_BI(self, operand1: torch.Tensor, operand2: torch.Tensor):
167161
@parameterized.expand(Add2.test_parameters)
168162
def test_add2_u55_BI(self, operand1: torch.Tensor, operand2: torch.Tensor):
169163
test_data = (operand1, operand2)
170-
tester = self._test_add_ethos_BI_pipeline(
164+
self._test_add_ethos_BI_pipeline(
171165
self.Add2(), common.get_u55_compile_spec(), test_data
172166
)
173-
if common.is_option_enabled("corstone300"):
174-
tester.run_method_and_compare_outputs(
175-
qtol=1, inputs=test_data, target_board="corstone-300"
176-
)
177167

178168
@parameterized.expand(Add2.test_parameters)
179169
def test_add2_u85_BI(self, operand1: torch.Tensor, operand2: torch.Tensor):
180170
test_data = (operand1, operand2)
181-
tester = self._test_add_ethos_BI_pipeline(
171+
self._test_add_ethos_BI_pipeline(
182172
self.Add2(), common.get_u85_compile_spec(), test_data
183173
)
184-
if common.is_option_enabled("corstone300"):
185-
tester.run_method_and_compare_outputs(
186-
qtol=1, inputs=test_data, target_board="corstone-320"
187-
)

backends/arm/test/runner_utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,6 @@ def init_run(
191191
target_board: str,
192192
):
193193

194-
if target_board not in ["corstone-300", "corstone-320"]:
195-
raise RuntimeError(f"Unknown target board: {target_board}")
196-
197194
self.input_names = _get_input_names(edge_program)
198195
self.output_node = _get_output_node(exported_program)
199196
self.output_name = self.output_node.name
@@ -222,6 +219,8 @@ def run_corstone(
222219
assert (
223220
self._has_init_run
224221
), "RunnerUtil needs to be initialized using init_run() before running Corstone300."
222+
if self.target_board not in ["corstone-300", "corstone-320"]:
223+
raise RuntimeError(f"Unknown target board: {self.target_board}")
225224

226225
pte_path = os.path.join(self.intermediate_path, "program.pte")
227226
assert os.path.exists(pte_path), f"Pte path '{pte_path}' not found."

backends/arm/test/tester/arm_tester.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
arm_test_options,
2727
current_time_formated,
2828
get_option,
29+
get_target_board,
2930
)
3031

3132
from executorch.backends.arm.test.runner_utils import (
@@ -267,7 +268,7 @@ def run_method_and_compare_outputs(
267268
self,
268269
inputs: Optional[Tuple[torch.Tensor]] = None,
269270
stage: Optional[str] = None,
270-
target_board: Optional[str] = "corstone-300",
271+
target_board: Optional[str] = None,
271272
num_runs=1,
272273
atol=1e-03,
273274
rtol=1e-03,
@@ -301,6 +302,9 @@ def run_method_and_compare_outputs(
301302
test_stage = self.stages[stage]
302303
is_quantized = self.stages[self.stage_name(tester.Quantize)] is not None
303304

305+
if target_board is None:
306+
target_board = get_target_board(self.compile_spec)
307+
304308
exported_program = self.stages[self.stage_name(tester.Export)].artifact
305309
edge_program = edge_stage.artifact.exported_program()
306310
self.runner_util.init_run(

0 commit comments

Comments
 (0)