Skip to content

Commit 87d9b8a

Browse files
authored
1 parent 05b977d commit 87d9b8a

37 files changed

Lines changed: 141 additions & 378 deletions

‎backends/arm/_passes/fuse_constant_ops_pass.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,13 @@ def call(self, graph_module):
174174
for node in graph_module.graph.nodes:
175175
if node.op != "call_function":
176176
continue
177-
# Don't fuse ops whose explicit args/kwargs include symbolic shape values.
178-
if self._arg_contains_symbolic_shape(
179-
node.args
180-
) or self._arg_contains_symbolic_shape(node.kwargs):
177+
# Don't fuse TOSA dialect ops as they do not have eager forward functions.
178+
# Also don't fuse ops whose explicit args/kwargs include symbolic shape values.
179+
if (
180+
self._is_tosa_dialect_op(node.target)
181+
or self._arg_contains_symbolic_shape(node.args)
182+
or self._arg_contains_symbolic_shape(node.kwargs)
183+
):
181184
continue
182185

183186
input_nodes = node.all_input_nodes

‎backends/arm/operators/node_visitor.py‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
TosaSpecMapping,
3232
)
3333

34-
3534
logger = logging.getLogger(__name__)
3635

3736

@@ -247,15 +246,3 @@ def get_node_visitors(*args) -> Dict[str, NodeVisitor]:
247246
node_visitors[target] = visitor(*args)
248247

249248
return node_visitors
250-
251-
252-
def get_node_visitor(target: str, tosa_spec: TosaSpecification):
253-
# Ensure all operator modules are imported so visitors are registered.
254-
import executorch.backends.arm.operators # noqa: F401
255-
256-
node_visitor_tuples = _node_visitor_tuples.get(tosa_spec)
257-
for target_name, node_visitor_cls in node_visitor_tuples:
258-
if target_name == target:
259-
return node_visitor_cls(tosa_spec)
260-
261-
raise ValueError(f"No {target} NodeVisitor registered for {tosa_spec}")

‎backends/arm/test/misc/tosa_dialect/test_tosa_gather.py‎

Lines changed: 0 additions & 44 deletions
This file was deleted.

‎backends/arm/test/misc/tosa_dialect/test_tosa_identity.py‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from torch._subclasses.fake_tensor import FakeTensorMode
1414

1515

16-
def test_identity_tosa_FP_fake() -> None:
16+
def test_identity_tosa_FP() -> None:
1717
sample_input = torch.randn((1, 2, 3, 4), dtype=torch.float32)
1818

1919
with TosaLoweringContext(
@@ -23,12 +23,3 @@ def test_identity_tosa_FP_fake() -> None:
2323

2424
assert output.dtype == sample_input.dtype
2525
assert tuple(output.shape) == tuple(sample_input.shape)
26-
27-
28-
def test_identity_tosa_FP_real() -> None:
29-
sample_input = torch.randn((1, 2, 3, 4), dtype=torch.float32)
30-
31-
with TosaLoweringContext(TosaSpecification.create_from_string("TOSA-1.0+FP")):
32-
output = exir_ops.backend.tosa.IDENTITY.default(sample_input)
33-
34-
torch.testing.assert_close(output, sample_input)

‎backends/arm/test/passes/test_ensure_unique_output_nodes_pass.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def test_ensure_unique_output_nodes_no_target_inserts_identity_per_repeated_outp
3535
"executorch_exir_dialects_backend__ops_tosa_IDENTITY_default": 2,
3636
},
3737
)
38+
pipeline.pop_stage("run_method_and_compare_outputs")
3839
pipeline.run()
3940

4041
graph_module = (
@@ -61,4 +62,5 @@ def test_ensure_unique_output_nodes_no_target_keeps_unique_outputs_unchanged() -
6162
"executorch_exir_dialects_backend__ops_tosa_IDENTITY_default",
6263
],
6364
)
65+
pipeline.pop_stage("run_method_and_compare_outputs")
6466
pipeline.run()

‎backends/arm/test/passes/test_rewrite_avg_pool2d_pass.py‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import cast, Dict, Protocol, Tuple
77

