1//===-- TosaOps.td - TOSA dialect operation definitions ----*- tablegen -*-===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8// 9// This file defines the operation set for the TOSA dialect as defined in 10// the TOSA specfication (https://developer.mlplatform.org/w/tosa/). 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef TOSA_OPS 15#define TOSA_OPS 16 17include "mlir/IR/OpBase.td" 18 19include "mlir/Interfaces/SideEffectInterfaces.td" 20include "mlir/Interfaces/InferTypeOpInterface.td" 21include "mlir/Interfaces/LoopLikeInterface.td" 22include "mlir/Dialect/Tosa/IR/TosaInterfaces.td" 23 24include "mlir/Dialect/Tosa/IR/TosaTypesBase.td" 25include "mlir/Dialect/Tosa/IR/TosaOpBase.td" 26 27//===----------------------------------------------------------------------===// 28// TOSA Spec Section 2.2 29// Operator Class: Tensor Data Engine Operators. 30//===----------------------------------------------------------------------===// 31 32//===----------------------------------------------------------------------===// 33// Operator: argmax 34//===----------------------------------------------------------------------===// 35def Tosa_ArgMaxOp : Tosa_Op<"argmax", [ 36 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 37 ["inferReturnTypeComponents"]>, 38 NoSideEffect]> { 39 let summary = "Perform argmax on the input."; 40 41 let description = [{ 42 This returns the index with the largest value across the given axis of the 43 input tensor. 44 }]; 45 46 let arguments = (ins 47 Tosa_Tensor1Dto4D: $input, 48 I64Attr: $axis 49 ); 50 51 let results = (outs 52 Tosa_TensorUpto4D: $output 53 ); 54} 55 56//===----------------------------------------------------------------------===// 57// Operator: avg_pool2d 58//===----------------------------------------------------------------------===// 59def Tosa_AvgPool2dOp : Tosa_Op<"avg_pool2d", [ 60 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 61 ["inferReturnTypeComponents"]>, 62 NoSideEffect]> { 63 let summary = "Performs max pooling on the input."; 64 65 let description = [{ 66 This performs an average pooling over the given input tensor. A sliding 67 window of size given by <kernel size> is passed over the input tensor, with 68 the mean value being placed in the output tensor. 69 }]; 70 71 let arguments = (ins 72 Tosa_Tensor4D:$input, 73 74 Tosa_IntArrayAttr2:$kernel, 75 Tosa_IntArrayAttr2:$stride, 76 Tosa_IntArrayAttr4:$pad, 77 OptionalAttr<Tosa_UnaryOpQuantizationAttr>:$quantization_info 78 ); 79 80 let results = (outs 81 Tosa_Tensor4D:$output 82 ); 83 84 let builders = [Tosa_AvgPool2dOpQuantInfoBuilder]; 85} 86 87//===----------------------------------------------------------------------===// 88// Operator: conv2d 89//===----------------------------------------------------------------------===// 90def Tosa_Conv2DOp : Tosa_Op<"conv2d", [ 91 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 92 ["inferReturnTypeComponents"]>, 93 NoSideEffect]> { 94 let summary = "2D Convolution Operator"; 95 96 let description = [{ 97 Performs a 2D convolution over the given tensor input, using the weight 98 tensor. 99 }]; 100 101 let arguments = (ins 102 Tosa_Tensor4D:$input, 103 Tosa_Tensor4D:$weight, 104 Tosa_Tensor1D:$bias, 105 106 Tosa_IntArrayAttr4:$pad, 107 Tosa_IntArrayAttr2:$stride, 108 Tosa_IntArrayAttr2:$dilation, 109 OptionalAttr<Tosa_ConvOpQuantizationAttr>:$quantization_info 110 ); 111 112 let results = (outs 113 Tosa_Tensor4D:$output 114 ); 115 116 let builders = [Tosa_ConvOpQuantInfoBuilder]; 117 118 let verifier = [{ return verifyConvOp(*this); }]; 119} 120 121//===----------------------------------------------------------------------===// 122// Operator: conv3d 123//===----------------------------------------------------------------------===// 124def Tosa_Conv3DOp : Tosa_Op<"conv3d", [ 125 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 126 ["inferReturnTypeComponents"]>, 127 NoSideEffect]> { 128 let summary = "3D Convolution operator"; 129 130 let description = [{ 131 Performs a 3D convolution over the given input tensor. 132 }]; 133 134 let arguments = (ins 135 Tosa_Tensor5D:$input, 136 Tosa_Tensor5D:$weight, 137 Tosa_Tensor1D:$bias, 138 139 Tosa_IntArrayAttr6:$pad, 140 Tosa_IntArrayAttr3:$stride, 141 Tosa_IntArrayAttr3:$dilation, 142 OptionalAttr<Tosa_ConvOpQuantizationAttr>:$quantization_info 143 ); 144 145 let results = (outs 146 Tosa_Tensor5D:$output 147 ); 148 149 let builders = [Tosa_ConvOpQuantInfoBuilder]; 150 151 let verifier = [{ return verifyConvOp(*this); }]; 152} 153 154//===----------------------------------------------------------------------===// 155// Operator: depthwise_conv2d 156//===----------------------------------------------------------------------===// 157def Tosa_DepthwiseConv2DOp : Tosa_Op<"depthwise_conv2d", [ 158 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 159 ["inferReturnTypeComponents"]>, 160 NoSideEffect]> { 161 let summary = "Depthwise 2D Convolution operator"; 162 163 let description = [{ 164 Performs 2D convolutions separately over each channel of the given tensor 165 input, using the weight tensor. 166 }]; 167 168 let arguments = (ins 169 Tosa_Tensor4D:$input, 170 Tosa_Tensor4D:$weight, 171 Tosa_Tensor1D:$bias, 172 173 Tosa_IntArrayAttr4:$pad, 174 Tosa_IntArrayAttr2:$stride, 175 Tosa_IntArrayAttr2:$dilation, 176 OptionalAttr<Tosa_ConvOpQuantizationAttr>:$quantization_info 177 ); 178 179 let results = (outs 180 Tosa_Tensor4D:$output 181 ); 182 183 let builders = [Tosa_ConvOpQuantInfoBuilder]; 184 185 let verifier = [{ return verifyConvOp(*this); }]; 186} 187 188//===----------------------------------------------------------------------===// 189// Operator: fully_connected 190//===----------------------------------------------------------------------===// 191def Tosa_FullyConnectedOp : Tosa_Op<"fully_connected", [ 192 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 193 ["inferReturnTypeComponents"]>, 194 NoSideEffect]> { 195 let summary = "Fully Connected operator"; 196 197 let description = [{ 198 Performs a fully connected network. 199 }]; 200 201 let arguments = (ins 202 Tosa_Tensor2D:$input, 203 Tosa_Tensor2D:$weight, 204 Tosa_Tensor1D:$bias, 205 OptionalAttr<Tosa_ConvOpQuantizationAttr>:$quantization_info 206 ); 207 208 let results = (outs 209 Tosa_Tensor2D:$output 210 ); 211 212 let builders = [Tosa_FCOpQuantInfoBuilder]; 213 214 let verifier = [{ return verifyConvOp(*this); }]; 215} 216 217//===----------------------------------------------------------------------===// 218// Operator: matmul 219//===----------------------------------------------------------------------===// 220def Tosa_MatMulOp : Tosa_Op<"matmul", [ 221 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 222 ["inferReturnTypeComponents"]>, 223 NoSideEffect]> { 224 let summary = "Matrix multiplication with bias"; 225 226 let description = [{ 227 Performs a two dimensional matrix multiplication. This allows both inputs to 228 be activations, rather than reserving weights as an attribute in the 229 FULLY_CONNECTED operator. 230 }]; 231 232 let arguments = (ins 233 Tosa_Tensor3D:$a, 234 Tosa_Tensor3D:$b, 235 OptionalAttr<Tosa_MatMulOpQuantizationAttr>:$quantization_info 236 ); 237 238 let results = (outs 239 Tosa_Tensor3D:$c 240 ); 241 242 let builders = [Tosa_MatMulOpQuantInfoBuilder]; 243} 244 245//===----------------------------------------------------------------------===// 246// Operator: max_pool2d 247//===----------------------------------------------------------------------===// 248def Tosa_MaxPool2dOp : Tosa_Op<"max_pool2d", [ 249 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 250 ["inferReturnTypeComponents"]>, 251 NoSideEffect]> { 252 let summary = "Performs max pooling on the input."; 253 254 let description = [{ 255 This performs a max pooling over the given input tensor. A sliding window of 256 size given by <kernel size> is passed over the input tensor, with the 257 maximum value being placed in the 258 output tensor. 259 }]; 260 261 let arguments = (ins 262 Tosa_Tensor4D:$input, 263 264 Tosa_IntArrayAttr2:$kernel, 265 Tosa_IntArrayAttr2:$stride, 266 Tosa_IntArrayAttr4:$pad 267 ); 268 269 let results = (outs 270 Tosa_Tensor4D:$output 271 ); 272} 273 274//===----------------------------------------------------------------------===// 275// Operator: transpose_conv2d 276//===----------------------------------------------------------------------===// 277def Tosa_TransposeConv2DOp : Tosa_Op<"transpose_conv2d", [ 278 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 279 ["inferReturnTypeComponents"]>, 280 NoSideEffect]> { 281 let summary = "Transpose 2D Convolution operator."; 282 283 let description = [{ 284 Performs a 2D transposed convolution over the given tensor input, using the 285 weights tensor. 286 }]; 287 288 let arguments = (ins 289 Tosa_Tensor4D:$input, 290 Tosa_Tensor4D:$filter, 291 Tosa_Tensor1D:$bias, 292 293 Tosa_IntArrayAttr2:$out_pad, 294 Tosa_IntArrayAttr2:$stride, 295 Tosa_IntArrayAttr2:$dilation, 296 Tosa_IntArrayAttrUpto4:$out_shape, 297 OptionalAttr<Tosa_ConvOpQuantizationAttr>:$quantization_info 298 ); 299 300 let results = (outs 301 Tosa_Tensor4D:$output 302 ); 303 304 let builders = [Tosa_TransConvOpQuantInfoBuilder]; 305} 306 307//===----------------------------------------------------------------------===// 308// TOSA Spec Section 2.3 309// Operator Class: Activation Functions. 310//===----------------------------------------------------------------------===// 311 312//===----------------------------------------------------------------------===// 313// Operator: clamp 314//===----------------------------------------------------------------------===// 315def Tosa_ClampOp : Tosa_Op<"clamp", [ 316 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 317 ["inferReturnTypeComponents"]>, 318 NoSideEffect]> { 319 let summary = "Computes clamp(features, min, max)."; 320 321 let description = [{ 322 Clamp to an arbitrary minimum and maximum value. Note that the maximum and 323 minimum values are specified as signed quantized values, no scaling happens 324 before or after this operation. 325 }]; 326 327 let arguments = (ins 328 Tosa_Tensor:$input, 329 I64Attr:$min_int, 330 I64Attr:$max_int, 331 F32Attr:$min_fp, 332 F32Attr:$max_fp 333 ); 334 335 let results = (outs 336 Tosa_Tensor:$output 337 ); 338} 339 340//===----------------------------------------------------------------------===// 341// Operator: reluN 342//===----------------------------------------------------------------------===// 343def Tosa_ReluNOp : Tosa_Op<"reluN", [ 344 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 345 ["inferReturnTypeComponents"]>, 346 NoSideEffect]> { 347 let summary = "Computes rectified linear: `max(features, N)`."; 348 349 let description = [{ 350 ReLU with a scalar maximum value. 351 }]; 352 353 let arguments = (ins 354 Tosa_Tensor:$input, 355 I64Attr:$max_int, 356 F32Attr:$max_fp 357 ); 358 359 let results = (outs 360 Tosa_Tensor:$output 361 ); 362} 363 364//===----------------------------------------------------------------------===// 365// Operator: sigmoid 366//===----------------------------------------------------------------------===// 367def Tosa_SigmoidOp : Tosa_Op<"sigmoid", [ 368 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 369 ["inferReturnTypeComponents"]>, 370 NoSideEffect]> { 371 let summary = "Computes elementwise sigmoid of input."; 372 373 let description = [{ 374 Sigmoid function: output = 1 / (1 + exp(-input)) 375 For quantized integer data types, the TABLE operator should be used instead 376 with the following definition. The sigmoid table has 513 entries each of 377 16-bit precision and covering the input range -16.0 to +16.0 378 in steps of 1/16. 379 }]; 380 381 let arguments = (ins 382 Tosa_Tensor:$input 383 ); 384 385 let results = (outs 386 Tosa_Tensor:$output 387 ); 388} 389 390//===----------------------------------------------------------------------===// 391// Operator: tanh 392//===----------------------------------------------------------------------===// 393def Tosa_TanhOp : Tosa_Op<"tanh", [ 394 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 395 ["inferReturnTypeComponents"]>, 396 NoSideEffect]> { 397 let summary = "Computes elementwise hyperbolic tangent of input"; 398 399 let description = [{ 400 Parameterized hyperbolic tangent. 401 For quantized integer data types, the TABLE operator should be used instead 402 with the following definition. The tanh_table has 513 entries each of 403 16-bit precision and covering the input range -8.0 to +8.0 in steps of 1/32. 404 }]; 405 406 let arguments = (ins 407 Tosa_Tensor:$input 408 ); 409 410 let results = (outs 411 Tosa_Tensor:$output 412 ); 413} 414 415//===----------------------------------------------------------------------===// 416// TOSA Spec Section 2.4 417// Operator Class: Elementwise unary/binary/ternary operators. 418// Operator Subclass: Elementwise binary ops. 419//===----------------------------------------------------------------------===// 420 421//===----------------------------------------------------------------------===// 422// Operator: add 423//===----------------------------------------------------------------------===// 424def Tosa_AddOp : Tosa_Op<"add", [ 425 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 426 ["inferReturnTypeComponents"]>, 427 ResultsBroadcastableShape, NoSideEffect, Commutative]> { 428 let summary = "Elementwise addition operator"; 429 430 let description = [{ 431 Elementwise addition of input1 and input2. Axis of size 1 will be broadcast, 432 as necessary. 433 }]; 434 435 let arguments = (ins 436 Tosa_Tensor:$input1, 437 Tosa_Tensor:$input2 438 ); 439 440 let results = (outs 441 Tosa_Tensor:$output 442 ); 443} 444 445//===----------------------------------------------------------------------===// 446// Operator: arithmetic_right_shift 447//===----------------------------------------------------------------------===// 448def Tosa_ArithmeticRightShiftOp : Tosa_Op<"arithmetic_right_shift", [ 449 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 450 ["inferReturnTypeComponents"]>, 451 ResultsBroadcastableShape, NoSideEffect]> { 452 let summary = "Elementwise Arithmetic Right Shift"; 453 454 let description = [{ 455 Elementwise arithmetic right shift of input1 by the amount specified in 456 input2. Axis of size 1 will be broadcast, as necessary. 457 }]; 458 459 let arguments = (ins 460 Tosa_Tensor:$input1, 461 Tosa_Tensor:$input2, 462 BoolAttr:$round 463 ); 464 465 let results = (outs 466 Tosa_Tensor:$output 467 ); 468} 469 470//===----------------------------------------------------------------------===// 471// Operator: bitwise_and 472//===----------------------------------------------------------------------===// 473def Tosa_BitwiseAndOp : Tosa_Op<"bitwise_and", [ 474 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 475 ["inferReturnTypeComponents"]>, 476 ResultsBroadcastableShape, NoSideEffect, Commutative]> { 477 let summary = "Bitwise AND operator"; 478 479 let description = [{ 480 Elementwise bitwise AND of input1 and input2. Axis of size 1 481 will be broadcast as necessary. 482 }]; 483 484 let arguments = (ins 485 Tosa_Tensor:$input1, 486 Tosa_Tensor:$input2 487 ); 488 489 let results = (outs 490 Tosa_Tensor:$output 491 ); 492} 493 494//===----------------------------------------------------------------------===// 495// Operator: bitwise_or 496//===----------------------------------------------------------------------===// 497def Tosa_BitwiseOrOp : Tosa_Op<"bitwise_or", [ 498 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 499 ["inferReturnTypeComponents"]>, 500 ResultsBroadcastableShape, NoSideEffect, Commutative]> { 501 let summary = "Bitwise OR operator"; 502 503 let description = [{ 504 Elementwise bitwise OR of input1 and input2. Axis of size 1 will be 505 broadcast as necessary. 506 }]; 507 508 let arguments = (ins 509 Tosa_Tensor:$input1, 510 Tosa_Tensor:$input2 511 ); 512 513 let results = (outs 514 Tosa_Tensor:$output 515 ); 516} 517 518//===----------------------------------------------------------------------===// 519// Operator: bitwise_xor 520//===----------------------------------------------------------------------===// 521def Tosa_BitwiseXorOp : Tosa_Op<"bitwise_xor", [ 522 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 523 ["inferReturnTypeComponents"]>, 524 ResultsBroadcastableShape, NoSideEffect, Commutative]> { 525 let summary = "Bitwise XOR operator"; 526 527 let description = [{ 528 Elementwise bitwise XOR of input1 and input2. Axis of size 1 will be 529 broadcast as necessary. 530 }]; 531 532 let arguments = (ins 533 Tosa_Tensor:$input1, 534 Tosa_Tensor:$input2 535 ); 536 537 let results = (outs 538 Tosa_Tensor:$output 539 ); 540} 541 542//===----------------------------------------------------------------------===// 543// Operator: div 544//===----------------------------------------------------------------------===// 545def Tosa_DivOp : Tosa_Op<"div", [ 546 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 547 ["inferReturnTypeComponents"]>, 548 ResultsBroadcastableShape, NoSideEffect]> { 549 let summary = "Integer divide operator"; 550 551 let description = [{ 552 Elementwise integer divide operator of input1 by input2. Axis of size 1 553 will be broadcast, as necessary. 554 }]; 555 556 let arguments = (ins 557 Tosa_Int32Tensor:$input1, 558 Tosa_Int32Tensor:$input2 559 ); 560 561 let results = (outs 562 Tosa_Int32Tensor:$output 563 ); 564} 565 566//===----------------------------------------------------------------------===// 567// Operator: logical_and 568//===----------------------------------------------------------------------===// 569def Tosa_LogicalAndOp : Tosa_Op<"logical_and", [ 570 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 571 ["inferReturnTypeComponents"]>, 572 ResultsBroadcastableShape, Commutative, NoSideEffect]> { 573 let summary = "Returns the truth value of x AND y element-wise."; 574 575 let description = [{ 576 Elementwise logical AND of input1 and input2. Axis of size 1 will be 577 broadcast, as necessary. 578 }]; 579 580 let arguments = (ins 581 I1Tensor:$input1, 582 I1Tensor:$input2 583 ); 584 585 let results = (outs 586 I1Tensor:$z 587 ); 588} 589 590//===----------------------------------------------------------------------===// 591// Operator: logical_left_shift 592//===----------------------------------------------------------------------===// 593def Tosa_LogicalLeftShiftOp : Tosa_Op<"logical_left_shift", [ 594 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 595 ["inferReturnTypeComponents"]>, 596 ResultsBroadcastableShape, NoSideEffect]> { 597 let summary = "Elementwise Logical Left Shift"; 598 599 let description = [{ 600 Elementwise left shift of input1 and input2. Axis of size 1 will be 601 broadcast, as necessary. 602 }]; 603 604 let arguments = (ins 605 Tosa_Tensor:$input1, 606 Tosa_Tensor:$input2 607 ); 608 609 let results = (outs 610 Tosa_Tensor:$output 611 ); 612} 613 614//===----------------------------------------------------------------------===// 615// Operator: logical_right_shift 616//===----------------------------------------------------------------------===// 617def Tosa_LogicalRightShiftOp : Tosa_Op<"logical_right_shift", [ 618 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 619 ["inferReturnTypeComponents"]>, 620 ResultsBroadcastableShape, NoSideEffect]> { 621 let summary = "Elementwise Logical Right Shift"; 622 623 let description = [{ 624 Elementwise logical right shift of input1 by the amount specified in input2. 625 Axis of size 1 will be broadcast, as necessary. 626 }]; 627 628 let arguments = (ins 629 Tosa_Tensor:$input1, 630 Tosa_Tensor:$input2 631 ); 632 633 let results = (outs 634 Tosa_Tensor:$output 635 ); 636} 637 638//===----------------------------------------------------------------------===// 639// Operator: logical_or 640//===----------------------------------------------------------------------===// 641def Tosa_LogicalOrOp : Tosa_Op<"logical_or", [ 642 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 643 ["inferReturnTypeComponents"]>, 644 ResultsBroadcastableShape, Commutative, NoSideEffect]> { 645 let summary = "Returns the truth value of x OR y element-wise."; 646 647 let description = [{ 648 Elementwise logical OR of input1 and input2. Axis of size 1 will be 649 broadcast as necessary. 650 }]; 651 652 let arguments = (ins 653 I1Tensor:$input1, 654 I1Tensor:$input2 655 ); 656 657 let results = (outs 658 I1Tensor:$z 659 ); 660} 661 662//===----------------------------------------------------------------------===// 663// Operator: logical_xor 664//===----------------------------------------------------------------------===// 665def Tosa_LogicalXorOp : Tosa_Op<"logical_xor", [ 666 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 667 ["inferReturnTypeComponents"]>, 668 ResultsBroadcastableShape, Commutative, NoSideEffect]> { 669 let summary = "Returns the truth value of x XOR y element-wise."; 670 671 let description = [{ 672 Elementwise logical XOR of input1 and input2. Axis of size 1 will be 673 broadcast as necessary. 674 }]; 675 676 let arguments = (ins 677 I1Tensor:$input1, 678 I1Tensor:$input2 679 ); 680 681 let results = (outs 682 I1Tensor:$z 683 ); 684} 685 686//===----------------------------------------------------------------------===// 687// Operator: maximum 688//===----------------------------------------------------------------------===// 689def Tosa_MaximumOp : Tosa_Op<"maximum", [ 690 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 691 ["inferReturnTypeComponents"]>, 692 ResultsBroadcastableShape, NoSideEffect, Commutative]> { 693 let summary = "Elementwise Maximum"; 694 695 let description = [{ 696 Elementwise max of input1 and input2. Axis of size 1 will be broadcast, as 697 necessary. 698 }]; 699 700 let arguments = (ins 701 Tosa_Tensor:$input1, 702 Tosa_Tensor:$input2 703 ); 704 705 let results = (outs 706 Tosa_Tensor:$output 707 ); 708} 709 710//===----------------------------------------------------------------------===// 711// Operator: minimum 712//===----------------------------------------------------------------------===// 713def Tosa_MinimumOp : Tosa_Op<"minimum", [ 714 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 715 ["inferReturnTypeComponents"]>, 716 ResultsBroadcastableShape, NoSideEffect, Commutative]> { 717 let summary = "Elementwise Minimum"; 718 719 let description = [{ 720 Elementwise minimum of input1 and input2. Axis of size 1 721 will be broadcast, as necessary. 722 }]; 723 724 let arguments = (ins 725 Tosa_Tensor:$input1, 726 Tosa_Tensor:$input2 727 ); 728 729 let results = (outs 730 Tosa_Tensor:$output 731 ); 732} 733 734//===----------------------------------------------------------------------===// 735// Operator: mul 736//===----------------------------------------------------------------------===// 737def Tosa_MulOp : Tosa_Op<"mul", [ 738 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 739 ["inferReturnTypeComponents"]>, 740 ResultsBroadcastableShape, NoSideEffect, Commutative]> { 741 let summary = "Multiplication operator"; 742 743 let description = [{ 744 Elementwise multiplication (Hadamard product) of input1 and input2. 745 Axis of size 1 will be broadcast, as necessary. 746 }]; 747 748 let arguments = (ins 749 Tosa_Tensor:$input1, 750 Tosa_Tensor:$input2, 751 I32Attr:$shift 752 ); 753 754 let results = (outs 755 Tosa_Tensor:$output 756 ); 757} 758 759//===----------------------------------------------------------------------===// 760// Operator: pow 761//===----------------------------------------------------------------------===// 762def Tosa_PowOp : Tosa_Op<"pow", [ 763 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 764 ["inferReturnTypeComponents"]>, 765 ResultsBroadcastableShape, NoSideEffect]> { 766 let summary = "Computes the power of one value to another."; 767 768 let description = [{ 769 Elementwise input1 raised to the power of input2. 770 Axis of size 1 will be broadcast, as necessary. 771 }]; 772 773 let arguments = (ins 774 Tosa_Tensor:$input1, 775 Tosa_Tensor:$input2 776 ); 777 778 let results = (outs 779 Tosa_Tensor:$z 780 ); 781} 782 783//===----------------------------------------------------------------------===// 784// Operator: sub 785//===----------------------------------------------------------------------===// 786def Tosa_SubOp : Tosa_Op<"sub", [ 787 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 788 ["inferReturnTypeComponents"]>, 789 ResultsBroadcastableShape, NoSideEffect]> { 790 let summary = "Elementwise subtraction operator"; 791 792 let description = [{ 793 Elementwise subtraction of input1 and input2. Axis of size 1 will be 794 broadcast as necessary. 795 }]; 796 797 let arguments = (ins 798 Tosa_Tensor:$input1, 799 Tosa_Tensor:$input2 800 ); 801 802 let results = (outs 803 Tosa_Tensor:$output 804 ); 805} 806 807//===----------------------------------------------------------------------===// 808// Operator: table 809//===----------------------------------------------------------------------===// 810def Tosa_TableOp : Tosa_Op<"table", [ 811 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 812 ["inferReturnTypeComponents"]>, 813 NoSideEffect]> { 814 let summary = "Table lookup op"; 815 816 let description = [{ 817 Interpolated table lookup operation. Input values are scaled to create a 818 fixed-point 9.7 value. The high 9 bits are used to index into the table. 819 The fractional bits are used to interpolate based on the looked up value and 820 the index+1 value in the table. The TABLE operator then returns a 16.7 821 interpolated value. Note that there must be 513 values to handle the full 822 range of inputs. 823 824 The TABLE operator is expected to be used as follows: 825 * A RESCALE node is expected before the TABLE operator to scale the input 826 to a full int16_t range for the table lookup 827 * If an int16_t result is required then follow the TABLE operator with a 828 RESCALE with a right shift of 7 829 * If an int8_t result is required then follow the TABLE operator with a 830 RESCALE with a right shift of 15 831 }]; 832 833 let arguments = (ins 834 Tosa_Tensor: $input, 835 Tosa_Tensor1D: $table 836 ); 837 838 let results = (outs 839 Tosa_Tensor:$output 840 ); 841 842} 843 844//===----------------------------------------------------------------------===// 845// TOSA Spec Section 2.5 846// Operator Class: Elementwise unary/binary/ternary operators. 847// Operator Subclass: Elementwise unary ops. 848//===----------------------------------------------------------------------===// 849 850//===----------------------------------------------------------------------===// 851// Operator: abs 852//===----------------------------------------------------------------------===// 853def Tosa_AbsOp : Tosa_Op<"abs", [ 854 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 855 ["inferReturnTypeComponents"]>, 856 NoSideEffect]> { 857 let summary = "Elementwise abs op"; 858 859 let description = [{ 860 Elementwise absolute value operation 861 }]; 862 863 let arguments = (ins 864 Tosa_Tensor:$input1 865 ); 866 867 let results = (outs 868 Tosa_Tensor:$output 869 ); 870} 871 872//===----------------------------------------------------------------------===// 873// Operator: bitwise_not 874//===----------------------------------------------------------------------===// 875def Tosa_BitwiseNotOp : Tosa_Op<"bitwise_not", [ 876 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 877 ["inferReturnTypeComponents"]>, 878 ResultsBroadcastableShape, NoSideEffect]> { 879 let summary = "Bitwise NOT operator"; 880 881 let description = [{ 882 Elementwise bitwise NOT of input tensor. 883 }]; 884 885 let arguments = (ins 886 Tosa_Tensor:$input1 887 ); 888 889 let results = (outs 890 Tosa_Tensor:$output 891 ); 892} 893 894//===----------------------------------------------------------------------===// 895// Operator: ceil 896//===----------------------------------------------------------------------===// 897def Tosa_CeilOp : Tosa_Op<"ceil", [ 898 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 899 ["inferReturnTypeComponents"]>, 900 NoSideEffect]> { 901 let summary = "Elementwise ceil op"; 902 903 let description = [{ 904 Elementwise ceiling operation 905 }]; 906 907 let arguments = (ins 908 Tosa_Tensor:$input1 909 ); 910 911 let results = (outs 912 Tosa_Tensor:$output 913 ); 914} 915 916//===----------------------------------------------------------------------===// 917// Operator: clz 918//===----------------------------------------------------------------------===// 919def Tosa_ClzOp : Tosa_Op<"clz", [ 920 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 921 ["inferReturnTypeComponents"]>, 922 NoSideEffect]> { 923 let summary = "Elementwise count leading zero op"; 924 925 let description = [{ 926 Elementwise count leading zeros operation 927 }]; 928 929 let arguments = (ins 930 Tosa_Tensor:$input1 931 ); 932 933 let results = (outs 934 Tosa_Tensor:$output 935 ); 936} 937 938//===----------------------------------------------------------------------===// 939// Operator: exp 940//===----------------------------------------------------------------------===// 941def Tosa_ExpOp : Tosa_Op<"exp", [ 942 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 943 ["inferReturnTypeComponents"]>, 944 NoSideEffect]> { 945 let summary = "Elementwise exp op"; 946 947 let description = [{ 948 Elementwise e to the x operation 949 }]; 950 951 let arguments = (ins 952 Tosa_Tensor:$input1 953 ); 954 955 let results = (outs 956 Tosa_Tensor:$output 957 ); 958} 959 960//===----------------------------------------------------------------------===// 961// Operator: floor 962//===----------------------------------------------------------------------===// 963def Tosa_FloorOp : Tosa_Op<"floor", [ 964 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 965 ["inferReturnTypeComponents"]>, 966 NoSideEffect]> { 967 let summary = "Elementwise floor op"; 968 969 let description = [{ 970 Elementwise floor operation 971 }]; 972 973 let arguments = (ins 974 Tosa_Tensor:$input1 975 ); 976 977 let results = (outs 978 Tosa_Tensor:$output 979 ); 980} 981 982//===----------------------------------------------------------------------===// 983// Operator: log 984//===----------------------------------------------------------------------===// 985def Tosa_LogOp : Tosa_Op<"log", [ 986 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 987 ["inferReturnTypeComponents"]>, 988 NoSideEffect]> { 989 let summary = "Elementwise log op"; 990 991 let description = [{ 992 Elementwise natural logarithm operation 993 }]; 994 995 let arguments = (ins 996 Tosa_Tensor:$input1 997 ); 998 999 let results = (outs 1000 Tosa_Tensor:$output 1001 ); 1002} 1003 1004//===----------------------------------------------------------------------===// 1005// Operator: logical_not 1006//===----------------------------------------------------------------------===// 1007def Tosa_LogicalNotOp : Tosa_Op<"logical_not", [ 1008 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1009 ["inferReturnTypeComponents"]>, 1010 NoSideEffect]> { 1011 let summary = "Returns the truth value of NOT x element-wise."; 1012 1013 let description = [{ 1014 Elementwise logical NOT of input. 1015 }]; 1016 1017 let arguments = (ins 1018 I1Tensor:$input1 1019 ); 1020 1021 let results = (outs 1022 I1Tensor:$output 1023 ); 1024} 1025 1026//===----------------------------------------------------------------------===// 1027// Operator: negate 1028//===----------------------------------------------------------------------===// 1029def Tosa_NegateOp : Tosa_Op<"negate", [ 1030 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1031 ["inferReturnTypeComponents"]>, 1032 NoSideEffect]> { 1033 let summary = "Elementwise negate op"; 1034 1035 let description = [{ 1036 Elementwise negation operation 1037 }]; 1038 1039 let arguments = (ins 1040 Tosa_Tensor:$input1, 1041 OptionalAttr<Tosa_UnaryOpQuantizationAttr>:$quantization_info 1042 ); 1043 1044 let results = (outs 1045 Tosa_Tensor:$output 1046 ); 1047 1048 let builders = [Tosa_UnaryOpQuantInfoBuilder]; 1049} 1050 1051//===----------------------------------------------------------------------===// 1052// Operator: reciprocal 1053//===----------------------------------------------------------------------===// 1054def Tosa_ReciprocalOp : Tosa_Op<"reciprocal", [ 1055 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1056 ["inferReturnTypeComponents"]>, 1057 NoSideEffect]> { 1058 let summary = "Elementwise reciprocal op"; 1059 1060 let description = [{ 1061 Elementwise reciprocal operation. For integer operation, a TABLE should be 1062 used with the appropriate ranges. 1063 }]; 1064 1065 let arguments = (ins 1066 Tosa_Tensor:$input1 1067 ); 1068 1069 let results = (outs 1070 Tosa_Tensor:$output 1071 ); 1072} 1073 1074//===----------------------------------------------------------------------===// 1075// Operator: rsqrt 1076//===----------------------------------------------------------------------===// 1077def Tosa_RsqrtOp : Tosa_Op<"rsqrt", [ 1078 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1079 ["inferReturnTypeComponents"]>, 1080 NoSideEffect]> { 1081 let summary = "Elementwise 1/sqrt op"; 1082 1083 let description = [{ 1084 Elementwise reciprocal square root operation. For integer operation, a TABLE 1085 should be used with the appropriate ranges. 1086 }]; 1087 1088 let arguments = (ins 1089 Tosa_Tensor:$input1 1090 ); 1091 1092 let results = (outs 1093 Tosa_Tensor:$output 1094 ); 1095} 1096 1097//===----------------------------------------------------------------------===// 1098// TOSA Spec Section 2.6 1099// Operator Class: Elementwise unary/binary/ternary operators. 1100// Operator Subclass: Elementwise ternary ops. 1101//===----------------------------------------------------------------------===// 1102 1103//===----------------------------------------------------------------------===// 1104// Operator: select 1105//===----------------------------------------------------------------------===// 1106def Tosa_SelectOp : Tosa_Op<"select", [ 1107 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1108 ["inferReturnTypeComponents"]>, NoSideEffect]> { 1109 let summary = "Elementwise select operator"; 1110 1111 let description = [{ 1112 Elementwise select of the output based on a condition. 1113 }]; 1114 1115 let arguments = (ins 1116 I1Tensor:$input1, 1117 Tosa_Tensor:$input2, 1118 Tosa_Tensor:$input3 1119 ); 1120 1121 let results = (outs 1122 Tosa_Tensor:$output 1123 ); 1124} 1125 1126//===----------------------------------------------------------------------===// 1127// TOSA Spec Section 2.7 1128// Operator Class: Logical Operations. 1129//===----------------------------------------------------------------------===// 1130 1131//===----------------------------------------------------------------------===// 1132// Operator: equal 1133//===----------------------------------------------------------------------===// 1134def Tosa_EqualOp : Tosa_Op<"equal", [ 1135 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1136 ["inferReturnTypeComponents"]>, 1137 ResultsBroadcastableShape, Commutative, NoSideEffect]> { 1138 let summary = "Returns the truth value of (x == y) element-wise."; 1139 1140 let description = [{ 1141 Elementwise comparison operation 1142 }]; 1143 1144 let arguments = (ins 1145 Tosa_Tensor:$input1, 1146 Tosa_Tensor:$input2 1147 ); 1148 1149 let results = (outs 1150 I1Tensor:$output 1151 ); 1152} 1153 1154//===----------------------------------------------------------------------===// 1155// Operator: greater 1156//===----------------------------------------------------------------------===// 1157def Tosa_GreaterOp : Tosa_Op<"greater", [ 1158 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1159 ["inferReturnTypeComponents"]>, 1160 ResultsBroadcastableShape, NoSideEffect]> { 1161 let summary = "Returns the truth value of (x > y) element-wise."; 1162 1163 let description = [{ 1164 Elementwise greater than comparison operation 1165 }]; 1166 1167 let arguments = (ins 1168 Tosa_Tensor:$input1, 1169 Tosa_Tensor:$input2 1170 ); 1171 1172 let results = (outs 1173 I1Tensor:$output 1174 ); 1175} 1176 1177//===----------------------------------------------------------------------===// 1178// Operator: greater_equal 1179//===----------------------------------------------------------------------===// 1180def Tosa_GreaterEqualOp : Tosa_Op<"greater_equal", [ 1181 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1182 ["inferReturnTypeComponents"]>, 1183 ResultsBroadcastableShape, NoSideEffect]> { 1184 let summary = "Returns the truth value of (x >= y) element-wise."; 1185 1186 let description = [{ 1187 Elementwise comparison operation 1188 }]; 1189 1190 let arguments = (ins 1191 Tosa_Tensor:$input1, 1192 Tosa_Tensor:$input2 1193 ); 1194 1195 let results = (outs 1196 I1Tensor:$output 1197 ); 1198} 1199 1200//===----------------------------------------------------------------------===// 1201// TOSA Spec Section 2.8 1202// Operator Class: Reduction Ops. 1203//===----------------------------------------------------------------------===// 1204 1205//===----------------------------------------------------------------------===// 1206// Operator: reduce_all 1207//===----------------------------------------------------------------------===// 1208def Tosa_ReduceAllOp : Tosa_Op<"reduce_all", [ 1209 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1210 ["inferReturnTypeComponents"]>, 1211 NoSideEffect]> { 1212 let summary = "Reduce All operator"; 1213 1214 let description = [{ 1215 Reduce a tensor along the given axis with a logical AND operation 1216 }]; 1217 1218 let arguments = (ins 1219 Tosa_Tensor1Dto4D:$input, 1220 I64Attr:$axis 1221 ); 1222 1223 let results = (outs 1224 Tosa_Tensor1Dto4D:$output 1225 ); 1226 1227 let hasFolder = 1; 1228} 1229 1230//===----------------------------------------------------------------------===// 1231// Operator: reduce_any 1232//===----------------------------------------------------------------------===// 1233def Tosa_ReduceAnyOp : Tosa_Op<"reduce_any", [ 1234 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1235 ["inferReturnTypeComponents"]>, 1236 NoSideEffect]> { 1237 let summary = "Reduce Any operator"; 1238 1239 let description = [{ 1240 Reduce a tensor along the given axis with a logical OR operation 1241 }]; 1242 1243 let arguments = (ins 1244 Tosa_Tensor1Dto4D:$input, 1245 I64Attr:$axis 1246 ); 1247 1248 let results = (outs 1249 Tosa_Tensor1Dto4D:$output 1250 ); 1251 1252 let hasFolder = 1; 1253} 1254 1255//===----------------------------------------------------------------------===// 1256// Operator: reduce_max 1257//===----------------------------------------------------------------------===// 1258def Tosa_ReduceMaxOp : Tosa_Op<"reduce_max", [ 1259 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1260 ["inferReturnTypeComponents"]>, 1261 NoSideEffect]> { 1262 let summary = "Reduce Max operator"; 1263 1264 let description = [{ 1265 Reduce a tensor along the given axis with a maximum operation 1266 }]; 1267 1268 let arguments = (ins 1269 Tosa_Tensor1Dto4D:$input, 1270 I64Attr:$axis 1271 ); 1272 1273 let results = (outs 1274 Tosa_Tensor1Dto4D:$output 1275 ); 1276 1277 let hasFolder = 1; 1278} 1279 1280//===----------------------------------------------------------------------===// 1281// Operator: reduce_min 1282//===----------------------------------------------------------------------===// 1283def Tosa_ReduceMinOp : Tosa_Op<"reduce_min", [ 1284 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1285 ["inferReturnTypeComponents"]>, 1286 NoSideEffect]> { 1287 let summary = "Reduce Min operator"; 1288 1289 let description = [{ 1290 Reduce a tensor along the given axis with a minimum operation 1291 }]; 1292 1293 let arguments = (ins 1294 Tosa_Tensor1Dto4D:$input, 1295 I64Attr:$axis 1296 ); 1297 1298 let results = (outs 1299 Tosa_Tensor1Dto4D:$output 1300 ); 1301 1302 let hasFolder = 1; 1303} 1304 1305//===----------------------------------------------------------------------===// 1306// Operator: reduce_prod 1307//===----------------------------------------------------------------------===// 1308def Tosa_ReduceProdOp : Tosa_Op<"reduce_prod", [ 1309 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1310 ["inferReturnTypeComponents"]>, 1311 NoSideEffect]> { 1312 let summary = "Reduce Prod operator"; 1313 1314 let description = [{ 1315 Reduce a tensor along the given axis by computing the product of the axis. 1316 }]; 1317 1318 let arguments = (ins 1319 Tosa_Tensor1Dto4D:$input, 1320 I64Attr:$axis 1321 ); 1322 1323 let results = (outs 1324 Tosa_Tensor1Dto4D:$output 1325 ); 1326 1327 let hasFolder = 1; 1328} 1329 1330//===----------------------------------------------------------------------===// 1331// Operator: reduce_sum 1332//===----------------------------------------------------------------------===// 1333def Tosa_ReduceSumOp : Tosa_Op<"reduce_sum", [ 1334 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1335 ["inferReturnTypeComponents"]>, 1336 NoSideEffect]> { 1337 let summary = "Reduce Sum operator"; 1338 1339 let description = [{ 1340 Reduce a tensor along the given axis by computing the sum of the axis. 1341 }]; 1342 1343 let arguments = (ins 1344 Tosa_Tensor1Dto4D:$input, 1345 I64Attr:$axis 1346 ); 1347 1348 let results = (outs 1349 Tosa_Tensor1Dto4D:$output 1350 ); 1351 1352 let hasFolder = 1; 1353} 1354 1355//===----------------------------------------------------------------------===// 1356// TOSA Spec Section 2.9 1357// Operator Class: Data Layout / Memory Reinterpretation. 1358//===----------------------------------------------------------------------===// 1359 1360//===----------------------------------------------------------------------===// 1361// Operator: concat 1362//===----------------------------------------------------------------------===// 1363def Tosa_ConcatOp : Tosa_Op<"concat", [ 1364 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1365 ["inferReturnTypeComponents"]>, 1366 NoSideEffect]> { 1367 let summary = "Concatenates tensors along one dimension."; 1368 1369 let description = [{ 1370 Concatenate a variadic amount of tensors along a given axis. No data 1371 conversion happens during a concat operation. 1372 }]; 1373 1374 let arguments = (ins 1375 Variadic<Tosa_Tensor>:$input1, 1376 I64Attr:$axis 1377 ); 1378 1379 let results = (outs 1380 Tosa_Tensor:$output 1381 ); 1382 1383 let hasCanonicalizer = 1; 1384} 1385 1386//===----------------------------------------------------------------------===// 1387// Operator: pad 1388//===----------------------------------------------------------------------===// 1389def Tosa_PadOp : Tosa_Op<"pad", [ 1390 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1391 ["inferReturnTypeComponents"]>, 1392 NoSideEffect]> { 1393 let summary = "Pads a tensor with zeros."; 1394 1395 let description = [{ 1396 Zero-pads a tensor along borders of each dimension. 1397 }]; 1398 1399 let arguments = (ins 1400 Tosa_RankedTensor:$input1, 1401 Tosa_Int32Or64Tensor:$padding, 1402 OptionalAttr<Tosa_PadOpQuantizationAttr>:$quantization_info 1403 ); 1404 1405 let results = (outs 1406 Tosa_RankedTensor:$output 1407 ); 1408 1409 let builders = [Tosa_PadOpQuantInfoBuilder]; 1410} 1411 1412//===----------------------------------------------------------------------===// 1413// Operator: reshape 1414//===----------------------------------------------------------------------===// 1415def Tosa_ReshapeOp: Tosa_Op<"reshape", [ 1416 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1417 ["inferReturnTypeComponents"]>, 1418 NoSideEffect]> { 1419 let summary = "Reshape operator"; 1420 1421 let description = [{ 1422 Returns a tensor with the same type/values as the input, with a new shape 1423 specified by the shape argument. Reshape may operate on tensors of any rank. 1424 No data conversion happens during a reshape operation. 1425 }]; 1426 1427 let hasCanonicalizer = 1; 1428 let hasFolder = 1; 1429 1430 let arguments = (ins 1431 Tosa_Tensor:$input1, 1432 I64ArrayAttr:$new_shape 1433 ); 1434 1435 let results = (outs 1436 Tosa_RankedTensor:$output 1437 ); 1438} 1439 1440//===----------------------------------------------------------------------===// 1441// Operator: reverse 1442//===----------------------------------------------------------------------===// 1443def Tosa_ReverseOp: Tosa_Op<"reverse", [ 1444 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1445 ["inferReturnTypeComponents"]>, NoSideEffect]> { 1446 let summary = "Reverse operator"; 1447 1448 let description = [{ 1449 Returns a tensor with the same type/values as the input, with the data 1450 reversed along the given axis. No data conversion happens during a reverse 1451 operation. 1452 }]; 1453 1454 let arguments = (ins 1455 Tosa_Tensor1Dto4D:$input, 1456 I64Attr:$axis 1457 ); 1458 1459 let results = (outs 1460 Tosa_Tensor1Dto4D:$output 1461 ); 1462} 1463 1464//===----------------------------------------------------------------------===// 1465// Operator: slice 1466//===----------------------------------------------------------------------===// 1467def Tosa_SliceOp: Tosa_Op<"slice", [ 1468 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1469 ["inferReturnTypeComponents"]>, NoSideEffect]> { 1470 let summary = "Slice operator"; 1471 1472 let description = [{ 1473 Extracts a slice of the input1 on the given axis, beginning at the 1474 start coordinates, and extending for size elements in each direction. No 1475 data conversion happens during a slice operation. 1476 }]; 1477 1478 let arguments = (ins 1479 Tosa_Tensor1Dto6D:$input, 1480 I64ArrayAttr:$start, 1481 I64ArrayAttr:$size 1482 ); 1483 1484 let results = (outs 1485 Tosa_Tensor1Dto6D:$output 1486 ); 1487 1488 let hasFolder = 1; 1489} 1490 1491//===----------------------------------------------------------------------===// 1492// Operator: tile 1493//===----------------------------------------------------------------------===// 1494def Tosa_TileOp: Tosa_Op<"tile", [ 1495 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1496 ["inferReturnTypeComponents"]>, 1497 NoSideEffect]> { 1498 let summary = "Tile operator"; 1499 1500 let description = [{ 1501 Replicates input 0 multiplies times along each dimension. 1502 }]; 1503 1504 let arguments = (ins 1505 Tosa_Tensor1Dto4D:$input1, 1506 I64ArrayAttr:$multiples); 1507 1508 let results = (outs 1509 Tosa_Tensor1Dto4D:$output 1510 ); 1511 1512 let hasFolder = 1; 1513} 1514 1515//===----------------------------------------------------------------------===// 1516// Operator: transpose 1517//===----------------------------------------------------------------------===// 1518def Tosa_TransposeOp : Tosa_Op<"transpose", [ 1519 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1520 ["inferReturnTypeComponents"]>, 1521 NoSideEffect]> { 1522 let summary = "Transpose operator"; 1523 1524 let description = [{ 1525 Permutes the dimensions based on perm. 1526 }]; 1527 1528 let arguments = (ins 1529 Tosa_Tensor1Dto6D:$input1, 1530 Tosa_Int32Or64Tensor:$perms 1531 ); 1532 1533 let results = ( 1534 outs Tosa_Tensor1Dto6D:$output 1535 ); 1536 1537 let hasCanonicalizer = 1; 1538 let hasFolder = 1; 1539} 1540 1541//===----------------------------------------------------------------------===// 1542// TOSA Spec Section 2.10 1543// Operator Class: Scatter/gather Operations. 1544//===----------------------------------------------------------------------===// 1545 1546//===----------------------------------------------------------------------===// 1547// Operator: gather 1548//===----------------------------------------------------------------------===// 1549def Tosa_GatherOp : Tosa_Op<"gather", [ 1550 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1551 ["inferReturnTypeComponents"]>, 1552 NoSideEffect]> { 1553 let summary = "Gather operation,"; 1554 1555 let description = [{ 1556 Generate a tensor for which each element in the output is a slice of the 1557 values tensor based on the value of indices. 1558 }]; 1559 1560 let arguments = (ins 1561 Tosa_Tensor3D:$values, 1562 2DTensorOf<[Tosa_Int32]>:$indices 1563 ); 1564 1565 let results = (outs 1566 Tosa_Tensor3D:$output 1567 ); 1568} 1569 1570//===----------------------------------------------------------------------===// 1571// Operator: scatter 1572//===----------------------------------------------------------------------===// 1573def Tosa_ScatterOp : Tosa_Op<"scatter", [ 1574 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1575 ["inferReturnTypeComponents"]>, 1576 NoSideEffect]> { 1577 let summary = "Scatter operation,"; 1578 1579 let description = [{ 1580 The values_out tensor is set to the values_in tensor with data modified as follows: 1581 data from the input tensor is inserted at the positions specified by the indices tensor. 1582 }]; 1583 1584 let arguments = (ins 1585 Tosa_Tensor3D:$values_in, 1586 2DTensorOf<[Tosa_Int32]>:$indices, 1587 Tosa_Tensor3D:$input 1588 ); 1589 1590 let results = (outs 1591 Tosa_Tensor3D:$values_out 1592 ); 1593} 1594 1595//===----------------------------------------------------------------------===// 1596// TOSA Spec Section 2.11 1597// Operator Class: Image Frontend Functions. 1598//===----------------------------------------------------------------------===// 1599 1600//===----------------------------------------------------------------------===// 1601// Operator: resize 1602//===----------------------------------------------------------------------===// 1603def Tosa_ResizeOp : Tosa_Op<"resize", [ 1604 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1605 ["inferReturnTypeComponents"]>, 1606 NoSideEffect]> { 1607 1608 let summary = "Resize operation, supports various resize/upsample modes"; 1609 1610 let description = [{ 1611 Resizes a tensor. Resize is only allowed in the H and W dimensions. In 1612 expected use, stride_y is approximately (IH<<shift)/OH and stride_x is 1613 approximately (IW<<shift)/OW. OH and OW are also supplied as inputs since 1614 there may be off by one errors if calculating OH and OW from the strides. 1615 }]; 1616 1617 let arguments = (ins 1618 Tosa_Tensor4D:$input, 1619 Tosa_IntArrayAttr2:$output_size, 1620 Tosa_IntArrayAttr2:$stride, 1621 Tosa_IntArrayAttr2:$offset, 1622 I32Attr:$shift, 1623 Tosa_Fp32ArrayAttr2:$stride_fp, 1624 Tosa_Fp32ArrayAttr2:$offset_fp, 1625 Tosa_ResizeTypeAttr:$mode 1626 ); 1627 1628 let results = (outs 1629 Tosa_Tensor4D:$output 1630 ); 1631} 1632 1633//===----------------------------------------------------------------------===// 1634// TOSA Spec Section 2.12 1635// Operator Class: Type Conversion. 1636//===----------------------------------------------------------------------===// 1637 1638//===----------------------------------------------------------------------===// 1639// Operator: cast 1640//===----------------------------------------------------------------------===// 1641def Tosa_CastOp: Tosa_Op<"cast", [NoSideEffect, 1642 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1643 ["inferReturnTypeComponents"]>]> { 1644 1645 let summary = "Cast operation"; 1646 1647 let description = [{ 1648 Performs a set of permissible cast operations 1649 Mode Input Output 1650 --------------------------------------- 1651 signed 8 to bool int8 Boolean 1652 signed 16 to bool int16 Boolean 1653 signed 32 to bool int32 Boolean 1654 bool to 8 Boolean int8 1655 bool to 16 Boolean int16 1656 bool to 32 Boolean int32 1657 signed 8 to signed 16 int8 int16 1658 signed 8 to signed 32 int8 int32 1659 signed 16 to signed 8 int16 int8 1660 signed 16 to signed 32 int16 int32 1661 signed 32 to signed 8 int32 int8 1662 signed 32 to signed 16 int32 int16 1663 float to signed 8 float int8 1664 float to signed 16 float int16 1665 signed 8 to float int8 float 1666 signed 16 to float int16 float 1667 }]; 1668 1669 let arguments = (ins 1670 Tosa_Tensor:$input 1671 ); 1672 1673 let results = (outs 1674 Tosa_Tensor:$output 1675 ); 1676 1677 let hasFolder = 1; 1678} 1679 1680//===----------------------------------------------------------------------===// 1681// Operator: rescale 1682//===----------------------------------------------------------------------===// 1683def Tosa_RescaleOp: Tosa_Op<"rescale", [NoSideEffect, 1684 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1685 ["inferReturnTypeComponents"]>]> { 1686 let summary = "Tosa rescale operator"; 1687 1688 let description = [{ 1689 Rescale quantized values into a new domain. Supported rescalings are: 1690 Mode Input Output 1691 signed 8 to 8 int8 int8 1692 signed 8 to 16 int8 int16 1693 signed 8 to 32 int8 int32 1694 signed 16 to 8 int16 int8 1695 signed 16 to 16 int16 int16 1696 signed 16 to 32 int16 int32 1697 signed 32 to 8 int32 int8 1698 signed 32 to 16 int32 int16 1699 signed 32 to 32 int32 int32 1700 signed 48 to 8 int48 int8 1701 signed 48 to 16 int48 int16 1702 signed 48 to 32 int48 int32 1703 unsigned 8 to signed 8 uint8 int8 1704 signed 8 to unsigned 8 int8 uint8 1705 }]; 1706 1707 let arguments = (ins 1708 Tosa_Tensor:$input, 1709 I32Attr:$input_zp, 1710 I32Attr:$output_zp, 1711 I32ArrayAttr:$multiplier, 1712 I32ArrayAttr:$shift, 1713 BoolAttr:$scale32, 1714 BoolAttr:$double_round, 1715 BoolAttr:$per_channel 1716 ); 1717 1718 let results = (outs 1719 Tosa_Tensor:$output 1720 ); 1721} 1722 1723//===----------------------------------------------------------------------===// 1724// TOSA Spec Section 2.13 1725// Operator Class: Data Node Ops. 1726//===----------------------------------------------------------------------===// 1727 1728//===----------------------------------------------------------------------===// 1729// Operator: const 1730//===----------------------------------------------------------------------===// 1731def Tosa_ConstOp : Tosa_Op<"const", [ConstantLike, NoSideEffect, 1732 FirstAttrDerivedResultType]> { 1733 let summary = "Constant op."; 1734 1735 let description = [{ 1736 A node containing constant data for use as the input to an operation. May 1737 hold data in any of the supported data formats. 1738 }]; 1739 1740 let arguments = (ins 1741 ElementsAttr:$value 1742 ); 1743 1744 let results = (outs 1745 Tosa_Tensor:$output 1746 ); 1747 let hasFolder = 1; 1748} 1749 1750//===----------------------------------------------------------------------===// 1751// Operator: identity 1752//===----------------------------------------------------------------------===// 1753def Tosa_IdentityOp: Tosa_Op<"identity", [NoSideEffect, 1754 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1755 ["inferReturnTypeComponents"]>]> { 1756 let summary = "Identity operator"; 1757 let description = [{ 1758 Returns a tensor with the same shape, size, type 1759 and content as the input. 1760 }]; 1761 1762 let arguments = (ins 1763 Tosa_Tensor:$input1 1764 ); 1765 1766 let results = (outs 1767 Tosa_Tensor:$output 1768 ); 1769} 1770 1771//===----------------------------------------------------------------------===// 1772// TOSA Spec Section 2.14 1773// Operator Class: Custom Operators. 1774//===----------------------------------------------------------------------===// 1775 1776//===----------------------------------------------------------------------===// 1777// Operator: custom 1778//===----------------------------------------------------------------------===// 1779def Tosa_CustomOp : Tosa_Op<"custom"> { 1780 1781 let summary = "Custom operator wrapper for Tosa"; 1782 1783 let description = [{ 1784 Hardware implementing TOSA may choose to add additional custom operators 1785 that are not expressed in the existing TOSA operations. These operators are 1786 not expected to be portable across TOSA implementations. The input and 1787 output signatures must be expressed in the corresponding TOSA node. 1788 }]; 1789 1790 let arguments = (ins 1791 StrAttr:$identifier, 1792 Variadic<Tosa_Tensor>:$inputs 1793 ); 1794 1795 let results = (outs 1796 Variadic<Tosa_Tensor>:$outputs 1797 ); 1798} 1799 1800//===----------------------------------------------------------------------===// 1801// TOSA Spec Section 2.15 1802// Operator Class: Control Flow Operators. 1803//===----------------------------------------------------------------------===// 1804 1805//===----------------------------------------------------------------------===// 1806// Operator: cond_if 1807//===----------------------------------------------------------------------===// 1808//===----------------------------------------------------------------------===// 1809// Further described in docs/Rationale/RationaleTOSADialect.md . 1810//===----------------------------------------------------------------------===// 1811def Tosa_IfOp : Tosa_Op<"cond_if", [ 1812 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1813 ["inferReturnTypeComponents"]>, 1814 SingleBlockImplicitTerminator<"YieldOp">, 1815 RecursiveSideEffects]> { 1816 let summary = "Conditional if operator"; 1817 1818 let description = [{ 1819 Evaluates a Boolean condition and then takes one of two distinct execution 1820 paths. This implements the semantic If-then-else structure. 1821 }]; 1822 1823 let arguments = (ins 1824 I1Tensor:$cond, 1825 Variadic<Tosa_Tensor>:$inputs 1826 ); 1827 1828 let results = (outs 1829 Variadic<Tosa_Tensor>:$output 1830 ); 1831 1832 let regions = (region 1833 SizedRegion<1>:$then_branch, 1834 SizedRegion<1>:$else_branch 1835 ); 1836} 1837 1838//===----------------------------------------------------------------------===// 1839// Operator: while_loop 1840//===----------------------------------------------------------------------===// 1841//===----------------------------------------------------------------------===// 1842// Further described in docs/Rationale/RationaleTOSADialect.md . 1843//===----------------------------------------------------------------------===// 1844def Tosa_WhileOp : Tosa_Op<"while_loop", [ 1845 DeclareOpInterfaceMethods<LoopLikeOpInterface>, 1846 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1847 ["inferReturnTypeComponents"]>, 1848 SingleBlockImplicitTerminator<"YieldOp">, 1849 RecursiveSideEffects]> { 1850 let summary = "output = input; While (Cond(output)) {output = Body(output)}"; 1851 1852 let description = [{ 1853 Generates and evaluates a Bool condition and either executes a loop body or 1854 exits to another control point. This action is performed repeatedly after 1855 updating and re-evaluating the Boolean condition every iteration. This 1856 implements the semantic foreach or while iterative loop structure. 1857 }]; 1858 1859 let arguments = (ins 1860 Variadic<Tosa_Tensor>:$inputs 1861 ); 1862 1863 let results = (outs 1864 Variadic<Tosa_Tensor>:$output 1865 ); 1866 1867 let regions = (region 1868 SizedRegion<1>:$cond, 1869 SizedRegion<1>:$body 1870 ); 1871} 1872 1873include "mlir/Dialect/Tosa/IR/TosaUtilOps.td" 1874 1875#endif // TOSA_OPS 1876