From c683f3f171d2996491753516bc15d3aa4f085b3a Mon Sep 17 00:00:00 2001 From: Sebastian Larsson Date: Thu, 6 Nov 2025 16:22:43 +0100 Subject: [PATCH] Arm backend: Add docstrings to vgf/backend.py and ethosu/backend.py Signed-off-by: Sebastian Larsson Change-Id: I242cc622e636da50d17a6b5783ed3061a5e9c329 --- backends/arm/ethosu/backend.py | 35 +++++++++++++++++++----- backends/arm/vgf/backend.py | 49 +++++++++++++++++++++++++++++----- 2 files changed, 71 insertions(+), 13 deletions(-) diff --git a/backends/arm/ethosu/backend.py b/backends/arm/ethosu/backend.py index 9a2d24a9684..bd6da08dc38 100644 --- a/backends/arm/ethosu/backend.py +++ b/backends/arm/ethosu/backend.py @@ -9,6 +9,7 @@ # backends. Converts via TOSA as an intermediate form supported by AoT and # JIT compiler flows. # +"""Ahead-of-time Arm Ethos-U backend built on the shared TOSA pipeline.""" import logging from typing import final, List @@ -27,19 +28,28 @@ @final class EthosUBackend(BackendDetails): - """ - BackendDetails subclass for delegation to Ethos-U. Deduce the TOSA lowering from - the compile spec list by filtering out the compile spec values that are of interest - for the TOSABackend. + """BackendDetails subclass for delegation to Ethos-U. + + Deduce the TOSA lowering from the compile spec list by filtering out the + compile spec values that are of interest for the TOSABackend. + """ @staticmethod def _compile_tosa_flatbuffer( tosa_flatbuffer: bytes, compile_spec: EthosUCompileSpec ) -> bytes: - """ - Static helper method to do the compilation of the TOSA flatbuffer - representation to a target specific binary stream. + """Compile a TOSA flatbuffer into a target-specific binary stream. + + Args: + tosa_flatbuffer (bytes): Serialized TOSA graph produced by + ``TOSABackend``. + compile_spec (EthosUCompileSpec): Compile specification providing + Vela flags and intermediate paths. + + Returns: + bytes: Target-specific binary stream produced by Vela. + """ compile_flags = compile_spec.compiler_flags @@ -73,6 +83,17 @@ def preprocess( edge_program: ExportedProgram, compile_specs: List[CompileSpec], ) -> PreprocessResult: + """Lower the exported program and compile it for an Ethos-U target. + + Args: + edge_program (ExportedProgram): Program to lower to Ethos-U. + compile_specs (List[CompileSpec]): Serialized Ethos-U compile specs + supplied by the frontend. + + Returns: + PreprocessResult: Result containing the compiled Ethos-U binary. + + """ logger.info(f"{EthosUBackend.__name__} preprocess") compile_spec = EthosUCompileSpec.from_list(compile_specs) diff --git a/backends/arm/vgf/backend.py b/backends/arm/vgf/backend.py index 5263ce6737d..d22dc27afa0 100644 --- a/backends/arm/vgf/backend.py +++ b/backends/arm/vgf/backend.py @@ -10,6 +10,7 @@ # this form is used where the final JIT compile is performed on target (in the # runtime delegate executorch::runtime::BackendInterface::init # +"""Ahead-of-time Arm VGF backend built on the shared TOSA pipeline.""" import logging import os @@ -43,9 +44,11 @@ @final class VgfBackend(BackendDetails): - """ - BackendDetails subclass for delegation to VGF compatible devices. This enables - encapsulated TOSA on target device and JIT compilation on suitable platforms. + """BackendDetails subclass for delegation to VGF compatible devices. + + This enables encapsulated TOSA on target device and JIT compilation on + suitable platforms. + """ @staticmethod @@ -54,9 +57,18 @@ def _compile_tosa_flatbuffer( compile_spec: VgfCompileSpec, tag_name: str = "", ) -> bytes: - """ - Static helper method to do the compilation of the TOSA flatbuffer - representation to a target specific binary stream. + """Compile a TOSA flatbuffer into a target-specific binary stream. + + Args: + tosa_flatbuffer (bytes): Serialized TOSA graph produced by + ``TOSABackend``. + compile_spec (VgfCompileSpec): Compile specification providing + converter flags and artifact paths. + tag_name (str): Optional suffix used when producing debug outputs. + + Returns: + bytes: Target-specific VGF binary stream. + """ compile_flags = compile_spec.compiler_flags artifact_path = compile_spec.get_intermediate_path() @@ -69,6 +81,17 @@ def preprocess( edge_program: ExportedProgram, compile_specs: List[CompileSpec], ) -> PreprocessResult: + """Lower the exported program and compile it for a VGF target. + + Args: + edge_program (ExportedProgram): Program to lower to VGF. + compile_specs (List[CompileSpec]): Serialized VGF compile specs + supplied by the frontend. + + Returns: + PreprocessResult: Result containing the compiled VGF binary. + + """ logger.info(f"{VgfBackend.__name__} preprocess") compile_spec = VgfCompileSpec.from_list(compile_specs) @@ -98,6 +121,20 @@ def vgf_compile( artifact_path: str | None = None, tag_name: str = "", ): + """Invoke the VGF compiler to convert a TOSA flatbuffer. + + Args: + tosa_flatbuffer (bytes): Serialized TOSA graph produced by + ``TOSABackend``. + compile_flags (List[str]): Command-line flags forwarded to + ``model-converter``. + artifact_path (str | None): Directory where debug artifacts are saved. + tag_name (str): Optional suffix used when producing debug outputs. + + Returns: + bytes: Compiled VGF binary emitted by ``model-converter``. + + """ with tempfile.TemporaryDirectory() as tmpdir: # We currently write out a flatbuffer as input to the converter