88
import torch
9-
from executorch.backends.arm._passes import RewriteAvgPool2dPass
9+
from executorch.backends.arm._passes.rewrite_avg_pool2d_pass import RewriteAvgPool2dPass
1010
from executorch.backends.arm.test import common
1111
from executorch.backends.arm.test.tester.test_pipeline import PassPipeline
1212
from executorch.backends.test.harness.stages import StageType
@@ -29,31 +29,31 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
2929

3030
class AvgPool2dWithoutStride(torch.nn.Module):
3131
def get_inputs(self) -> input_t:
32-
return (torch.rand(1, 3, 9, 9),)
32+
return (torch.rand(1, 3, 8, 8),)
3333

3434
def forward(self, x: torch.Tensor) -> torch.Tensor:
3535
return torch.nn.functional.avg_pool2d(x, kernel_size=3)
3636

3737

3838
class AvgPool2dListKernel(torch.nn.Module):
3939
def get_inputs(self) -> input_t:
40-
return (torch.rand(1, 3, 8, 9),)
40+
return (torch.rand(1, 3, 8, 8),)
4141

4242
def forward(self, x: torch.Tensor) -> torch.Tensor:
4343
return torch.nn.functional.avg_pool2d(x, kernel_size=[2, 3])
4444

4545

4646
class AvgPool2dScalarPadding(torch.nn.Module):
4747
def get_inputs(self) -> input_t:
48-
return (torch.rand(1, 3, 9, 9),)
48+
return (torch.rand(1, 3, 8, 8),)
4949

5050
def forward(self, x: torch.Tensor) -> torch.Tensor:
5151
return torch.nn.functional.avg_pool2d(x, kernel_size=3, stride=2, padding=1)
5252

5353

5454
class AvgPool2dWithEmptyStride(torch.nn.Module):
5555
def get_inputs(self) -> input_t:
56-
return (torch.rand(1, 3, 8, 9),)
56+
return (torch.rand(1, 3, 8, 8),)
5757

5858
def forward(self, x: torch.Tensor) -> torch.Tensor:
5959
return torch.nn.functional.avg_pool2d(x, kernel_size=[2, 3], stride=[])
@@ -81,6 +81,9 @@ def test_rewrite_avg_pool2d_tosa(module: ModuleWithInputs) -> None:
8181
},
8282
pass_list=[RewriteAvgPool2dPass],
8383
)
84+
pipeline.pop_stage(
85+
"run_method_and_compare_outputs"
86+
) # Cannot run aten graph with tosa dialect ops
8487
pipeline.run()
8588

8689

@@ -116,6 +119,7 @@ def test_rewrite_avg_pool2d_tosa_empty_stride_uses_kernel_size() -> None:
116119
},
117120
pass_list=[RewriteAvgPool2dPass],
118121
)
122+
pipeline.pop_stage("run_method_and_compare_outputs")
119123
pipeline.run()
120124

121125
tosa_node = _get_tosa_avg_pool2d_node(pipeline)

‎backends/arm/test/passes/test_rewrite_conv_pass.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ def test_rewrite_conv_tosa_FP():
213213
pipeline = PassPipeline(
214214
module, module.get_inputs(), passes_with_exported_program=[RewriteConvPass]
215215
)
216+
# We cannot run TOSA backend dialect operators in eager mode.
217+
pipeline.pop_stage("run_method_and_compare_outputs")
216218
pipeline.run()
217219

218220

‎backends/arm/test/passes/test_rewrite_max_pool2d_pass.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
3737

3838
class MaxPool2dWithoutStride(torch.nn.Module):
3939
def get_inputs(self) -> input_t:
40-
return (torch.rand(1, 3, 9, 9),)
40+
return (torch.rand(1, 3, 8, 8),)
4141

4242
def forward(self, x: torch.Tensor) -> torch.Tensor:
4343
return torch.nn.functional.max_pool2d(x, kernel_size=3)
4444

4545

4646
class MaxPool2dListKernel(torch.nn.Module):
4747
def get_inputs(self) -> input_t:
48-
return (torch.rand(1, 3, 8, 9),)
48+
return (torch.rand(1, 3, 8, 8),)
4949

5050
def forward(self, x: torch.Tensor) -> torch.Tensor:
5151
return torch.nn.functional.max_pool2d(x, kernel_size=[2, 3])
@@ -56,7 +56,7 @@ def get_inputs(self) -> input_t:
5656
return (torch.rand(1, 3, 8, 8),)
5757

