Skip to content

Commit bd01471

Browse files
Arm backend: Add backend (DW) Conv2d dialect
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]> Change-Id: I1185f51ded5e931ca042f445934cd21e20fdf469
1 parent 0b748bf commit bd01471

16 files changed

+993
-239
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
@@ -91,6 +90,7 @@
9190
ReplaceScalarWithTensorArgPassTOSABI,
9291
ReplaceScalarWithTensorArgPassTOSAMI,
9392
)
93+
from .rewrite_conv2d_pass import RewriteConv2dPass # noqa
9494
from .rewrite_upsample import RewriteUpsamplePass # noqa
9595
from .scalars_to_attribute_pass import ScalarsToAttributePass # noqa
9696
from .size_adjust_input_pass import SizeAdjustInputPass # noqa

backends/arm/_passes/add_bias_pass.py

Lines changed: 0 additions & 71 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,
@@ -91,6 +90,7 @@
9190
ReplaceScalarWithTensorArgPassTOSABI,
9291
ReplaceScalarWithTensorArgPassTOSAMI,
9392
RetraceFoldedDtypesPass,
93+
RewriteConv2dPass,
9494
RewriteUpsamplePass,
9595
ScalarsToAttributePass,
9696
SizeAdjustInputPass,
@@ -204,12 +204,12 @@ def _tosa_INT_pipeline(self, exported_program: ExportedProgram) -> GraphModule:
204204
self.add_pass(InsertTableOpsPass(exported_program))
205205
# If we have a conv2d with int16 activation split up into a convolution
206206
# and an addition, to work-around the lack of support for int48 in torch
207-
# needs to happen before AddBiasPass, but after the table ops are inserted
207+
# needs to happen before RewriteConv2dPass, but after the table ops are inserted
208208
# to be able to validate that conv2d has right dtype arguments.
209209
self.add_pass(DecomposeConv2dWithInt16ActivationPass())
210-
self.add_pass(RewriteUpsamplePass(exported_program))
211-
self.add_pass(AddBiasPass(exported_program))
210+
self.add_pass(RewriteConv2dPass(exported_program))
212211

212+
self.add_pass(RewriteUpsamplePass(exported_program))
213213
self.add_pass(FuseEqualPlaceholdersPass(exported_program))
214214
self.add_pass(ToTosaMemoryFormatPass(exported_program))
215215
self.add_pass(RemoveNoopPass())
@@ -291,9 +291,9 @@ def _tosa_FP_pipeline(self, exported_program: ExportedProgram) -> GraphModule:
291291

292292
self.add_pass(FuseViewCopyTransform())
293293
self.add_pass(FuseConstantArgsPass(exported_program))
294+
self.add_pass(RewriteConv2dPass(exported_program))
294295
self.add_pass(CastInt64BuffersToInt32Pass(exported_program))
295296
self.add_pass(RewriteUpsamplePass(exported_program))
296-
self.add_pass(AddBiasPass(exported_program))
297297
self.add_pass(InsertTableOpsPass(exported_program))
298298
self.add_pass(FuseEqualPlaceholdersPass(exported_program))
299299
self.add_pass(ToTosaMemoryFormatPass(exported_program))

backends/arm/_passes/conv1d_unsqueeze_pass.py

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

99
from typing import Set, Type
1010

11-
from executorch.backends.arm._passes.add_bias_pass import AddBiasPass
11+
from executorch.backends.arm._passes.rewrite_conv2d_pass import RewriteConv2dPass
1212
from executorch.backends.arm._passes.size_adjust_input_pass import SizeAdjustInputPass
1313

1414
from executorch.exir.dialects._ops import ops as exir_ops
@@ -26,7 +26,10 @@ class Conv1dUnsqueezePass(ExportPass):
2626
3) squeeze the output back down to 3d.
2727
"""
2828

29-
_passes_required_after: Set[Type[ExportPass]] = {AddBiasPass, SizeAdjustInputPass}
29+
_passes_required_after: Set[Type[ExportPass]] = {
30+
RewriteConv2dPass,
31+
SizeAdjustInputPass,
32+
}
3033

3134
def call_operator(self, op, args, kwargs, meta):
3235
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.dialects._ops import ops as exir_ops
@@ -41,7 +41,7 @@ class DecomposeCumsumPass(ArmPass):
4141
And the convolution is applied over dimension H.
4242
"""
4343

44-
_passes_required_after: Set[Type[ExportPass]] = {AddBiasPass}
44+
_passes_required_after: Set[Type[ExportPass]] = {RewriteConv2dPass}
4545

4646
def call(self, graph_module):
4747
graph = graph_module.graph

0 commit comments

Comments
 (0)