Skip to content

Commit 3305927

Browse files
Arm backend: Add docstrings to vgf/backend.py and ethosu/backend.py (#15887)
cc @freddan80 @per @zingo @oscarandersson8218 @digantdesai Signed-off-by: Sebastian Larsson <[email protected]> Co-authored-by: Zingo Andersen <[email protected]>
1 parent a78f023 commit 3305927

File tree

2 files changed

+71
-13
lines changed

2 files changed

+71
-13
lines changed

backends/arm/ethosu/backend.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# backends. Converts via TOSA as an intermediate form supported by AoT and
1010
# JIT compiler flows.
1111
#
12+
"""Ahead-of-time Arm Ethos-U backend built on the shared TOSA pipeline."""
1213

1314
import logging
1415
from typing import final, List
@@ -27,19 +28,28 @@
2728

2829
@final
2930
class EthosUBackend(BackendDetails):
30-
"""
31-
BackendDetails subclass for delegation to Ethos-U. Deduce the TOSA lowering from
32-
the compile spec list by filtering out the compile spec values that are of interest
33-
for the TOSABackend.
31+
"""BackendDetails subclass for delegation to Ethos-U.
32+
33+
Deduce the TOSA lowering from the compile spec list by filtering out the
34+
compile spec values that are of interest for the TOSABackend.
35+
3436
"""
3537

3638
@staticmethod
3739
def _compile_tosa_flatbuffer(
3840
tosa_flatbuffer: bytes, compile_spec: EthosUCompileSpec
3941
) -> bytes:
40-
"""
41-
Static helper method to do the compilation of the TOSA flatbuffer
42-
representation to a target specific binary stream.
42+
"""Compile a TOSA flatbuffer into a target-specific binary stream.
43+
44+
Args:
45+
tosa_flatbuffer (bytes): Serialized TOSA graph produced by
46+
``TOSABackend``.
47+
compile_spec (EthosUCompileSpec): Compile specification providing
48+
Vela flags and intermediate paths.
49+
50+
Returns:
51+
bytes: Target-specific binary stream produced by Vela.
52+
4353
"""
4454
compile_flags = compile_spec.compiler_flags
4555

@@ -73,6 +83,17 @@ def preprocess(
7383
edge_program: ExportedProgram,
7484
compile_specs: List[CompileSpec],
7585
) -> PreprocessResult:
86+
"""Lower the exported program and compile it for an Ethos-U target.
87+
88+
Args:
89+
edge_program (ExportedProgram): Program to lower to Ethos-U.
90+
compile_specs (List[CompileSpec]): Serialized Ethos-U compile specs
91+
supplied by the frontend.
92+
93+
Returns:
94+
PreprocessResult: Result containing the compiled Ethos-U binary.
95+
96+
"""
7697
logger.info(f"{EthosUBackend.__name__} preprocess")
7798

7899
compile_spec = EthosUCompileSpec.from_list(compile_specs)

backends/arm/vgf/backend.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# this form is used where the final JIT compile is performed on target (in the
1111
# runtime delegate executorch::runtime::BackendInterface::init
1212
#
13+
"""Ahead-of-time Arm VGF backend built on the shared TOSA pipeline."""
1314

1415
import logging
1516
import os
@@ -43,9 +44,11 @@
4344

4445
@final
4546
class VgfBackend(BackendDetails):
46-
"""
47-
BackendDetails subclass for delegation to VGF compatible devices. This enables
48-
encapsulated TOSA on target device and JIT compilation on suitable platforms.
47+
"""BackendDetails subclass for delegation to VGF compatible devices.
48+
49+
This enables encapsulated TOSA on target device and JIT compilation on
50+
suitable platforms.
51+
4952
"""
5053

5154
@staticmethod
@@ -54,9 +57,18 @@ def _compile_tosa_flatbuffer(
5457
compile_spec: VgfCompileSpec,
5558
tag_name: str = "",
5659
) -> bytes:
57-
"""
58-
Static helper method to do the compilation of the TOSA flatbuffer
59-
representation to a target specific binary stream.
60+
"""Compile a TOSA flatbuffer into a target-specific binary stream.
61+
62+
Args:
63+
tosa_flatbuffer (bytes): Serialized TOSA graph produced by
64+
``TOSABackend``.
65+
compile_spec (VgfCompileSpec): Compile specification providing
66+
converter flags and artifact paths.
67+
tag_name (str): Optional suffix used when producing debug outputs.
68+
69+
Returns:
70+
bytes: Target-specific VGF binary stream.
71+
6072
"""
6173
compile_flags = compile_spec.compiler_flags
6274
artifact_path = compile_spec.get_intermediate_path()
@@ -69,6 +81,17 @@ def preprocess(
6981
edge_program: ExportedProgram,
7082
compile_specs: List[CompileSpec],
7183
) -> PreprocessResult:
84+
"""Lower the exported program and compile it for a VGF target.
85+
86+
Args:
87+
edge_program (ExportedProgram): Program to lower to VGF.
88+
compile_specs (List[CompileSpec]): Serialized VGF compile specs
89+
supplied by the frontend.
90+
91+
Returns:
92+
PreprocessResult: Result containing the compiled VGF binary.
93+
94+
"""
7295
logger.info(f"{VgfBackend.__name__} preprocess")
7396

7497
compile_spec = VgfCompileSpec.from_list(compile_specs)
@@ -98,6 +121,20 @@ def vgf_compile(
98121
artifact_path: str | None = None,
99122
tag_name: str = "",
100123
):
124+
"""Invoke the VGF compiler to convert a TOSA flatbuffer.
125+
126+
Args:
127+
tosa_flatbuffer (bytes): Serialized TOSA graph produced by
128+
``TOSABackend``.
129+
compile_flags (List[str]): Command-line flags forwarded to
130+
``model-converter``.
131+
artifact_path (str | None): Directory where debug artifacts are saved.
132+
tag_name (str): Optional suffix used when producing debug outputs.
133+
134+
Returns:
135+
bytes: Compiled VGF binary emitted by ``model-converter``.
136+
137+
"""
101138
with tempfile.TemporaryDirectory() as tmpdir:
102139

103140
# We currently write out a flatbuffer as input to the converter

0 commit comments

Comments
 (0)