18
18
from executorch .backends .arm .test import common
19
19
from executorch .backends .arm .test .tester .arm_tester import ArmTester
20
20
from executorch .backends .xnnpack .test .tester .tester import Quantize
21
+ from executorch .exir .backend .compile_spec_schema import CompileSpec
21
22
from parameterized import parameterized
22
23
from torchvision .ops import Permute
23
24
24
25
test_data_suite = [
25
26
# (test_name,test_data,dims)
26
- ("zeros " , torch .zeros (10 , 10 , 10 , 10 ), [1 , 0 , 3 , 2 ]),
27
- ("ones " , torch .ones (10 , 10 , 10 , 10 ), [3 , 1 , 0 , 2 ]),
28
- ("rand " , torch .rand (10 , 10 , 10 , 10 ) - 0.5 , [0 , 2 , 3 , 1 ]),
29
- ("randn_pos " , torch .randn ( 10 , 10 , 10 ) + 10 , [2 , 0 , 1 ]),
30
- ("randn_neg " , torch .randn ( 10 , 10 , 10 ) - 10 , [1 , 2 , 0 ]),
31
- ("ramp " , torch .arange ( - 16 , 16 , 0.2 ), [0 ]),
27
+ ("rank_2 " , torch .rand (10 , 10 ), [1 , 0 ]),
28
+ ("rank_3 " , torch .rand (10 , 10 , 10 ), [2 , 0 , 1 ]),
29
+ ("rank_3 " , torch .rand (10 , 10 , 10 ) , [1 , 2 , 0 ]),
30
+ ("rank_4 " , torch .rand ( 1 , 5 , 1 , 10 ) , [0 , 2 , 3 , 1 ]),
31
+ ("rank_4 " , torch .rand ( 1 , 2 , 5 , 10 ) , [1 , 0 , 2 , 3 ]),
32
+ ("rank_4 " , torch .rand ( 1 , 10 , 10 , 5 ), [2 , 0 , 1 , 3 ]),
32
33
]
33
34
34
35
@@ -46,13 +47,18 @@ def forward(self, x):
46
47
return self .permute (x )
47
48
48
49
def _test_permute_tosa_MI_pipeline (
49
- self , module : torch .nn .Module , test_data : Tuple [torch .tensor ]
50
+ self ,
51
+ module : torch .nn .Module ,
52
+ test_data : Tuple [torch .tensor ],
53
+ permute_memory_to_nhwc : bool ,
50
54
):
51
55
(
52
56
ArmTester (
53
57
module ,
54
58
example_inputs = test_data ,
55
- compile_spec = common .get_tosa_compile_spec (),
59
+ compile_spec = common .get_tosa_compile_spec (
60
+ permute_memory_to_nhwc = permute_memory_to_nhwc
61
+ ),
56
62
)
57
63
.export ()
58
64
.check (["torch.ops.aten.permute.default" ])
@@ -87,15 +93,18 @@ def _test_permute_tosa_BI_pipeline(
87
93
.run_method_and_compare_outputs (inputs = test_data )
88
94
)
89
95
90
- def _test_permute_tosa_u55_BI_pipeline (
91
- self , module : torch .nn .Module , test_data : Tuple [torch .tensor ]
96
+ def _test_permute_ethos_BI_pipeline (
97
+ self ,
98
+ module : torch .nn .Module ,
99
+ compile_spec : CompileSpec ,
100
+ test_data : Tuple [torch .Tensor ],
92
101
):
93
102
quantizer = ArmQuantizer ().set_io (get_symmetric_quantization_config ())
94
103
(
95
104
ArmTester (
96
105
module ,
97
106
example_inputs = test_data ,
98
- compile_spec = common . get_u55_compile_spec () ,
107
+ compile_spec = compile_spec ,
99
108
)
100
109
.quantize (Quantize (quantizer , get_symmetric_quantization_config ()))
101
110
.export ()
@@ -106,24 +115,38 @@ def _test_permute_tosa_u55_BI_pipeline(
106
115
.check_not (["executorch_exir_dialects_edge__ops_aten_permute_default" ])
107
116
.check_count ({"torch.ops.higher_order.executorch_call_delegate" : 1 })
108
117
.to_executorch ()
118
+ .serialize ()
109
119
)
110
120
111
121
@parameterized .expand (test_data_suite )
112
122
def test_permute_tosa_MI (
113
123
self , test_name : str , test_data : torch .Tensor , dims : list [int ]
114
124
):
115
- self ._test_permute_tosa_MI_pipeline (self .Permute (dims = dims ), (test_data ,))
125
+ self ._test_permute_tosa_MI_pipeline (self .Permute (dims = dims ), (test_data ,), True )
126
+ self ._test_permute_tosa_MI_pipeline (
127
+ self .Permute (dims = dims ), (test_data ,), False
128
+ )
116
129
117
130
@parameterized .expand (test_data_suite )
118
131
def test_permute_tosa_BI (
119
132
self , test_name : str , test_data : torch .Tensor , dims : list [int ]
120
133
):
121
134
self ._test_permute_tosa_BI_pipeline (self .Permute (dims = dims ), (test_data ,))
122
135
123
- # Expected to fail as Permute is not supported by the NPU
124
- @parameterized .expand (test_data_suite )
136
+ # Expected to fail as TOSA.Transpose is not supported by Ethos-U55.
137
+ @parameterized .expand (test_data_suite [ 0 : 1 ] )
125
138
@unittest .expectedFailure
126
- def test_permute_tosa_u55_BI (
139
+ def test_permute_u55_BI (
127
140
self , test_name : str , test_data : torch .Tensor , dims : list [int ]
128
141
):
129
- self ._test_permute_tosa_u55_BI_pipeline (self .Permute (dims = dims ), (test_data ,))
142
+ self ._test_permute_ethos_BI_pipeline (
143
+ self .Permute (dims = dims ), common .get_u55_compile_spec (), (test_data ,)
144
+ )
145
+
146
+ @parameterized .expand (test_data_suite )
147
+ def test_permute_u85_BI (
148
+ self , test_name : str , test_data : torch .Tensor , dims : list [int ]
149
+ ):
150
+ self ._test_permute_ethos_BI_pipeline (
151
+ self .Permute (dims = dims ), common .get_u85_compile_spec (), (test_data ,)
152
+ )
0 commit comments