Skip to content

Commit f995ff7

Browse files
Arm backend: Add TOSA (DW) Conv2d dialect operator (#14843)
Adds backend dialect operators for: - Conv2D - Depthwise Conv2D Also removes AddBiasPass and moves that logic to new RewriteConv2dPass. Signed-off-by: Oscar Andersson <[email protected]>
1 parent 53c1a77 commit f995ff7

16 files changed

+995
-245
lines changed

backends/arm/_passes/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from . import arm_pass_utils # noqa
88
from .arm_pass import ArmPass # noqa # usort: skip
9-
from .add_bias_pass import AddBiasPass # noqa
109
from .annotate_decomposed_matmul import AnnotateDecomposedMatmulPass # noqa
1110
from .annotate_output_dim_order_pass import AnnotateOutputDimOrderPass # noqa
1211
from .broadcast_args_pass import BroadcastArgsPass # noqa
@@ -92,6 +91,7 @@
9291
ReplaceScalarWithTensorArgPassTOSABI,
9392
ReplaceScalarWithTensorArgPassTOSAMI,
9493
)
94+
from .rewrite_conv2d_pass import RewriteConv2dPass # noqa
9595
from .rewrite_matmul import RewriteMatmulPass # noqa
9696
from .rewrite_upsample import RewriteUpsamplePass # noqa
9797
from .scalars_to_attribute_pass import ScalarsToAttributePass # noqa

backends/arm/_passes/add_bias_pass.py

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

backends/arm/_passes/arm_pass_manager.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import executorch.backends.arm.tosa.dialect # noqa: unused
1414
from executorch.backends.arm._passes import (
15-
AddBiasPass,
1615
AnnotateDecomposedMatmulPass,
1716
AnnotateOutputDimOrderPass,
1817
BroadcastArgsPass,
@@ -93,6 +92,7 @@
9392
ReplaceScalarWithTensorArgPassTOSABI,
9493
ReplaceScalarWithTensorArgPassTOSAMI,
9594
RetraceFoldedDtypesPass,
95+
RewriteConv2dPass,
9696
RewriteMatmulPass,
9797
RewriteUpsamplePass,
9898
ScalarsToAttributePass,
@@ -207,13 +207,13 @@ def _tosa_INT_pipeline(self, exported_program: ExportedProgram) -> GraphModule:
207207
self.add_pass(InsertTableOpsPass(exported_program))
208208
# If we have a conv2d with int16 activation split up into a convolution
209209
# and an addition, to work-around the lack of support for int48 in torch
210-
# needs to happen before AddBiasPass, but after the table ops are inserted
210+
# needs to happen before RewriteConv2dPass, but after the table ops are inserted
211211
# to be able to validate that conv2d has right dtype arguments.
212212
self.add_pass(DecomposeConv2dWithInt16ActivationPass())
213-
self.add_pass(RewriteUpsamplePass())
214-
self.add_pass(AddBiasPass(exported_program))
213+
self.add_pass(RewriteConv2dPass(exported_program))
215214

216215
self.add_pass(RewriteMatmulPass())
216+
self.add_pass(RewriteUpsamplePass())
217217
self.add_pass(FuseEqualPlaceholdersPass(exported_program))
218218
self.add_pass(ToTosaMemoryFormatPass(exported_program))
219219
self.add_pass(RemoveNoopPass())
@@ -297,9 +297,9 @@ def _tosa_FP_pipeline(self, exported_program: ExportedProgram) -> GraphModule:
297297

298298
self.add_pass(FuseViewCopyTransform())
299299
self.add_pass(FuseConstantArgsPass(exported_program))
300+
self.add_pass(RewriteConv2dPass(exported_program))
300301
self.add_pass(CastInt64BuffersToInt32Pass(exported_program))
301302
self.add_pass(RewriteUpsamplePass())
302-
self.add_pass(AddBiasPass(exported_program))
303303
self.add_pass(InsertTableOpsPass(exported_program))
304304
self.add_pass(RewriteMatmulPass())
305305
self.add_pass(FuseEqualPlaceholdersPass(exported_program))

backends/arm/_passes/conv1d_unsqueeze_pass.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from executorch.backends.arm._passes import ArmPass
1212

13-
from executorch.backends.arm._passes.add_bias_pass import AddBiasPass
13+
from executorch.backends.arm._passes.rewrite_conv2d_pass import RewriteConv2dPass
1414
from executorch.backends.arm._passes.size_adjust_input_pass import SizeAdjustInputPass
1515

1616
from executorch.exir.dialects._ops import ops as exir_ops
@@ -28,7 +28,10 @@ class Conv1dUnsqueezePass(ArmPass):
2828
3) squeeze the output back down to 3d.
2929
"""
3030

31-
_passes_required_after: Set[Type[ExportPass]] = {AddBiasPass, SizeAdjustInputPass}
31+
_passes_required_after: Set[Type[ExportPass]] = {
32+
RewriteConv2dPass,
33+
SizeAdjustInputPass,
34+
}
3235

3336
def call_operator(self, op, args, kwargs, meta):
3437
if op != exir_ops.edge.aten.convolution.default:

backends/arm/_passes/decompose_cumsum_pass.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
import torch
1010
from executorch.backends.arm._passes import ArmPass
11-
from executorch.backends.arm._passes.add_bias_pass import AddBiasPass
1211
from executorch.backends.arm._passes.arm_pass_utils import create_node
1312
from executorch.backends.arm._passes.quant_args import QuantArgs
13+
from executorch.backends.arm._passes.rewrite_conv2d_pass import RewriteConv2dPass
1414

1515
from executorch.backends.transforms.utils import create_constant_placeholder
1616
from executorch.exir import ExportedProgram
@@ -42,7 +42,7 @@ class DecomposeCumsumPass(ArmPass):
4242
And the convolution is applied over dimension H.
4343
"""
4444

45-
_passes_required_after: Set[Type[ExportPass]] = {AddBiasPass}
45+
_passes_required_after: Set[Type[ExportPass]] = {RewriteConv2dPass}
4646

4747
def __init__(self, exported_program: ExportedProgram) -> None:
4848
super().__init__()

0 commit comments

Comments
 (0)