@@ -56,6 +56,27 @@ class BitwiseBinary(torch.nn.Module):
56
56
}
57
57
58
58
59
+ class BitwiseBinaryScalar (torch .nn .Module ):
60
+ test_data = {
61
+ "zeros" : lambda : (torch .zeros (1 , 10 , 10 , 10 , dtype = torch .int32 ), 0 ),
62
+ "ones_int8" : lambda : (torch .ones (10 , 10 , 10 , dtype = torch .int8 ), 1 ),
63
+ "pattern_int8" : lambda : (0xAA * torch .ones (1 , 2 , 2 , 2 , dtype = torch .int8 ), 0x77 ),
64
+ "pattern_int16" : lambda : (
65
+ 0xAAAA * torch .ones (1 , 2 , 2 , 2 , dtype = torch .int16 ),
66
+ 0x7777 ,
67
+ ),
68
+ "pattern_int32" : lambda : (
69
+ 0xAAAAAAAA * torch .ones (1 , 2 , 2 , 2 , dtype = torch .int32 ),
70
+ 0x77777777 ,
71
+ ),
72
+ "rand_rank2" : lambda : (torch .randint (- 128 , 127 , (10 , 10 ), dtype = torch .int8 ), 5 ),
73
+ "rand_rank4" : lambda : (
74
+ torch .randint (- 128 , 127 , (1 , 10 , 10 , 10 ), dtype = torch .int8 ),
75
+ - 7 ,
76
+ ),
77
+ }
78
+
79
+
59
80
class And (BitwiseBinary ):
60
81
aten_op = "torch.ops.aten.bitwise_and.Tensor"
61
82
exir_op = "executorch_exir_dialects_edge__ops_aten_bitwise_and_Tensor"
@@ -80,6 +101,36 @@ def forward(self, tensor1: torch.Tensor, tensor2: torch.Tensor):
80
101
return tensor1 .bitwise_or (tensor2 )
81
102
82
103
104
+ class AndScalar (BitwiseBinaryScalar ):
105
+ aten_op = "torch.ops.aten.bitwise_and.Scalar"
106
+ # Tensor because it gets converted from Scalar -> Tensor in lowering
107
+ exir_op = "executorch_exir_dialects_edge__ops_aten_bitwise_and_Tensor"
108
+
109
+ def forward (self , tensor : torch .Tensor , scalar : int ):
110
+ return tensor .bitwise_and (scalar )
111
+
112
+
113
+ class XorScalar (BitwiseBinaryScalar ):
114
+ aten_op = "torch.ops.aten.bitwise_xor.Scalar"
115
+ # Tensor because it gets converted from Scalar -> Tensor in lowering
116
+ exir_op = "executorch_exir_dialects_edge__ops_aten_bitwise_xor_Tensor"
117
+
118
+ def forward (self , tensor : torch .Tensor , scalar : int ):
119
+ return tensor .bitwise_xor (scalar )
120
+
121
+
122
+ class OrScalar (BitwiseBinaryScalar ):
123
+ aten_op = "torch.ops.aten.bitwise_or.Scalar"
124
+ # Tensor because it gets converted from Scalar -> Tensor in lowering
125
+ exir_op = "executorch_exir_dialects_edge__ops_aten_bitwise_or_Tensor"
126
+
127
+ def forward (self , tensor : torch .Tensor , scalar : int ):
128
+ return tensor .bitwise_or (scalar )
129
+
130
+
131
+ # Bitwise AND
132
+
133
+
83
134
@common .parametrize ("test_data" , And ().test_data )
84
135
def test_bitwise_and_tensor_tosa_MI (test_data : input_t2 ):
85
136
pipeline = TosaPipelineMI [input_t2 ](
@@ -94,6 +145,20 @@ def test_bitwise_and_tensor_tosa_MI(test_data: input_t2):
94
145
pipeline .run ()
95
146
96
147
148
+ @common .parametrize ("test_data" , AndScalar .test_data )
149
+ def test_bitwise_and_scalar_tosa_MI (test_data : input_t2 ):
150
+ pipeline = TosaPipelineMI [input_t2 ](
151
+ AndScalar (),
152
+ test_data (),
153
+ AndScalar .aten_op ,
154
+ AndScalar .exir_op ,
155
+ atol = 0 ,
156
+ rtol = 0 ,
157
+ qtol = 0 ,
158
+ )
159
+ pipeline .run ()
160
+
161
+
97
162
@common .parametrize ("test_data" , And ().test_data )
98
163
def test_bitwise_and_tensor_tosa_BI (test_data : input_t2 ):
99
164
pipeline = TosaPipelineBI [input_t2 ](
@@ -110,6 +175,22 @@ def test_bitwise_and_tensor_tosa_BI(test_data: input_t2):
110
175
pipeline .run ()
111
176
112
177
178
+ @common .parametrize ("test_data" , AndScalar .test_data )
179
+ def test_bitwise_and_scalar_tosa_BI (test_data : input_t2 ):
180
+ pipeline = TosaPipelineBI [input_t2 ](
181
+ AndScalar (),
182
+ test_data (),
183
+ AndScalar .aten_op ,
184
+ AndScalar .exir_op ,
185
+ atol = 0 ,
186
+ rtol = 0 ,
187
+ qtol = 0 ,
188
+ )
189
+ pipeline .pop_stage ("quantize" )
190
+ pipeline .pop_stage ("check.quant_nodes" )
191
+ pipeline .run ()
192
+
193
+
113
194
@common .parametrize ("test_data" , And ().test_data )
114
195
def test_bitwise_and_tensor_u55_BI (test_data : input_t2 ):
115
196
# Tests that we don't delegate these ops since they are not supported on U55.
@@ -123,6 +204,43 @@ def test_bitwise_and_tensor_u55_BI(test_data: input_t2):
123
204
pipeline .run ()
124
205
125
206
207
+ @common .parametrize ("test_data" , AndScalar .test_data )
208
+ def test_bitwise_and_scalar_u55_BI (test_data : input_t2 ):
209
+ # There will be one full op which will be delegated.
210
+ num_delegates = 1
211
+ num_exir = 0
212
+ pipeline = OpNotSupportedPipeline [input_t2 ](
213
+ AndScalar (),
214
+ test_data (),
215
+ {
216
+ AndScalar .exir_op : 1 ,
217
+ "executorch_exir_dialects_edge__ops_aten_full_default" : num_exir ,
218
+ },
219
+ num_delegates ,
220
+ quantize = True ,
221
+ u55_subset = True ,
222
+ )
223
+ pipeline .run ()
224
+
225
+
226
+ @common .parametrize ("test_data" , AndScalar .test_data )
227
+ @common .XfailIfNoCorstone320
228
+ def test_bitwise_and_scalar_u85_BI (test_data : input_t2 ):
229
+ pipeline = EthosU85PipelineBI [input_t2 ](
230
+ AndScalar (),
231
+ test_data (),
232
+ AndScalar .aten_op ,
233
+ AndScalar .exir_op ,
234
+ run_on_fvp = True ,
235
+ atol = 0 ,
236
+ rtol = 0 ,
237
+ qtol = 0 ,
238
+ )
239
+ pipeline .pop_stage ("quantize" )
240
+ pipeline .pop_stage ("check.quant_nodes" )
241
+ pipeline .run ()
242
+
243
+
126
244
@common .parametrize ("test_data" , And ().test_data )
127
245
@common .XfailIfNoCorstone320
128
246
def test_bitwise_and_tensor_u85_BI (test_data : input_t2 ):
@@ -155,6 +273,20 @@ def test_bitwise_xor_tensor_tosa_MI(test_data: input_t2):
155
273
pipeline .run ()
156
274
157
275
276
+ @common .parametrize ("test_data" , XorScalar .test_data )
277
+ def test_bitwise_xor_scalar_tosa_MI (test_data : input_t2 ):
278
+ pipeline = TosaPipelineMI [input_t2 ](
279
+ XorScalar (),
280
+ test_data (),
281
+ XorScalar .aten_op ,
282
+ XorScalar .exir_op ,
283
+ atol = 0 ,
284
+ rtol = 0 ,
285
+ qtol = 0 ,
286
+ )
287
+ pipeline .run ()
288
+
289
+
158
290
@common .parametrize ("test_data" , Xor ().test_data )
159
291
def test_bitwise_xor_tensor_tosa_BI (test_data : input_t2 ):
160
292
pipeline = TosaPipelineBI [input_t2 ](
@@ -171,6 +303,22 @@ def test_bitwise_xor_tensor_tosa_BI(test_data: input_t2):
171
303
pipeline .run ()
172
304
173
305
306
+ @common .parametrize ("test_data" , XorScalar .test_data )
307
+ def test_bitwise_xor_scalar_tosa_BI (test_data : input_t2 ):
308
+ pipeline = TosaPipelineBI [input_t2 ](
309
+ XorScalar (),
310
+ test_data (),
311
+ XorScalar .aten_op ,
312
+ XorScalar .exir_op ,
313
+ atol = 0 ,
314
+ rtol = 0 ,
315
+ qtol = 0 ,
316
+ )
317
+ pipeline .pop_stage ("quantize" )
318
+ pipeline .pop_stage ("check.quant_nodes" )
319
+ pipeline .run ()
320
+
321
+
174
322
@common .parametrize ("test_data" , Xor ().test_data )
175
323
def test_bitwise_xor_tensor_u55_BI (test_data : input_t2 ):
176
324
# Tests that we don't delegate these ops since they are not supported on U55.
@@ -184,6 +332,25 @@ def test_bitwise_xor_tensor_u55_BI(test_data: input_t2):
184
332
pipeline .run ()
185
333
186
334
335
+ @common .parametrize ("test_data" , XorScalar .test_data )
336
+ def test_bitwise_xor_scalar_u55_BI (test_data : input_t2 ):
337
+ # There will be one full op which will be delegated.
338
+ num_delegates = 1
339
+ num_exir = 0
340
+ pipeline = OpNotSupportedPipeline [input_t2 ](
341
+ XorScalar (),
342
+ test_data (),
343
+ {
344
+ XorScalar .exir_op : 1 ,
345
+ "executorch_exir_dialects_edge__ops_aten_full_default" : num_exir ,
346
+ },
347
+ num_delegates ,
348
+ quantize = True ,
349
+ u55_subset = True ,
350
+ )
351
+ pipeline .run ()
352
+
353
+
187
354
@common .parametrize ("test_data" , Xor ().test_data )
188
355
@common .XfailIfNoCorstone320
189
356
def test_bitwise_xor_tensor_u85_BI (test_data : input_t2 ):
@@ -202,6 +369,24 @@ def test_bitwise_xor_tensor_u85_BI(test_data: input_t2):
202
369
pipeline .run ()
203
370
204
371
372
+ @common .parametrize ("test_data" , XorScalar .test_data )
373
+ @common .XfailIfNoCorstone320
374
+ def test_bitwise_xor_scalar_u85_BI (test_data : input_t2 ):
375
+ pipeline = EthosU85PipelineBI [input_t2 ](
376
+ XorScalar (),
377
+ test_data (),
378
+ XorScalar .aten_op ,
379
+ XorScalar .exir_op ,
380
+ run_on_fvp = True ,
381
+ atol = 0 ,
382
+ rtol = 0 ,
383
+ qtol = 0 ,
384
+ )
385
+ pipeline .pop_stage ("quantize" )
386
+ pipeline .pop_stage ("check.quant_nodes" )
387
+ pipeline .run ()
388
+
389
+
205
390
@common .parametrize ("test_data" , Or ().test_data )
206
391
def test_bitwise_or_tensor_tosa_MI (test_data : input_t2 ):
207
392
pipeline = TosaPipelineMI [input_t2 ](
@@ -216,6 +401,20 @@ def test_bitwise_or_tensor_tosa_MI(test_data: input_t2):
216
401
pipeline .run ()
217
402
218
403
404
+ @common .parametrize ("test_data" , OrScalar .test_data )
405
+ def test_bitwise_or_scalar_tosa_MI (test_data : input_t2 ):
406
+ pipeline = TosaPipelineMI [input_t2 ](
407
+ OrScalar (),
408
+ test_data (),
409
+ OrScalar .aten_op ,
410
+ OrScalar .exir_op ,
411
+ atol = 0 ,
412
+ rtol = 0 ,
413
+ qtol = 0 ,
414
+ )
415
+ pipeline .run ()
416
+
417
+
219
418
@common .parametrize ("test_data" , Or ().test_data )
220
419
def test_bitwise_or_tensor_tosa_BI (test_data : input_t2 ):
221
420
pipeline = TosaPipelineBI [input_t2 ](
@@ -232,6 +431,22 @@ def test_bitwise_or_tensor_tosa_BI(test_data: input_t2):
232
431
pipeline .run ()
233
432
234
433
434
+ @common .parametrize ("test_data" , OrScalar .test_data )
435
+ def test_bitwise_or_scalar_tosa_BI (test_data : input_t2 ):
436
+ pipeline = TosaPipelineBI [input_t2 ](
437
+ OrScalar (),
438
+ test_data (),
439
+ OrScalar .aten_op ,
440
+ OrScalar .exir_op ,
441
+ atol = 0 ,
442
+ rtol = 0 ,
443
+ qtol = 0 ,
444
+ )
445
+ pipeline .pop_stage ("quantize" )
446
+ pipeline .pop_stage ("check.quant_nodes" )
447
+ pipeline .run ()
448
+
449
+
235
450
@common .parametrize ("test_data" , Or ().test_data )
236
451
def test_bitwise_or_tensor_u55_BI (test_data : input_t2 ):
237
452
# Tests that we don't delegate these ops since they are not supported on U55.
@@ -245,6 +460,25 @@ def test_bitwise_or_tensor_u55_BI(test_data: input_t2):
245
460
pipeline .run ()
246
461
247
462
463
+ @common .parametrize ("test_data" , OrScalar .test_data )
464
+ def test_bitwise_or_scalar_u55_BI (test_data : input_t2 ):
465
+ # There will be one full op which will be delegated.
466
+ num_delegates = 1
467
+ num_exir = 0
468
+ pipeline = OpNotSupportedPipeline [input_t2 ](
469
+ OrScalar (),
470
+ test_data (),
471
+ {
472
+ OrScalar .exir_op : 1 ,
473
+ "executorch_exir_dialects_edge__ops_aten_full_default" : num_exir ,
474
+ },
475
+ num_delegates ,
476
+ quantize = True ,
477
+ u55_subset = True ,
478
+ )
479
+ pipeline .run ()
480
+
481
+
248
482
@common .parametrize ("test_data" , Or ().test_data )
249
483
@common .XfailIfNoCorstone320
250
484
def test_bitwise_or_tensor_u85_BI (test_data : input_t2 ):
@@ -261,3 +495,21 @@ def test_bitwise_or_tensor_u85_BI(test_data: input_t2):
261
495
pipeline .pop_stage ("quantize" )
262
496
pipeline .pop_stage ("check.quant_nodes" )
263
497
pipeline .run ()
498
+
499
+
500
+ @common .parametrize ("test_data" , OrScalar .test_data )
501
+ @common .XfailIfNoCorstone320
502
+ def test_bitwise_or_scalar_u85_BI (test_data : input_t2 ):
503
+ pipeline = EthosU85PipelineBI [input_t2 ](
504
+ OrScalar (),
505
+ test_data (),
506
+ OrScalar .aten_op ,
507
+ OrScalar .exir_op ,
508
+ run_on_fvp = True ,
509
+ atol = 0 ,
510
+ rtol = 0 ,
511
+ qtol = 0 ,
512
+ )
513
+ pipeline .pop_stage ("quantize" )
514
+ pipeline .pop_stage ("check.quant_nodes" )
515
+ pipeline .run ()
0 commit comments