/
TosaOps.td
1968 lines (1618 loc) · 58.6 KB
/
TosaOps.td
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//===-- TosaOps.td - TOSA dialect operation definitions ----*- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines the operation set for the TOSA dialect as defined in
// the TOSA specfication (https://developer.mlplatform.org/w/tosa/).
//
//===----------------------------------------------------------------------===//
#ifndef TOSA_OPS
#define TOSA_OPS
include "mlir/IR/OpBase.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/Interfaces/LoopLikeInterface.td"
include "mlir/Dialect/Tosa/IR/TosaInterfaces.td"
include "mlir/Dialect/Tosa/IR/TosaTypesBase.td"
include "mlir/Dialect/Tosa/IR/TosaOpBase.td"
//===----------------------------------------------------------------------===//
// TOSA Spec Section 2.2
// Operator Class: Tensor Data Engine Operators.
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
// Operator: argmax
//===----------------------------------------------------------------------===//
def Tosa_ArgMaxOp : Tosa_Op<"argmax", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
Pure]> {
let summary = "Perform argmax on the input.";
let description = [{
This returns the index with the largest value across the given axis of the
input tensor.
}];
let arguments = (ins
Tosa_Tensor1Dto4D: $input,
I64Attr: $axis
);
let results = (outs
Tosa_TensorUpto4D: $output
);
}
//===----------------------------------------------------------------------===//
// Operator: avg_pool2d
//===----------------------------------------------------------------------===//
def Tosa_AvgPool2dOp : Tosa_Op<"avg_pool2d", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
Pure]> {
let summary = "Performs max pooling on the input.";
let description = [{
This performs an average pooling over the given input tensor. A sliding
window of size given by <kernel size> is passed over the input tensor, with
the mean value being placed in the output tensor.
}];
let arguments = (ins
Tosa_Tensor4D:$input,
Tosa_IntArrayAttr2:$kernel,
Tosa_IntArrayAttr2:$stride,
Tosa_IntArrayAttr4:$pad,
OptionalAttr<Tosa_UnaryOpQuantizationAttr>:$quantization_info
);
let results = (outs
Tosa_Tensor4D:$output
);
let builders = [Tosa_AvgPool2dOpQuantInfoBuilder];
let hasVerifier = 1;
}
//===----------------------------------------------------------------------===//
// Operator: conv2d
//===----------------------------------------------------------------------===//
def Tosa_Conv2DOp : Tosa_Op<"conv2d", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
Pure]> {
let summary = "2D Convolution Operator";
let description = [{
Performs a 2D convolution over the given tensor input, using the weight
tensor.
}];
let arguments = (ins
Tosa_Tensor4D:$input,
Tosa_Tensor4D:$weight,
Tosa_Tensor1D:$bias,
Tosa_IntArrayAttr4:$pad,
Tosa_IntArrayAttr2:$stride,
Tosa_IntArrayAttr2:$dilation,
OptionalAttr<Tosa_ConvOpQuantizationAttr>:$quantization_info
);
let results = (outs
Tosa_Tensor4D:$output
);
let builders = [Tosa_ConvOpQuantInfoBuilder];
let hasVerifier = 1;
}
//===----------------------------------------------------------------------===//
// Operator: conv3d
//===----------------------------------------------------------------------===//
def Tosa_Conv3DOp : Tosa_Op<"conv3d", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
Pure]> {
let summary = "3D Convolution operator";
let description = [{
Performs a 3D convolution over the given input tensor.
}];
let arguments = (ins
Tosa_Tensor5D:$input,
Tosa_Tensor5D:$weight,
Tosa_Tensor1D:$bias,
Tosa_IntArrayAttr6:$pad,
Tosa_IntArrayAttr3:$stride,
Tosa_IntArrayAttr3:$dilation,
OptionalAttr<Tosa_ConvOpQuantizationAttr>:$quantization_info
);
let results = (outs
Tosa_Tensor5D:$output
);
let builders = [Tosa_ConvOpQuantInfoBuilder];
let hasVerifier = 1;
}
//===----------------------------------------------------------------------===//
// Operator: depthwise_conv2d
//===----------------------------------------------------------------------===//
def Tosa_DepthwiseConv2DOp : Tosa_Op<"depthwise_conv2d", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
Pure]> {
let summary = "Depthwise 2D Convolution operator";
let description = [{
Performs 2D convolutions separately over each channel of the given tensor
input, using the weight tensor.
}];
let arguments = (ins
Tosa_Tensor4D:$input,
Tosa_Tensor4D:$weight,
Tosa_Tensor1D:$bias,
Tosa_IntArrayAttr4:$pad,
Tosa_IntArrayAttr2:$stride,
Tosa_IntArrayAttr2:$dilation,
OptionalAttr<Tosa_ConvOpQuantizationAttr>:$quantization_info
);
let results = (outs
Tosa_Tensor4D:$output
);
let builders = [Tosa_ConvOpQuantInfoBuilder];
let hasVerifier = 1;
}
//===----------------------------------------------------------------------===//
// Operator: fft2d
//===----------------------------------------------------------------------===//
def Tosa_FFT2dOp : Tosa_Op<"fft2d", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
Pure]> {
let summary = "Performs FFT2D operation on the input.";
let description = [{
Performs a batched complex 2D Fast Fourier Transform over the input. The
complex input values are constructed from the corresponding values in the
input_real and input_imag tensors. The resulting values in the output are
split into the output_real and output_imag tensors. No normalization is
applied on either the forward or inverse versions of the operation.
}];
let arguments = (ins
Tosa_Tensor3D:$input_real,
Tosa_Tensor3D:$input_imag,
BoolAttr:$inverse
);
let results = (outs
Tosa_Tensor3D:$output_real,
Tosa_Tensor3D:$output_imag
);
}
//===----------------------------------------------------------------------===//
// Operator: fully_connected
//===----------------------------------------------------------------------===//
def Tosa_FullyConnectedOp : Tosa_Op<"fully_connected", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
Pure]> {
let summary = "Fully Connected operator";
let description = [{
Performs a fully connected network.
}];
let arguments = (ins
Tosa_Tensor2D:$input,
Tosa_Tensor2D:$weight,
Tosa_Tensor1D:$bias,
OptionalAttr<Tosa_ConvOpQuantizationAttr>:$quantization_info
);
let results = (outs
Tosa_Tensor2D:$output
);
let builders = [Tosa_FCOpQuantInfoBuilder];
let hasVerifier = 1;
}
//===----------------------------------------------------------------------===//
// Operator: matmul
//===----------------------------------------------------------------------===//
def Tosa_MatMulOp : Tosa_Op<"matmul", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
Pure]> {
let summary = "Matrix multiplication with bias";
let description = [{
Performs a two dimensional matrix multiplication. This allows both inputs to
be activations, rather than reserving weights as an attribute in the
FULLY_CONNECTED operator.
}];
let arguments = (ins
Tosa_Tensor3D:$a,
Tosa_Tensor3D:$b,
OptionalAttr<Tosa_MatMulOpQuantizationAttr>:$quantization_info
);
let results = (outs
Tosa_Tensor3D:$c
);
let builders = [Tosa_MatMulOpQuantInfoBuilder];
}
//===----------------------------------------------------------------------===//
// Operator: max_pool2d
//===----------------------------------------------------------------------===//
def Tosa_MaxPool2dOp : Tosa_Op<"max_pool2d", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
Pure]> {
let summary = "Performs max pooling on the input.";
let description = [{
This performs a max pooling over the given input tensor. A sliding window of
size given by <kernel size> is passed over the input tensor, with the
maximum value being placed in the
output tensor.
}];
let arguments = (ins
Tosa_Tensor4D:$input,
Tosa_IntArrayAttr2:$kernel,
Tosa_IntArrayAttr2:$stride,
Tosa_IntArrayAttr4:$pad
);
let results = (outs
Tosa_Tensor4D:$output
);
let hasCanonicalizer = 1;
}
//===----------------------------------------------------------------------===//
// Operator: rfft2d
//===----------------------------------------------------------------------===//
def Tosa_RFFT2dOp : Tosa_Op<"rfft2d", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
Pure]> {
let summary = "Performs RFFT2D operation on the input.";
let description = [{
Performs a batched 2D real-valued Fast Fourier Transform over the input where
the input tensor consists of real values producing complex valued output. The
complex output values will be split into the output_real and output_imag
tensor arguments. RFFT2D takes advantage of Hermitian symmetry to only
calculate the first half of the final output axis. Imaginary values with
locations (0,0), (0,W/2), (H/2,0) and (H/2,W/2) are zero.
}];
let arguments = (ins
Tosa_Tensor3D:$input
);
let results = (outs
Tosa_Tensor3D:$output_real,
Tosa_Tensor3D:$output_imag
);
}
//===----------------------------------------------------------------------===//
// Operator: transpose_conv2d
//===----------------------------------------------------------------------===//
def Tosa_TransposeConv2DOp : Tosa_Op<"transpose_conv2d", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
Pure]> {
let summary = "Transpose 2D Convolution operator.";
let description = [{
Performs a 2D transposed convolution over the given tensor input, using the
weights tensor.
}];
let arguments = (ins
Tosa_Tensor4D:$input,
Tosa_Tensor4D:$filter,
Tosa_Tensor1D:$bias,
Tosa_IntArrayAttr4:$out_pad,
Tosa_IntArrayAttr2:$stride,
Tosa_IntArrayAttrUpto4:$out_shape,
OptionalAttr<Tosa_ConvOpQuantizationAttr>:$quantization_info
);
let results = (outs
Tosa_Tensor4D:$output
);
let builders = [Tosa_TransConvOpQuantInfoBuilder];
}
//===----------------------------------------------------------------------===//
// TOSA Spec Section 2.3
// Operator Class: Activation Functions.
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
// Operator: clamp
//===----------------------------------------------------------------------===//
def Tosa_ClampOp : Tosa_Op<"clamp", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
Pure]> {
let summary = "Computes clamp(features, min, max).";
let description = [{
Clamp to an arbitrary minimum and maximum value.
Maximum and minimum values are specified as values in the range of the
input type.
No zero point subtraction is done to the values, thus to clamp to the zero
point value, the zero point itself should be supplied as the minimum value.
}];
let arguments = (ins
Tosa_Tensor:$input,
I64Attr:$min_int,
I64Attr:$max_int,
F32Attr:$min_fp,
F32Attr:$max_fp
);
let results = (outs
Tosa_Tensor:$output
);
let hasCanonicalizer = 1;
}
//===----------------------------------------------------------------------===//
// Operator: sigmoid
//===----------------------------------------------------------------------===//
def Tosa_SigmoidOp : Tosa_Op<"sigmoid", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
Pure]> {
let summary = "Computes elementwise sigmoid of input.";
let description = [{
Sigmoid function: output = 1 / (1 + exp(-input))
For quantized integer data types, the TABLE operator should be used instead
with the following definition. The sigmoid table has 513 entries each of
16-bit precision and covering the input range -16.0 to +16.0
in steps of 1/16.
}];
let arguments = (ins
Tosa_Tensor:$input
);
let results = (outs
Tosa_Tensor:$output
);
}
//===----------------------------------------------------------------------===//
// Operator: tanh
//===----------------------------------------------------------------------===//
def Tosa_TanhOp : Tosa_Op<"tanh", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
Pure]> {
let summary = "Computes elementwise hyperbolic tangent of input";
let description = [{
Parameterized hyperbolic tangent.
For quantized integer data types, the TABLE operator should be used instead
with the following definition. The tanh_table has 513 entries each of
16-bit precision and covering the input range -8.0 to +8.0 in steps of 1/32.
}];
let arguments = (ins
Tosa_Tensor:$input
);
let results = (outs
Tosa_Tensor:$output
);
}
//===----------------------------------------------------------------------===//
// TOSA Spec Section 2.4
// Operator Class: Elementwise unary/binary/ternary operators.
// Operator Subclass: Elementwise binary ops.
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
// Operator: add
//===----------------------------------------------------------------------===//
def Tosa_AddOp : Tosa_Op<"add", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
ResultsBroadcastableShape, Pure, Commutative]> {
let summary = "Elementwise addition operator";
let description = [{
Elementwise addition of input1 and input2. Axis of size 1 will be broadcast,
as necessary.
}];
let arguments = (ins
Tosa_Tensor:$input1,
Tosa_Tensor:$input2
);
let results = (outs
Tosa_Tensor:$output
);
let hasFolder = 1;
}
//===----------------------------------------------------------------------===//
// Operator: arithmetic_right_shift
//===----------------------------------------------------------------------===//
def Tosa_ArithmeticRightShiftOp : Tosa_Op<"arithmetic_right_shift", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
ResultsBroadcastableShape, Pure]> {
let summary = "Elementwise Arithmetic Right Shift";
let description = [{
Elementwise arithmetic right shift of input1 by the amount specified in
input2. Axis of size 1 will be broadcast, as necessary.
}];
let arguments = (ins
Tosa_Tensor:$input1,
Tosa_Tensor:$input2,
BoolAttr:$round
);
let results = (outs
Tosa_Tensor:$output
);
}
//===----------------------------------------------------------------------===//
// Operator: bitwise_and
//===----------------------------------------------------------------------===//
def Tosa_BitwiseAndOp : Tosa_Op<"bitwise_and", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
ResultsBroadcastableShape, Pure, Commutative]> {
let summary = "Bitwise AND operator";
let description = [{
Elementwise bitwise AND of input1 and input2. Axis of size 1
will be broadcast as necessary.
}];
let arguments = (ins
Tosa_Tensor:$input1,
Tosa_Tensor:$input2
);
let results = (outs
Tosa_Tensor:$output
);
}
//===----------------------------------------------------------------------===//
// Operator: bitwise_or
//===----------------------------------------------------------------------===//
def Tosa_BitwiseOrOp : Tosa_Op<"bitwise_or", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
ResultsBroadcastableShape, Pure, Commutative]> {
let summary = "Bitwise OR operator";
let description = [{
Elementwise bitwise OR of input1 and input2. Axis of size 1 will be
broadcast as necessary.
}];
let arguments = (ins
Tosa_Tensor:$input1,
Tosa_Tensor:$input2
);
let results = (outs
Tosa_Tensor:$output
);
}
//===----------------------------------------------------------------------===//
// Operator: bitwise_xor
//===----------------------------------------------------------------------===//
def Tosa_BitwiseXorOp : Tosa_Op<"bitwise_xor", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
ResultsBroadcastableShape, Pure, Commutative]> {
let summary = "Bitwise XOR operator";
let description = [{
Elementwise bitwise XOR of input1 and input2. Axis of size 1 will be
broadcast as necessary.
}];
let arguments = (ins
Tosa_Tensor:$input1,
Tosa_Tensor:$input2
);
let results = (outs
Tosa_Tensor:$output
);
}
//===----------------------------------------------------------------------===//
// Operator: div
//===----------------------------------------------------------------------===//
def Tosa_DivOp : Tosa_Op<"div", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
ResultsBroadcastableShape, Pure]> {
let summary = "Integer divide operator";
let description = [{
Elementwise integer divide operator of input1 by input2. Axis of size 1
will be broadcast, as necessary.
}];
let arguments = (ins
Tosa_Int32Tensor:$input1,
Tosa_Int32Tensor:$input2
);
let results = (outs
Tosa_Int32Tensor:$output
);
let hasFolder = 1;
}
//===----------------------------------------------------------------------===//
// Operator: logical_and
//===----------------------------------------------------------------------===//
def Tosa_LogicalAndOp : Tosa_Op<"logical_and", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
ResultsBroadcastableShape, Commutative, Pure]> {
let summary = "Returns the truth value of x AND y element-wise.";
let description = [{
Elementwise logical AND of input1 and input2. Axis of size 1 will be
broadcast, as necessary.
}];
let arguments = (ins
I1Tensor:$input1,
I1Tensor:$input2
);
let results = (outs
I1Tensor:$z
);
}
//===----------------------------------------------------------------------===//
// Operator: logical_left_shift
//===----------------------------------------------------------------------===//
def Tosa_LogicalLeftShiftOp : Tosa_Op<"logical_left_shift", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
ResultsBroadcastableShape, Pure]> {
let summary = "Elementwise Logical Left Shift";
let description = [{
Elementwise left shift of input1 and input2. Axis of size 1 will be
broadcast, as necessary.
}];
let arguments = (ins
Tosa_Tensor:$input1,
Tosa_Tensor:$input2
);
let results = (outs
Tosa_Tensor:$output
);
}
//===----------------------------------------------------------------------===//
// Operator: logical_right_shift
//===----------------------------------------------------------------------===//
def Tosa_LogicalRightShiftOp : Tosa_Op<"logical_right_shift", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
ResultsBroadcastableShape, Pure]> {
let summary = "Elementwise Logical Right Shift";
let description = [{
Elementwise logical right shift of input1 by the amount specified in input2.
Axis of size 1 will be broadcast, as necessary.
}];
let arguments = (ins
Tosa_Tensor:$input1,
Tosa_Tensor:$input2
);
let results = (outs
Tosa_Tensor:$output
);
}
//===----------------------------------------------------------------------===//
// Operator: logical_or
//===----------------------------------------------------------------------===//
def Tosa_LogicalOrOp : Tosa_Op<"logical_or", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
ResultsBroadcastableShape, Commutative, Pure]> {
let summary = "Returns the truth value of x OR y element-wise.";
let description = [{
Elementwise logical OR of input1 and input2. Axis of size 1 will be
broadcast as necessary.
}];
let arguments = (ins
I1Tensor:$input1,
I1Tensor:$input2
);
let results = (outs
I1Tensor:$z
);
}
//===----------------------------------------------------------------------===//
// Operator: logical_xor
//===----------------------------------------------------------------------===//
def Tosa_LogicalXorOp : Tosa_Op<"logical_xor", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
ResultsBroadcastableShape, Commutative, Pure]> {
let summary = "Returns the truth value of x XOR y element-wise.";
let description = [{
Elementwise logical XOR of input1 and input2. Axis of size 1 will be
broadcast as necessary.
}];
let arguments = (ins
I1Tensor:$input1,
I1Tensor:$input2
);
let results = (outs
I1Tensor:$z
);
}
//===----------------------------------------------------------------------===//
// Operator: maximum
//===----------------------------------------------------------------------===//
def Tosa_MaximumOp : Tosa_Op<"maximum", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
ResultsBroadcastableShape, Pure, Commutative]> {
let summary = "Elementwise Maximum";
let description = [{
Elementwise max of input1 and input2. Axis of size 1 will be broadcast, as
necessary.
}];
let arguments = (ins
Tosa_Tensor:$input1,
Tosa_Tensor:$input2
);
let results = (outs
Tosa_Tensor:$output
);
}
//===----------------------------------------------------------------------===//
// Operator: minimum
//===----------------------------------------------------------------------===//
def Tosa_MinimumOp : Tosa_Op<"minimum", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
ResultsBroadcastableShape, Pure, Commutative]> {
let summary = "Elementwise Minimum";
let description = [{
Elementwise minimum of input1 and input2. Axis of size 1
will be broadcast, as necessary.
}];
let arguments = (ins
Tosa_Tensor:$input1,
Tosa_Tensor:$input2
);
let results = (outs
Tosa_Tensor:$output
);
}
//===----------------------------------------------------------------------===//
// Operator: mul
//===----------------------------------------------------------------------===//
def Tosa_MulOp : Tosa_Op<"mul", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
ResultsBroadcastableShape, Pure, Commutative]> {
let summary = "Multiplication operator";
let description = [{
Elementwise multiplication (Hadamard product) of input1 and input2.
Axis of size 1 will be broadcast, as necessary.
}];
let arguments = (ins
Tosa_Tensor:$input1,
Tosa_Tensor:$input2,
I32Attr:$shift
);
let results = (outs
Tosa_Tensor:$output
);
let hasFolder = 1;
}
//===----------------------------------------------------------------------===//
// Operator: pow
//===----------------------------------------------------------------------===//
def Tosa_PowOp : Tosa_Op<"pow", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
ResultsBroadcastableShape, Pure]> {
let summary = "Computes the power of one value to another.";
let description = [{
Elementwise input1 raised to the power of input2.
Axis of size 1 will be broadcast, as necessary.
}];
let arguments = (ins
Tosa_Tensor:$input1,
Tosa_Tensor:$input2
);
let results = (outs
Tosa_Tensor:$z
);
}
//===----------------------------------------------------------------------===//
// Operator: sub
//===----------------------------------------------------------------------===//
def Tosa_SubOp : Tosa_Op<"sub", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
ResultsBroadcastableShape, Pure]> {
let summary = "Elementwise subtraction operator";
let description = [{
Elementwise subtraction of input1 and input2. Axis of size 1 will be
broadcast as necessary.
}];
let arguments = (ins
Tosa_Tensor:$input1,
Tosa_Tensor:$input2
);
let results = (outs
Tosa_Tensor:$output
);
let hasFolder = 1;
}
//===----------------------------------------------------------------------===//
// Operator: table
//===----------------------------------------------------------------------===//
def Tosa_TableOp : Tosa_Op<"table", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
Pure]> {
let summary = "Table lookup op";
let description = [{
Interpolated table lookup operation. Input values are scaled to create a
fixed-point 9.7 value. The high 9 bits are used to index into the table.
The fractional bits are used to interpolate based on the looked up value and
the index+1 value in the table. The TABLE operator then returns a 16.7
interpolated value. Note that there must be 513 values to handle the full
range of inputs.
The TABLE operator is expected to be used as follows:
* A RESCALE node is expected before the TABLE operator to scale the input
to a full int16_t range for the table lookup
* If an int16_t result is required then follow the TABLE operator with a
RESCALE with a right shift of 7
* If an int8_t result is required then follow the TABLE operator with a
RESCALE with a right shift of 15
}];
let arguments = (ins
Tosa_Tensor: $input,
Tosa_Tensor1D: $table
);
let results = (outs
Tosa_Tensor:$output
);
}
//===----------------------------------------------------------------------===//
// TOSA Spec Section 2.5
// Operator Class: Elementwise unary/binary/ternary operators.
// Operator Subclass: Elementwise unary ops.
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
// Operator: abs
//===----------------------------------------------------------------------===//
def Tosa_AbsOp : Tosa_Op<"abs", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
Pure]> {
let summary = "Elementwise abs op";
let description = [{
Elementwise absolute value operation
}];
let arguments = (ins
Tosa_Tensor:$input1
);
let results = (outs
Tosa_Tensor:$output
);
}
//===----------------------------------------------------------------------===//
// Operator: bitwise_not
//===----------------------------------------------------------------------===//
def Tosa_BitwiseNotOp : Tosa_Op<"bitwise_not", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
ResultsBroadcastableShape, Pure]> {
let summary = "Bitwise NOT operator";
let description = [{
Elementwise bitwise NOT of input tensor.
}];
let arguments = (ins
Tosa_Tensor:$input1
);
let results = (outs
Tosa_Tensor:$output
);
}
//===----------------------------------------------------------------------===//
// Operator: ceil
//===----------------------------------------------------------------------===//
def Tosa_CeilOp : Tosa_Op<"ceil", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
Pure]> {
let summary = "Elementwise ceil op";
let description = [{
Elementwise ceiling operation
}];
let arguments = (ins
Tosa_Tensor:$input1
);
let results = (outs
Tosa_Tensor:$output
);
}
//===----------------------------------------------------------------------===//
// Operator: clz
//===----------------------------------------------------------------------===//
def Tosa_ClzOp : Tosa_Op<"clz", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
Pure]> {
let summary = "Elementwise count leading zero op";
let description = [{
Elementwise count leading zeros operation
}];
let arguments = (ins
Tosa_Tensor:$input1
);
let results = (outs
Tosa_Tensor:$output
);
}
//===----------------------------------------------------------------------===//
// Operator: exp
//===----------------------------------------------------------------------===//
def Tosa_ExpOp : Tosa_Op<"exp", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
Pure]> {
let summary = "Elementwise exp op";
let description = [{
Elementwise e to the x operation
}];
let arguments = (ins
Tosa_Tensor:$input1
);
let results = (outs
Tosa_Tensor:$output