1- # Copyright 2025 NXP
1+ # Copyright 2025-2026 NXP
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.
55
6- from executorch . backends . nxp . backend . ir . converter . conversion . common import (
7- node_uses_shape_broadcasting ,
8- )
6+ import torch
7+
8+ from executorch . backends . nxp . backend . data_format import NXP_NODE_FORMAT
99from executorch .backends .nxp .backend .ir .converter .node_converter import (
1010 CustomDelegationOptions ,
1111 NodeConverter ,
@@ -26,19 +26,41 @@ def _is_supported_on_target(
2626 parameters_mapping : dict [str , Parameter ],
2727 custom_delegation_options : CustomDelegationOptions ,
2828 ) -> bool :
29- if node_uses_shape_broadcasting (node ):
30- # Shape broadcasting may require the addition of `Transpose` ops during conversion.
31- return False
29+ if custom_delegation_options .use_new_flow_neutron_c :
30+ if not NodeConverter .at_least_one_input_shape_matches_the_output_shape (
31+ node
32+ ):
33+ return False
34+
35+ # If one input is in channel first and ranks of input tensors are not equal, we need to add Transposes
36+ # Transpose is currently not supported for new flow
37+ if any (
38+ input_node .meta [NXP_NODE_FORMAT ].is_channels_first ()
39+ for input_node in node .all_input_nodes
40+ ) and NodeConverter ._node_inputs_ranks_not_equal (node ):
41+ return False
42+
43+ supported_types = [torch .int8 , torch .uint8 ]
44+ if not NodeConverter .uses_quantization_type_for_io (
45+ node , supported_types , [0 , 1 ], [0 ]
46+ ):
47+ return False
48+
49+ return True
50+ else :
51+ if NodeConverter .uses_shape_broadcasting (node ):
52+ # Shape broadcasting may require the addition of `Transpose` ops during conversion.
53+ return False
3254
33- node_shape = node .meta ["val" ].shape
55+ node_shape = node .meta ["val" ].shape
3456
35- # Check that at least one dimension is divisible by number of MACS
36- # or all dimensions are equal to one
37- # Otherwise Neutron cannot convert it
38- dim_divisible = any (s % 8 == 0 for s in node_shape ) or all (
39- s == 1 for s in node_shape
40- )
41- return dim_divisible
57+ # Check that at least one dimension is divisible by number of MACS
58+ # or all dimensions are equal to one
59+ # Otherwise Neutron cannot convert it
60+ dim_divisible = any (s % 8 == 0 for s in node_shape ) or all (
61+ s == 1 for s in node_shape
62+ )
63+ return dim_divisible
4264
4365 @staticmethod
4466 def _is_supported_in_IR (
@@ -51,9 +73,11 @@ def _is_supported_in_IR(
5173
5274 return True
5375
54- # mul.Tensor Node format: (Tensor self, Tensor other, *)
5576 def convert (self , node : Node ):
56- """Convert 'mul_tensor' operator to NeutronIR 'Mul'."""
77+ """Convert 'mul_tensor' operator to NeutronIR 'Mul'.
78+ The ExecuTorch schema is:
79+ mul.Tensor(Tensor self, Tensor other)
80+ """
5781 self .assert_convertible (node )
5882 t_op = self ._create_tflite_op_with_io_tensors (node )
5983 t_op .builtin_options = mul_options .Mul ()
0 commit comments