Skip to content

Commit 7a48c2c

Browse files
Arm backend: Make compile_spec serialization helpers private
Rename `from_list()` and `to_list()` to `_from_list()` and `_to_list()` so they remain internal backend plumbing instead of public API. Change-Id: I87047e3b3c90b7836bf8bc9d0d8fbcf092c6f1c0 Signed-off-by: Sebastian Larsson <sebastian.larsson@arm.com>
1 parent 834607b commit 7a48c2c

File tree

11 files changed

+26
-26
lines changed

11 files changed

+26
-26
lines changed

backends/arm/common/arm_compile_spec.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _set_compile_specs(
5858
self._pipeline_config = pipeline_config
5959

6060
@classmethod
61-
def from_list(cls, compile_specs: list[CompileSpec]): # noqa: C901
61+
def _from_list(cls, compile_specs: list[CompileSpec]): # noqa: C901
6262
tosa_spec: TosaSpecification | None = None
6363
output_format: str | None = None
6464
compiler_flags: list[str] | None = None
@@ -147,10 +147,10 @@ def _from_list_hook(cls, compile_spec, specs: dict[str, str]): # noqa: B027
147147
def _validate(self):
148148
"""Throws an error if the compile spec is not valid."""
149149

150-
def to_list(self):
150+
def _to_list(self):
151151
"""Get the ArmCompileSpec in list form."""
152152
if not self.tosa_spec:
153-
raise ValueError("tosa_spec must be set before calling to_list()")
153+
raise ValueError("tosa_spec must be set before calling _to_list()")
154154

155155
# Always supply a TOSA version
156156
compile_spec = [

backends/arm/ethosu/backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def preprocess(
9696
"""
9797
logger.info(f"{EthosUBackend.__name__} preprocess")
9898

99-
compile_spec = EthosUCompileSpec.from_list(compile_specs)
99+
compile_spec = EthosUCompileSpec._from_list(compile_specs)
100100
# deduce TOSA compile_spec from Ethos-U compile spec. We get a new
101101
# compile spec list, containing only elements relevant for the
102102
# TOSABackend.

backends/arm/ethosu/compile_spec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ def __init__(
121121
self._set_compile_specs(tosa_spec, compiler_flags)
122122
self._validate()
123123

124-
def to_list(self):
124+
def _to_list(self):
125125
"""Return compile specs including the encoded Ethos-U target."""
126-
compile_specs = super().to_list()
126+
compile_specs = super()._to_list()
127127
compile_specs.append(CompileSpec(self._TARGET_KEY, self.target.encode()))
128128
return compile_specs
129129

backends/arm/ethosu/partitioner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(
2929
) -> None:
3030
# Override the delegation spec for Ethos-U
3131
self.delegation_spec = DelegationSpec(
32-
EthosUBackend.__name__, compile_spec.to_list()
32+
EthosUBackend.__name__, compile_spec._to_list()
3333
)
3434
self.additional_checks = additional_checks
3535
self.tosa_spec = compile_spec.tosa_spec

backends/arm/test/misc/test_compile_spec.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ def test_compile_spec_u55_INT():
1616
.dump_intermediate_artifacts_to("my_path")
1717
.dump_debug_info(EthosUCompileSpec.DebugMode.TOSA)
1818
)
19-
spec_list = compile_spec.to_list()
19+
spec_list = compile_spec._to_list()
2020

21-
assert EthosUCompileSpec.from_list(spec_list) == compile_spec
21+
assert EthosUCompileSpec._from_list(spec_list) == compile_spec
2222
assert "--my-flag" in compile_spec.compiler_flags
2323
assert "--output-format=raw" in compile_spec.compiler_flags
2424
with raises(ValueError, match="Incorrect output format"):
25-
VgfCompileSpec.from_list(spec_list)
25+
VgfCompileSpec._from_list(spec_list)
2626

2727
spec_list.pop(0)
2828
with raises(ValueError, match="No tosa_spec in compile spec."):
29-
EthosUCompileSpec.from_list(spec_list)
29+
EthosUCompileSpec._from_list(spec_list)
3030

3131

3232
def test_ethos_u55_defaults_to_stable_softmax_u55_INT():
@@ -53,18 +53,18 @@ def test_compile_spec_vgf_no_quant():
5353
compiler_flags=["--my-flag2"]
5454
).dump_intermediate_artifacts_to("my_path")
5555

56-
spec_list = compile_spec.to_list()
56+
spec_list = compile_spec._to_list()
5757

58-
assert VgfCompileSpec.from_list(spec_list) == compile_spec
59-
assert VgfCompileSpec.from_list(spec_list) != compile_spec2
58+
assert VgfCompileSpec._from_list(spec_list) == compile_spec
59+
assert VgfCompileSpec._from_list(spec_list) != compile_spec2
6060
with raises(ValueError, match="Incorrect output format"):
61-
EthosUCompileSpec.from_list(spec_list)
61+
EthosUCompileSpec._from_list(spec_list)
6262

6363

6464
def test_compile_spec_tosa_INT():
6565
compile_spec = TosaCompileSpec("TOSA-1.0+INT")
66-
spec_list = compile_spec.to_list()
66+
spec_list = compile_spec._to_list()
6767

68-
assert TosaCompileSpec.from_list(spec_list) == compile_spec
68+
assert TosaCompileSpec._from_list(spec_list) == compile_spec
6969
with raises(ValueError, match="Incorrect output format"):
70-
VgfCompileSpec.from_list(spec_list)
70+
VgfCompileSpec._from_list(spec_list)

backends/arm/test/runner_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def __init__(self):
221221

222222
def _tosa_dispatch(self, lowered_backend_module: LoweredBackendModule, inputs):
223223
tosa_buffer = lowered_backend_module.processed_bytes
224-
compile_spec = TosaCompileSpec.from_list(lowered_backend_module.compile_specs)
224+
compile_spec = TosaCompileSpec._from_list(lowered_backend_module.compile_specs)
225225

226226
output_node = lowered_backend_module.original_module.graph.output_node()
227227
return run_tosa_graph(tosa_buffer, compile_spec.tosa_spec, inputs, output_node)

backends/arm/tosa/backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def preprocess(edge_program: ExportedProgram, compile_specs: List[CompileSpec]):
170170
171171
"""
172172
return TOSABackend._preprocess(
173-
edge_program, TosaCompileSpec.from_list(compile_specs)
173+
edge_program, TosaCompileSpec._from_list(compile_specs)
174174
)
175175

176176
@staticmethod

backends/arm/tosa/partitioner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def __init__(
145145
146146
"""
147147
self.delegation_spec = DelegationSpec(
148-
TOSABackend.__name__, compile_spec.to_list()
148+
TOSABackend.__name__, compile_spec._to_list()
149149
)
150150
self.tosa_spec = compile_spec.tosa_spec
151151
self.additional_checks = additional_checks

backends/arm/util/_factory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ def parse_compile_spec(compile_specs: list[CompileSpec]) -> ArmCompileSpec:
2626
else:
2727
raise ValueError("Compile spec without output format.")
2828
if output_format == TosaCompileSpec._get_output_format():
29-
return TosaCompileSpec.from_list(compile_specs)
29+
return TosaCompileSpec._from_list(compile_specs)
3030
if output_format == EthosUCompileSpec._get_output_format():
31-
return EthosUCompileSpec.from_list(compile_specs)
31+
return EthosUCompileSpec._from_list(compile_specs)
3232
if output_format == VgfCompileSpec._get_output_format():
33-
return VgfCompileSpec.from_list(compile_specs)
33+
return VgfCompileSpec._from_list(compile_specs)
3434
raise ValueError(f"Unknown output format {output_format}")
3535

3636

backends/arm/vgf/backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def preprocess(
9595
"""
9696
logger.info(f"{VgfBackend.__name__} preprocess")
9797

98-
compile_spec = VgfCompileSpec.from_list(compile_specs)
98+
compile_spec = VgfCompileSpec._from_list(compile_specs)
9999
# deduce TOSA compile_spec from VGF compile spec. We get a new
100100
# compile spec list, containing only elements relevant for the
101101
# TOSABackend.

0 commit comments

Comments
 (0)