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
2 changes: 2 additions & 0 deletions backends/arm/operator_support/ethos_u55_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ def __init__(self, reporter: WhyNoPartitionReporter):

targeted_ops_i8_i16_i32 = [
exir_ops.edge.aten.cat.default,
exir_ops.edge.aten.expand_copy.default,
exir_ops.edge.aten.repeat.default,
exir_ops.edge.aten.constant_pad_nd.default,
exir_ops.edge.aten.view.default,
exir_ops.edge.aten.permute.default,
exir_ops.edge.aten.permute_copy.default,
]

target_ops_i8 = tuple(TableOps.included_ops())
Expand Down
5 changes: 4 additions & 1 deletion backends/arm/operators/op_avg_pool2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,13 @@ def define_node(
) -> None:
validate_num_inputs(self.target, inputs, [3, 4, 5, 6, 7])
validate_same_dtype(self.target, [inputs[0], output], ts)
supported_dtypes = [ts.DType.INT8, ts.DType.FP32]
if self.tosa_spec.support_extension("int16"):
supported_dtypes.append(ts.DType.INT16)
validate_valid_dtype(
self.target,
[inputs[0], output],
[ts.DType.INT8, ts.DType.INT16, ts.DType.FP32],
supported_dtypes,
output.tosa_spec,
)

Expand Down
16 changes: 14 additions & 2 deletions backends/arm/operators/op_cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
)
from executorch.backends.arm.operators.operator_validation_utils import (
validate_num_inputs,
validate_same_dtype,
validate_valid_dtype,
)
from executorch.backends.arm.tosa.mapping import TosaArg
from torch.fx import Node
Expand All @@ -35,9 +37,19 @@ def define_node(
inputs: List[TosaArg],
output: TosaArg,
) -> None:
supported_dtypes = [ts.DType.BOOL, ts.DType.INT8, ts.DType.INT32, ts.DType.FP32]
if self.tosa_spec.support_extension("int16"):
supported_dtypes.append(ts.DType.INT16)
validate_num_inputs(self.target, inputs, [1, 2])
input_tosa_args = [TosaArg(arg, output.tosa_spec) for arg in inputs[0].special]
validate_same_dtype(self.target, [*input_tosa_args, output], ts)
validate_valid_dtype(
self.target,
[*input_tosa_args, output],
supported_dtypes,
output.tosa_spec,
)

tensors = inputs[0].special
dim = 0 if len(inputs) < 2 else inputs[1].number
rank = len(output.shape)
dim = (dim + rank) % rank
Expand All @@ -50,7 +62,7 @@ def define_node(
node,
tosa_graph,
ts.Op.CONCAT,
[tensor.name for tensor in tensors],
[tensor.name for tensor in input_tosa_args],
[output.name],
attr,
)
12 changes: 5 additions & 7 deletions backends/arm/operators/op_clamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,18 @@ def define_node(
) -> None:
validate_num_inputs(self.target, inputs, [2, 3])
validate_same_dtype(self.target, [inputs[0], output], ts)
supported_dtypes = [ts.DType.INT8, ts.DType.FP16, ts.DType.FP32]
if self.tosa_spec.support_extension("int16"):
supported_dtypes.append(ts.DType.INT16)
validate_valid_dtype(
self.target,
[inputs[0], output],
[
ts.DType.INT8,
ts.DType.INT16,
ts.DType.FP16,
ts.DType.FP32,
],
supported_dtypes,
output.tosa_spec,
)

node_input_dtype = node.meta["val"].dtype
# NOTE: Quantization of the min/max arguments is handled by QuantizeClampArgumentsPass
# NOTE: Quantization of the min/max arguments is handled by QuantizeOperatorArguments
min_val, max_val = self._get_min_max_arguments(node, node_input_dtype)

