Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions backends/arm/ethosu/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down
49 changes: 43 additions & 6 deletions backends/arm/vgf/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Loading