Skip to content

Commit 28905e7

Browse files
authored
Arm backend: Remove hard coded TOSA profile in VGF backend (#11818)
* VFG backend supports TOSA-1.X in Arm backend. * For now only FP or INT is supported.
1 parent 10f0d22 commit 28905e7

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

backends/arm/arm_backend.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
# backends. Converts via TOSA as an intermediate form supported by AoT and
1111
# JIT compiler flows.
1212
#
13-
1413
from typing import List, Optional
1514

16-
from executorch.backends.arm.tosa_specification import TosaSpecification
15+
from executorch.backends.arm.tosa_specification import ( # type: ignore[import-not-found]
16+
TosaSpecification,
17+
)
1718

18-
from executorch.exir.backend.compile_spec_schema import CompileSpec
19+
from executorch.exir.backend.compile_spec_schema import ( # type: ignore[import-not-found]
20+
CompileSpec,
21+
)
1922

2023

2124
class ArmCompileSpecBuilder:
@@ -28,6 +31,7 @@ def __init__(self):
2831

2932
def vgf_compile_spec(
3033
self,
34+
tosa_spec: TosaSpecification = None, # type: ignore[assignment]
3135
compiler_flags: Optional[str] = "",
3236
) -> "ArmCompileSpecBuilder":
3337
"""
@@ -40,7 +44,33 @@ def vgf_compile_spec(
4044
self.compiler_flags = [
4145
compiler_flags,
4246
]
43-
self.tosa_spec = TosaSpecification.create_from_string("TOSA-0.80+MI")
47+
48+
if tosa_spec is None:
49+
tosa_spec = TosaSpecification.create_from_string("TOSA-1.0+FP")
50+
51+
tosa_version = tosa_spec.version # type: ignore[attr-defined]
52+
tosa_profiles = tosa_spec.profiles # type: ignore[attr-defined]
53+
54+
if tosa_version.major != 1:
55+
raise ValueError(
56+
"Arm backend only supports converter-backend for TOSA version 1. "
57+
f"Invalid TOSA version: {tosa_version}"
58+
)
59+
60+
if not ("FP" or "INT" in tosa_profiles):
61+
raise ValueError(
62+
"Arm backend only supports converter-backend for FP or INT. "
63+
f"Invalid TOSA profile: {tosa_profiles}"
64+
)
65+
66+
if len(tosa_profiles) != 1:
67+
raise ValueError(
68+
"For now Arm backend only supports converter-backend for either FP or INT. "
69+
f"Invalid TOSA profile: {tosa_profiles}"
70+
)
71+
72+
self.tosa_spec = tosa_spec
73+
4474
return self
4575

4676
def ethosu_compile_spec(

examples/arm/aot_arm_compiler.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ def get_compile_spec(
385385
intermediates: Optional[str] = None,
386386
system_config: Optional[str] = None,
387387
memory_mode: Optional[str] = None,
388+
quantize: bool = False,
388389
) -> list[CompileSpec]:
389390
spec_builder = None
390391
if target.startswith("TOSA"):
@@ -401,7 +402,11 @@ def get_compile_spec(
401402
extra_flags="--verbose-operators --verbose-cycle-estimate",
402403
)
403404
elif "vgf" in target:
404-
spec_builder = ArmCompileSpecBuilder().vgf_compile_spec()
405+
if quantize:
406+
tosa_spec = TosaSpecification.create_from_string("TOSA-1.0+INT")
407+
else:
408+
tosa_spec = TosaSpecification.create_from_string("TOSA-1.0+FP")
409+
spec_builder = ArmCompileSpecBuilder().vgf_compile_spec(tosa_spec)
405410

406411
if intermediates is not None:
407412
spec_builder.dump_intermediate_artifacts_to(intermediates)
@@ -700,6 +705,7 @@ def to_edge_TOSA_delegate(
700705
args.intermediates,
701706
args.system_config,
702707
args.memory_mode,
708+
args.quantize,
703709
)
704710

705711
model_int8 = None
@@ -739,6 +745,7 @@ def to_edge_no_delegate(exported_program, args, model: torch.nn.Module, example_
739745
args.intermediates,
740746
args.system_config,
741747
args.memory_mode,
748+
args.quantize,
742749
)
743750
model, exported_program = quantize_model(
744751
args, model, example_inputs, compile_spec

0 commit comments

Comments
 (0)