attr = ts.TosaSerializerAttribute()
Expand Down
2 changes: 1 addition & 1 deletion backends/arm/operators/op_eq.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def define_node(
validate_valid_dtype(
self.target,
inputs,
[ts.DType.INT8, ts.DType.INT16, ts.DType.INT32, ts.DType.FP32],
[ts.DType.INT32, ts.DType.FP32],
output.tosa_spec,
)
validate_valid_dtype(self.target, output, ts.DType.BOOL, output.tosa_spec)
Expand Down
2 changes: 1 addition & 1 deletion backends/arm/operators/op_ge.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def define_node(
validate_valid_dtype(
self.target,
inputs,
[ts.DType.INT8, ts.DType.INT16, ts.DType.INT32, ts.DType.FP32],
[ts.DType.INT32, ts.DType.FP32],
output.tosa_spec,
)
validate_valid_dtype(self.target, output, ts.DType.BOOL, output.tosa_spec)
Expand Down
2 changes: 1 addition & 1 deletion backends/arm/operators/op_gt.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def define_node(
validate_valid_dtype(
self.target,
inputs,
[ts.DType.INT8, ts.DType.INT16, ts.DType.INT32, ts.DType.FP32],
[ts.DType.INT32, ts.DType.FP32],
output.tosa_spec,
)
validate_valid_dtype(self.target, output, ts.DType.BOOL, output.tosa_spec)
Expand Down
17 changes: 14 additions & 3 deletions backends/arm/operators/op_index_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
NodeVisitor,
register_node_visitor,
)
from executorch.backends.arm.operators.operator_validation_utils import (
validate_num_inputs,
validate_same_dtype,
validate_valid_dtype,
)
from executorch.backends.arm.tosa.mapping import TosaArg

from executorch.backends.arm.tosa.utils import build_reshape_tosa_1_0
Expand Down Expand Up @@ -45,10 +50,16 @@ def define_node(
inputs: List[TosaArg],
output: TosaArg,
) -> None:
if len(inputs) != 3:
raise ValueError(f"Number of inputs are not 3: {len(inputs)}")
validate_num_inputs(self.target, inputs, 3)
validate_same_dtype(self.target, [inputs[0], output], ts)
validate_valid_dtype(
self.target,
[inputs[0], output],
[ts.DType.INT8, ts.DType.INT16, ts.DType.INT32, ts.DType.FP32],
output.tosa_spec,
)

weights, index, indices = inputs
weights, _, indices = inputs

if len(weights.shape) == 2:
weights_new_shape = [1, weights.shape[0], weights.shape[1]]
Expand Down
2 changes: 1 addition & 1 deletion backends/arm/operators/op_le.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def define_node(
validate_valid_dtype(
self.target,
inputs,
[ts.DType.INT8, ts.DType.INT16, ts.DType.INT32, ts.DType.FP32],
[ts.DType.INT32, ts.DType.FP32],
output.tosa_spec,
)
validate_valid_dtype(self.target, output, ts.DType.BOOL, output.tosa_spec)
Expand Down
2 changes: 1 addition & 1 deletion backends/arm/operators/op_lt.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def define_node(
validate_valid_dtype(
self.target,
inputs,
[ts.DType.INT8, ts.DType.INT16, ts.DType.INT32, ts.DType.FP32],
[ts.DType.INT32, ts.DType.FP32],
output.tosa_spec,
)
validate_valid_dtype(self.target, output, ts.DType.BOOL, output.tosa_spec)
Expand Down
5 changes: 4 additions & 1 deletion backends/arm/operators/op_max_pool2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ def define_node(
) -> None:
validate_num_inputs(self.target, inputs, [3, 4, 5, 6])
validate_same_dtype(self.target, [inputs[0], output], ts)
supported_dtypes = [ts.DType.INT8, ts.DType.FP32]
if self.tosa_spec.support_extension("int16"):
supported_dtypes.append(ts.DType.INT16)
validate_valid_dtype(
self.target,
[inputs[0], output],
[ts.DType.INT8, ts.DType.INT16, ts.DType.FP32],
supported_dtypes,
output.tosa_spec,
)

Expand Down
2 changes: 1 addition & 1 deletion backends/arm/operators/op_mul.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def define_node(
validate_valid_dtype(
self.target,
[*inputs, output],
[ts.DType.INT32, ts.DType.FP32],
[ts.DType.INT8, ts.DType.INT16, ts.DType.INT32, ts.DType.FP32],
output.tosa_spec,
)

Expand Down
8 changes: 7 additions & 1 deletion backends/arm/operators/op_permute.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ def define_node(
validate_valid_dtype(
self.target,
[inputs[0], output],
[ts.DType.INT8, ts.DType.INT16, ts.DType.INT32, ts.DType.FP32],
[
ts.DType.BOOL,
ts.DType.INT8,
ts.DType.INT16,
ts.DType.INT32,
ts.DType.FP32,
],
output.tosa_spec,
)

Expand Down
8 changes: 7 additions & 1 deletion backends/arm/operators/op_repeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ def define_node(
validate_valid_dtype(
self.target,
[inputs[0], output],
[ts.DType.INT8, ts.DType.INT32, ts.DType.INT16, ts.DType.FP32],
[
ts.DType.BOOL,
ts.DType.INT8,
ts.DType.INT16,
ts.DType.INT32,
ts.DType.FP32,
],
output.tosa_spec,
)

Expand Down
8 changes: 7 additions & 1 deletion backends/arm/operators/op_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ def define_node(
validate_valid_dtype(
self.target,
[inputs[0], output],
[ts.DType.INT8, ts.DType.INT16, ts.DType.INT32, ts.DType.FP32],
[
ts.DType.BOOL,
ts.DType.INT8,
ts.DType.INT16,
ts.DType.INT32,
ts.DType.FP32,
],
output.tosa_spec,
)

Expand Down
7 changes: 7 additions & 0 deletions backends/arm/operators/op_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from executorch.backends.arm.operators.operator_validation_utils import (
validate_num_inputs,
validate_same_dtype,
validate_valid_dtype,
)
from executorch.backends.arm.tosa import TosaSpecification
from executorch.backends.arm.tosa.mapping import TosaArg
Expand All @@ -39,6 +40,12 @@ def define_node(
) -> None:
validate_num_inputs(self.target, inputs, 3)
validate_same_dtype(self.target, [inputs[0], output], ts)
validate_valid_dtype(
self.target,
[inputs[0], output],
[ts.DType.INT32, ts.DType.FP32],
output.tosa_spec,
)

tensor = inputs[0]
input_shape = list(tensor.shape)
Expand Down
6 changes: 2 additions & 4 deletions backends/arm/operators/op_tosa_conv2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
validate_valid_dtype,
)
from executorch.backends.arm.tosa.mapping import TosaArg
from executorch.backends.arm.tosa.specification import Tosa_1_00, TosaSpecification
from executorch.backends.arm.tosa.specification import TosaSpecification


@register_node_visitor
Expand Down Expand Up @@ -64,9 +64,7 @@ def define_node(
if self.tosa_spec.support_integer():
valid_input_dtypes.append(ts.DType.INT8)

if isinstance(self.tosa_spec, Tosa_1_00) and self.tosa_spec.support_extension(
"int16"
):
if self.tosa_spec.support_extension("int16"):
valid_input_dtypes.append(ts.DType.INT16)
# Check constraints for int16 activations
if inputs[0].dtype == ts.DType.INT16:
Expand Down
10 changes: 8 additions & 2 deletions backends/arm/operators/op_tosa_matmul.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,22 @@ def define_node(
"""Define the TOSA ``MATMUL`` operator."""
validate_num_inputs(self.target, inputs, 2)
validate_same_dtype(self.target, [*inputs], ts)
supported_input_dtypes = [ts.DType.INT8, ts.DType.INT32, ts.DType.FP32]
if self.tosa_spec.support_extension("int16"):
supported_input_dtypes.append(ts.DType.INT16)
validate_valid_dtype(
self.target,
[*inputs],
[ts.DType.INT8, ts.DType.INT16, ts.DType.FP32],
supported_input_dtypes,
output.tosa_spec,
)
supported_output_dtypes = [ts.DType.INT32, ts.DType.FP32]
if self.tosa_spec.support_extension("int16"):
supported_output_dtypes.append(ts.DType.INT48)
validate_valid_dtype(
self.target,
[output],
[ts.DType.INT32, ts.DType.INT48, ts.DType.FP32],
supported_output_dtypes,
output.tosa_spec,
)

Expand Down
36 changes: 17 additions & 19 deletions backends/arm/operators/op_tosa_resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,31 @@ def define_node(
output: TosaArg,
) -> None:
validate_num_inputs(self.target, inputs, [3, 4])
supported_input_dtypes = [ts.DType.INT8, ts.DType.FP32]
if self.tosa_spec.support_extension("int16"):
supported_input_dtypes.append(ts.DType.INT16)
validate_valid_dtype(
self.target,
[inputs[0]],
supported_input_dtypes,
output.tosa_spec,
)
supported_output_dtypes = [ts.DType.FP32]
if node.kwargs.get("resize_mode") == "bilinear":
resize_mode = ts.ResizeMode.BILINEAR
align_corners = bool(node.args[2])
supported_output_dtypes.append(ts.DType.INT32)
if self.tosa_spec.support_extension("int16"):
supported_output_dtypes.append(ts.DType.INT48)
else:
resize_mode = ts.ResizeMode.NEAREST
align_corners = False
validate_same_dtype(self.target, [inputs[0], output], ts)

valid_dtypes = []
if self.tosa_spec.support_integer():
valid_dtypes.extend(
[ts.DType.INT8, ts.DType.INT16, ts.DType.INT32, ts.DType.INT48]
)

if self.tosa_spec.support_float():
valid_dtypes.extend(
[
ts.DType.FP16,
ts.DType.FP32,
]
)

supported_output_dtypes.append(ts.DType.INT8)
if self.tosa_spec.support_extension("int16"):
supported_output_dtypes.append(ts.DType.INT16)
validate_valid_dtype(
self.target,
[inputs[0], output],
valid_dtypes,
output.tosa_spec,
self.target, [output], supported_output_dtypes, output.tosa_spec
)
# tosa_shape output is NHWC, take HW
input_size_yx = tuple([inputs[0].shape[dim] for dim in inputs[0].dim_order])[
Expand Down
15 changes: 10 additions & 5 deletions backends/arm/operators/op_tosa_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ def define_node(
output: TosaArg,
) -> None:
validate_num_inputs(self.target, inputs, 2)
supported_input_dtypes = [ts.DType.INT8]
supported_output_dtypes = [ts.DType.INT8]
if self.tosa_spec.support_extension("int16"):
supported_input_dtypes.append(ts.DType.INT16)
supported_output_dtypes.append(ts.DType.INT32)

validate_valid_dtype(
self.target, inputs, supported_input_dtypes, output.tosa_spec
)
validate_valid_dtype(
self.target, inputs, [ts.DType.INT8, ts.DType.INT16], output.tosa_spec
self.target, output, supported_output_dtypes, output.tosa_spec
)
if inputs[0].dtype == ts.DType.INT8:
validate_valid_dtype(self.target, output, ts.DType.INT8, output.tosa_spec)
if inputs[0].dtype == ts.DType.INT16:
validate_valid_dtype(self.target, output, ts.DType.INT32, output.tosa_spec)

# The name of the table constant is a bit complex.
# The name of the pytorch buffer will be the target of last node argument.
Expand Down
4 changes: 2 additions & 2 deletions backends/arm/operators/op_tosa_transpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ def define_node(
self.target,
[inputs[0], output],
[
ts.DType.BOOL,
ts.DType.INT8,
ts.DType.INT16,
ts.DType.INT32,
ts.DType.FP32,
ts.DType.BOOL,
ts.DType.FP16,
ts.DType.FP32,
],
output.tosa_spec,
)
Expand Down
Loading
Loading