5858
def forward(self, x: torch.Tensor) -> torch.Tensor:
59-
return torch.nn.functional.max_pool2d(x, kernel_size=[2, 2], stride=[])
59+
return torch.nn.functional.max_pool2d(x, kernel_size=[2, 3], stride=[])
6060

6161

6262
class MaxPool2dDynamic(torch.nn.Module):
@@ -94,6 +94,9 @@ def test_rewrite_max_pool2d_tosa(module: ModuleWithInputs) -> None:
9494
},
9595
pass_list=[RemoveGetItemPass, RewriteMaxPool2dPass],
9696
)
97+
pipeline.pop_stage(
98+
"run_method_and_compare_outputs"
99+
) # Cannnot run aten graph with tosa dialect ops
97100
pipeline.run()
98101

99102

@@ -128,10 +131,11 @@ def test_rewrite_max_pool2d_tosa_empty_stride_uses_kernel_size() -> None:
128131
},
129132
pass_list=[RemoveGetItemPass, RewriteMaxPool2dPass],
130133
)
134+
pipeline.pop_stage("run_method_and_compare_outputs")
131135
pipeline.run()
132136

133137
tosa_node = _get_tosa_max_pool2d_node(pipeline)
134-
assert tosa_node.args[2] == [2, 2]
138+
assert tosa_node.args[2] == [2, 3]
135139

136140

137141
def test_rewrite_max_pool2d_tosa_dynamic_shape() -> None:

‎backends/arm/tosa/dialect/BUCK‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ fbcode_target(_kind = runtime.python_library,
66
srcs = [
77
"lib.py",
88
"ops_registration.py",
9-
"real_impl.py",
109
"shape.py",
1110
],
1211
deps = [

‎backends/arm/tosa/dialect/lib.py‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2025-2026 Arm Limited and/or its affiliates.
1+
# Copyright 2025 Arm Limited and/or its affiliates.
22
#
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
@@ -14,22 +14,16 @@
1414
tosa_lib = Library("tosa", "DEF")
1515

1616

17-
def register_tosa_dialect_op(
18-
op_schema,
19-
fake_func,
20-
real_func: Callable | None = None,
21-
real_dispatch_key: str = "CompositeExplicitAutograd",
22-
) -> Callable:
17+
def register_tosa_dialect_op(op_schema, func) -> Callable:
2318
"""Register a TOSA dialect operator with the backend op library.
2419
2520
Args:
2621
op_schema (str): Operator schema without namespace or overload name.
27-
fake_func (Callable): Fake implementation used for registration.
28-
real_func (Optional[Callable]): Optional eager implementation.
29-
real_dispatch_key (str): Dispatch key used for the eager implementation.
22+
func (Callable): Fake implementation used for registration.
3023
3124
Returns:
32-
Callable: Backend dialect operator handle exposed via ``exir_ops``.
25+
Callable: Backend dialect operator handle exposed via ``exir_ops`` and
26+
marked ``not_callable`` for runtime use.
3327
3428
"""
3529
if tosa_lib.ns not in _BACKEND_OP_LIB:
@@ -52,11 +46,19 @@ def register_tosa_dialect_op(
5246
overload_name = "default"
5347
op_qualified_name = f"{tosa_lib.ns}::{opname}"
5448

55-
register_fake(op_qualified_name, fake_func, lib=tosa_lib)
56-
if real_func is not None:
57-
tosa_lib.impl(opname, real_func, real_dispatch_key)
49+
register_fake(op_qualified_name, func, lib=tosa_lib)
50+
5851
op = getattr(getattr(getattr(exir_ops.backend, tosa_lib.ns), opname), overload_name)
5952

53+
# For now, since the TOSA operators are only used for lowering and serialization in the backend
54+
# the op doesn't need to be callable. This can be changed in the future if needed to support
55+
# execution of TOSA ops directly.
56+
def not_callable():
57+
"""Raise when the dialect op handle is invoked at runtime."""
58+
raise RuntimeError("TOSA dialect op is not callable")
59+
60+
op.__equvalent_callable__ = not_callable
61+
6062
return op
6163

6264

0 commit comments

Comments
 (0)