Skip to content

Commit 17e4392

Browse files
Arm backend: Add docstrings to compile specs (#15886)
cc @freddan80 @per @zingo @oscarandersson8218 @digantdesai Signed-off-by: Sebastian Larsson <sebastian.larsson@arm.com>
1 parent 6e4e8fa commit 17e4392

File tree

3 files changed

+44
-19
lines changed

3 files changed

+44
-19
lines changed

backends/arm/ethosu/compile_spec.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,7 @@
1515

1616

1717
class EthosUCompileSpec(ArmCompileSpec):
18-
"""
19-
Compile spec for Ethos-U NPU.
20-
21-
Args:
22-
target: Ethos-U accelerator configuration, e.g. ethos-u55-128.
23-
system_config: System configuration to select from the Vela configuration file.
24-
memory_mode: Memory mode to select from the Vela configuration file.
25-
extra_flags: Extra flags for the Vela compiler.
26-
config_ini: Vela configuration file(s) in Python ConfigParser .ini file format.
27-
"""
18+
"""Compile specification for Ethos-U NPU targets."""
2819

2920
_TARGET_KEY = "target"
3021

@@ -36,6 +27,21 @@ def __init__(
3627
extra_flags: list[str] | None = None,
3728
config_ini: str | None = "Arm/vela.ini",
3829
):
30+
"""Normalise Ethos-U compile configuration and compiler flags.
31+
32+
Args:
33+
target (str): Ethos-U accelerator configuration (for example,
34+
``"ethos-u55-128"``).
35+
system_config (str | None): System configuration name from the Vela
36+
config file. Defaults based on ``target`` when omitted.
37+
memory_mode (str | None): Memory mode selection from the Vela config
38+
file. Defaults based on ``target`` when omitted.
39+
extra_flags (list[str] | None): Additional command-line flags for
40+
Vela.
41+
config_ini (str | None): Path to a Vela .ini configuration file.
42+
Defaults to ``"Arm/vela.ini"``.
43+
44+
"""
3945
self.target = target
4046

4147
# Set vela compiler flags
@@ -78,16 +84,18 @@ def __init__(
7884
self.validate()
7985

8086
def to_list(self):
87+
"""Return compile specs including the encoded Ethos-U target."""
8188
compile_specs = super().to_list()
8289
compile_specs.append(CompileSpec(self._TARGET_KEY, self.target.encode()))
8390
return compile_specs
8491

8592
@classmethod
8693
def from_list_hook(cls, compile_spec, specs: dict[str, str]):
94+
"""Restore target-specific metadata from serialized compile specs."""
8795
compile_spec.target = specs.get(cls._TARGET_KEY, None)
8896

8997
def validate(self):
90-
"""Throws an error if the compile spec is not valid."""
98+
"""Validate the configuration against supported Ethos-U settings."""
9199
if len(self.compiler_flags) == 0:
92100
raise ValueError(
93101
"compile_flags are required in the CompileSpec list for EthosUBackend"
@@ -99,4 +107,5 @@ def validate(self):
99107

100108
@classmethod
101109
def get_output_format(cls) -> str:
110+
"""Return the artifact format emitted by this compile spec."""
102111
return "vela"

backends/arm/tosa/compile_spec.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,22 @@
88

99

1010
class TosaCompileSpec(ArmCompileSpec):
11+
"""Arm-specific compile spec capturing TOSA serializer requirements."""
12+
1113
def __init__(self, tosa_spec: TosaSpecification | str):
14+
"""Normalize and store the provided TOSA specification.
15+
16+
Args:
17+
tosa_spec (TosaSpecification | str): Target spec object or version
18+
string supported by :meth:`TosaSpecification.create_from_string`.
19+
20+
"""
1221
if isinstance(tosa_spec, str):
1322
tosa_spec = TosaSpecification.create_from_string(tosa_spec)
1423
self._set_compile_specs(tosa_spec, [])
1524

1625
def validate(self):
26+
"""Ensure that no unsupported compiler flags were supplied."""
1727
if len(self.compiler_flags) != 0:
1828
raise ValueError(
1929
f"TosaCompileSpec can't have compiler flags, got {self.compiler_flags}"
@@ -22,4 +32,5 @@ def validate(self):
2232

2333
@classmethod
2434
def get_output_format(cls) -> str:
35+
"""Return the artifact format emitted by this compile spec."""
2536
return "tosa"

backends/arm/vgf/compile_spec.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,23 @@
1515

1616

1717
class VgfCompileSpec(ArmCompileSpec):
18-
"""
19-
Compile spec for VGF compatible targets.
20-
21-
Args:
22-
tosa_spec: TOSA specification that should be targeted.
23-
compiler_flags: Extra compiler flags for converter_backend.
24-
"""
18+
"""Compile specification for VGF-compatible targets."""
2519

2620
def __init__(
2721
self,
2822
tosa_spec: TosaSpecification | str | None = None,
2923
compiler_flags: list[str] | None = None,
3024
):
25+
"""Normalise inputs and populate the underlying Arm compile spec.
26+
27+
Args:
28+
tosa_spec (TosaSpecification | str | None): TOSA specification to
29+
target. Strings are parsed via
30+
:meth:`TosaSpecification.create_from_string`. Defaults to
31+
``"TOSA-1.0+FP"``.
32+
compiler_flags (list[str] | None): Optional converter-backend flags.
33+
34+
"""
3135
if tosa_spec is None:
3236
tosa_spec = "TOSA-1.0+FP"
3337
if isinstance(tosa_spec, str):
@@ -39,7 +43,7 @@ def __init__(
3943
self.validate()
4044

4145
def validate(self):
42-
"""Throws an error if the compile spec is not valid."""
46+
"""Validate the configuration against VGF-supported TOSA profiles."""
4347
tosa_version = self.tosa_spec.version # type: ignore[attr-defined]
4448
tosa_profiles = self.tosa_spec.profiles # type: ignore[attr-defined]
4549

@@ -63,4 +67,5 @@ def validate(self):
6367

6468
@classmethod
6569
def get_output_format(cls) -> str:
70+
"""Return the artifact format emitted by this compile spec."""
6671
return "vgf"

0 commit comments

Comments
 (0)