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. Rank of input tensors must match. 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. Rank of input 457 tensors must match. 458 }]; 459 460 let arguments = (ins 461 Tosa_Tensor:$input1, 462 Tosa_Tensor:$input2, 463 BoolAttr:$round 464 ); 465 466 let results = (outs 467 Tosa_Tensor:$output 468 ); 469} 470 471//===----------------------------------------------------------------------===// 472// Operator: bitwise_and 473//===----------------------------------------------------------------------===// 474def Tosa_BitwiseAndOp : Tosa_Op<"bitwise_and", [ 475 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 476 ["inferReturnTypeComponents"]>, 477 ResultsBroadcastableShape, NoSideEffect, Commutative]> { 478 let summary = "Bitwise AND operator"; 479 480 let description = [{ 481 Elementwise bitwise AND of input1 and input2. Axis of size 1 482 will be broadcast as necessary. Rank of input tensors must match. 483 }]; 484 485 let arguments = (ins 486 Tosa_Tensor:$input1, 487 Tosa_Tensor:$input2 488 ); 489 490 let results = (outs 491 Tosa_Tensor:$output 492 ); 493} 494 495//===----------------------------------------------------------------------===// 496// Operator: bitwise_or 497//===----------------------------------------------------------------------===// 498def Tosa_BitwiseOrOp : Tosa_Op<"bitwise_or", [ 499 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 500 ["inferReturnTypeComponents"]>, 501 ResultsBroadcastableShape, NoSideEffect, Commutative]> { 502 let summary = "Bitwise OR operator"; 503 504 let description = [{ 505 Elementwise bitwise OR of input1 and input2. Axis of size 1 will be 506 broadcast as necessary. Rank of input tensors must match. 507 }]; 508 509 let arguments = (ins 510 Tosa_Tensor:$input1, 511 Tosa_Tensor:$input2 512 ); 513 514 let results = (outs 515 Tosa_Tensor:$output 516 ); 517} 518 519//===----------------------------------------------------------------------===// 520// Operator: bitwise_xor 521//===----------------------------------------------------------------------===// 522def Tosa_BitwiseXorOp : Tosa_Op<"bitwise_xor", [ 523 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 524 ["inferReturnTypeComponents"]>, 525 ResultsBroadcastableShape, NoSideEffect, Commutative]> { 526 let summary = "Bitwise XOR operator"; 527 528 let description = [{ 529 Elementwise bitwise XOR of input1 and input2. Axis of size 1 will be 530 broadcast as necessary. Rank of input tensors must match. 531 }]; 532 533 let arguments = (ins 534 Tosa_Tensor:$input1, 535 Tosa_Tensor:$input2 536 ); 537 538 let results = (outs 539 Tosa_Tensor:$output 540 ); 541} 542 543//===----------------------------------------------------------------------===// 544// Operator: div 545//===----------------------------------------------------------------------===// 546def Tosa_DivOp : Tosa_Op<"div", [ 547 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 548 ["inferReturnTypeComponents"]>, 549 ResultsBroadcastableShape, NoSideEffect]> { 550 let summary = "Integer divide operator"; 551 552 let description = [{ 553 Elementwise integer divide operator of input1 by input2. Axis of size 1 554 will be broadcast, as necessary. Rank of input tensors must match. 555 }]; 556 557 let arguments = (ins 558 Tosa_Int32Tensor:$input1, 559 Tosa_Int32Tensor:$input2 560 ); 561 562 let results = (outs 563 Tosa_Int32Tensor:$output 564 ); 565} 566 567//===----------------------------------------------------------------------===// 568// Operator: logical_and 569//===----------------------------------------------------------------------===// 570def Tosa_LogicalAndOp : Tosa_Op<"logical_and", [ 571 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 572 ["inferReturnTypeComponents"]>, 573 ResultsBroadcastableShape, Commutative, NoSideEffect]> { 574 let summary = "Returns the truth value of x AND y element-wise."; 575 576 let description = [{ 577 Elementwise logical AND of input1 and input2. Axis of size 1 will be 578 broadcast, as necessary. Rank of input tensors must match. 579 }]; 580 581 let arguments = (ins 582 I1Tensor:$input1, 583 I1Tensor:$input2 584 ); 585 586 let results = (outs 587 I1Tensor:$z 588 ); 589} 590 591//===----------------------------------------------------------------------===// 592// Operator: logical_left_shift 593//===----------------------------------------------------------------------===// 594def Tosa_LogicalLeftShiftOp : Tosa_Op<"logical_left_shift", [ 595 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 596 ["inferReturnTypeComponents"]>, 597 ResultsBroadcastableShape, NoSideEffect]> { 598 let summary = "Elementwise Logical Left Shift"; 599 600 let description = [{ 601 Elementwise left shift of input1 and input2. Axis of size 1 will be 602 broadcast, as necessary. Rank of input tensors must match. 603 }]; 604 605 let arguments = (ins 606 Tosa_Tensor:$input1, 607 Tosa_Tensor:$input2 608 ); 609 610 let results = (outs 611 Tosa_Tensor:$output 612 ); 613} 614 615//===----------------------------------------------------------------------===// 616// Operator: logical_right_shift 617//===----------------------------------------------------------------------===// 618def Tosa_LogicalRightShiftOp : Tosa_Op<"logical_right_shift", [ 619 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 620 ["inferReturnTypeComponents"]>, 621 ResultsBroadcastableShape, NoSideEffect]> { 622 let summary = "Elementwise Logical Right Shift"; 623 624 let description = [{ 625 Elementwise logical right shift of input1 by the amount specified in input2. 626 Axis of size 1 will be broadcast, as necessary. 627 Rank of input tensors must match. 628 }]; 629 630 let arguments = (ins 631 Tosa_Tensor:$input1, 632 Tosa_Tensor:$input2 633 ); 634 635 let results = (outs 636 Tosa_Tensor:$output 637 ); 638} 639 640//===----------------------------------------------------------------------===// 641// Operator: logical_or 642//===----------------------------------------------------------------------===// 643def Tosa_LogicalOrOp : Tosa_Op<"logical_or", [ 644 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 645 ["inferReturnTypeComponents"]>, 646 ResultsBroadcastableShape, Commutative, NoSideEffect]> { 647 let summary = "Returns the truth value of x OR y element-wise."; 648 649 let description = [{ 650 Elementwise logical OR of input1 and input2. Axis of size 1 will be 651 broadcast as necessary. Rank of input tensors must match. 652 }]; 653 654 let arguments = (ins 655 I1Tensor:$input1, 656 I1Tensor:$input2 657 ); 658 659 let results = (outs 660 I1Tensor:$z 661 ); 662} 663 664//===----------------------------------------------------------------------===// 665// Operator: logical_xor 666//===----------------------------------------------------------------------===// 667def Tosa_LogicalXorOp : Tosa_Op<"logical_xor", [ 668 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 669 ["inferReturnTypeComponents"]>, 670 ResultsBroadcastableShape, Commutative, NoSideEffect]> { 671 let summary = "Returns the truth value of x XOR y element-wise."; 672 673 let description = [{ 674 Elementwise logical XOR of input1 and input2. Axis of size 1 will be 675 broadcast as necessary. Rank of input tensors must match. 676 }]; 677 678 let arguments = (ins 679 I1Tensor:$input1, 680 I1Tensor:$input2 681 ); 682 683 let results = (outs 684 I1Tensor:$z 685 ); 686} 687 688//===----------------------------------------------------------------------===// 689// Operator: maximum 690//===----------------------------------------------------------------------===// 691def Tosa_MaximumOp : Tosa_Op<"maximum", [ 692 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 693 ["inferReturnTypeComponents"]>, 694 ResultsBroadcastableShape, NoSideEffect, Commutative]> { 695 let summary = "Elementwise Maximum"; 696 697 let description = [{ 698 Elementwise max of input1 and input2. Axis of size 1 will be broadcast, as 699 necessary. Rank of input tensors must match. 700 }]; 701 702 let arguments = (ins 703 Tosa_Tensor:$input1, 704 Tosa_Tensor:$input2 705 ); 706 707 let results = (outs 708 Tosa_Tensor:$output 709 ); 710} 711 712//===----------------------------------------------------------------------===// 713// Operator: minimum 714//===----------------------------------------------------------------------===// 715def Tosa_MinimumOp : Tosa_Op<"minimum", [ 716 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 717 ["inferReturnTypeComponents"]>, 718 ResultsBroadcastableShape, NoSideEffect, Commutative]> { 719 let summary = "Elementwise Minimum"; 720 721 let description = [{ 722 Elementwise minimum of input1 and input2. Axis of size 1 723 will be broadcast, as necessary. Rank of input tensors must match. 724 }]; 725 726 let arguments = (ins 727 Tosa_Tensor:$input1, 728 Tosa_Tensor:$input2 729 ); 730 731 let results = (outs 732 Tosa_Tensor:$output 733 ); 734} 735 736//===----------------------------------------------------------------------===// 737// Operator: mul 738//===----------------------------------------------------------------------===// 739def Tosa_MulOp : Tosa_Op<"mul", [ 740 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 741 ["inferReturnTypeComponents"]>, 742 ResultsBroadcastableShape, NoSideEffect, Commutative]> { 743 let summary = "Multiplication operator"; 744 745 let description = [{ 746 Elementwise multiplication (Hadamard product) of input1 and input2. 747 Axis of size 1 will be broadcast, as necessary. 748 Rank of input tensors must match. 749 }]; 750 751 let arguments = (ins 752 Tosa_Tensor:$input1, 753 Tosa_Tensor:$input2, 754 I32Attr:$shift 755 ); 756 757 let results = (outs 758 Tosa_Tensor:$output 759 ); 760} 761 762//===----------------------------------------------------------------------===// 763// Operator: pow 764//===----------------------------------------------------------------------===// 765def Tosa_PowOp : Tosa_Op<"pow", [ 766 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 767 ["inferReturnTypeComponents"]>, 768 ResultsBroadcastableShape, NoSideEffect]> { 769 let summary = "Computes the power of one value to another."; 770 771 let description = [{ 772 Elementwise input1 raised to the power of input2. 773 Axis of size 1 will be broadcast, as necessary. 774 Rank of input tensors must match. 775 }]; 776 777 let arguments = (ins 778 Tosa_Tensor:$input1, 779 Tosa_Tensor:$input2 780 ); 781 782 let results = (outs 783 Tosa_Tensor:$z 784 ); 785} 786 787//===----------------------------------------------------------------------===// 788// Operator: sub 789//===----------------------------------------------------------------------===// 790def Tosa_SubOp : Tosa_Op<"sub", [ 791 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 792 ["inferReturnTypeComponents"]>, 793 ResultsBroadcastableShape, NoSideEffect]> { 794 let summary = "Elementwise subtraction operator"; 795 796 let description = [{ 797 Elementwise subtraction of input1 and input2. Axis of size 1 will be 798 broadcast as necessary. Rank of input tensors must match. 799 }]; 800 801 let arguments = (ins 802 Tosa_Tensor:$input1, 803 Tosa_Tensor:$input2 804 ); 805 806 let results = (outs 807 Tosa_Tensor:$output 808 ); 809} 810 811//===----------------------------------------------------------------------===// 812// Operator: table 813//===----------------------------------------------------------------------===// 814def Tosa_TableOp : Tosa_Op<"table", [ 815 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 816 ["inferReturnTypeComponents"]>, 817 NoSideEffect]> { 818 let summary = "Table lookup op"; 819 820 let description = [{ 821 Interpolated table lookup operation. Input values are scaled to create a 822 fixed-point 9.7 value. The high 9 bits are used to index into the table. 823 The fractional bits are used to interpolate based on the looked up value and 824 the index+1 value in the table. The TABLE operator then returns a 16.7 825 interpolated value. Note that there must be 513 values to handle the full 826 range of inputs. 827 828 The TABLE operator is expected to be used as follows: 829 * A RESCALE node is expected before the TABLE operator to scale the input 830 to a full int16_t range for the table lookup 831 * If an int16_t result is required then follow the TABLE operator with a 832 RESCALE with a right shift of 7 833 * If an int8_t result is required then follow the TABLE operator with a 834 RESCALE with a right shift of 15 835 }]; 836 837 let arguments = (ins 838 Tosa_Tensor: $input, 839 Tosa_Tensor1D: $table 840 ); 841 842 let results = (outs 843 Tosa_Tensor:$output 844 ); 845 846} 847 848//===----------------------------------------------------------------------===// 849// TOSA Spec Section 2.5 850// Operator Class: Elementwise unary/binary/ternary operators. 851// Operator Subclass: Elementwise unary ops. 852//===----------------------------------------------------------------------===// 853 854//===----------------------------------------------------------------------===// 855// Operator: abs 856//===----------------------------------------------------------------------===// 857def Tosa_AbsOp : Tosa_Op<"abs", [ 858 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 859 ["inferReturnTypeComponents"]>, 860 NoSideEffect]> { 861 let summary = "Elementwise abs op"; 862 863 let description = [{ 864 Elementwise absolute value operation 865 }]; 866 867 let arguments = (ins 868 Tosa_Tensor:$input1 869 ); 870 871 let results = (outs 872 Tosa_Tensor:$output 873 ); 874} 875 876//===----------------------------------------------------------------------===// 877// Operator: bitwise_not 878//===----------------------------------------------------------------------===// 879def Tosa_BitwiseNotOp : Tosa_Op<"bitwise_not", [ 880 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 881 ["inferReturnTypeComponents"]>, 882 ResultsBroadcastableShape, NoSideEffect]> { 883 let summary = "Bitwise NOT operator"; 884 885 let description = [{ 886 Elementwise bitwise NOT of input tensor. 887 }]; 888 889 let arguments = (ins 890 Tosa_Tensor:$input1 891 ); 892 893 let results = (outs 894 Tosa_Tensor:$output 895 ); 896} 897 898//===----------------------------------------------------------------------===// 899// Operator: ceil 900//===----------------------------------------------------------------------===// 901def Tosa_CeilOp : Tosa_Op<"ceil", [ 902 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 903 ["inferReturnTypeComponents"]>, 904 NoSideEffect]> { 905 let summary = "Elementwise ceil op"; 906 907 let description = [{ 908 Elementwise ceiling operation 909 }]; 910 911 let arguments = (ins 912 Tosa_Tensor:$input1 913 ); 914 915 let results = (outs 916 Tosa_Tensor:$output 917 ); 918} 919 920//===----------------------------------------------------------------------===// 921// Operator: clz 922//===----------------------------------------------------------------------===// 923def Tosa_ClzOp : Tosa_Op<"clz", [ 924 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 925 ["inferReturnTypeComponents"]>, 926 NoSideEffect]> { 927 let summary = "Elementwise count leading zero op"; 928 929 let description = [{ 930 Elementwise count leading zeros operation 931 }]; 932 933 let arguments = (ins 934 Tosa_Tensor:$input1 935 ); 936 937 let results = (outs 938 Tosa_Tensor:$output 939 ); 940} 941 942//===----------------------------------------------------------------------===// 943// Operator: exp 944//===----------------------------------------------------------------------===// 945def Tosa_ExpOp : Tosa_Op<"exp", [ 946 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 947 ["inferReturnTypeComponents"]>, 948 NoSideEffect]> { 949 let summary = "Elementwise exp op"; 950 951 let description = [{ 952 Elementwise e to the x operation 953 }]; 954 955 let arguments = (ins 956 Tosa_Tensor:$input1 957 ); 958 959 let results = (outs 960 Tosa_Tensor:$output 961 ); 962} 963 964//===----------------------------------------------------------------------===// 965// Operator: floor 966//===----------------------------------------------------------------------===// 967def Tosa_FloorOp : Tosa_Op<"floor", [ 968 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 969 ["inferReturnTypeComponents"]>, 970 NoSideEffect]> { 971 let summary = "Elementwise floor op"; 972 973 let description = [{ 974 Elementwise floor operation 975 }]; 976 977 let arguments = (ins 978 Tosa_Tensor:$input1 979 ); 980 981 let results = (outs 982 Tosa_Tensor:$output 983 ); 984} 985 986//===----------------------------------------------------------------------===// 987// Operator: log 988//===----------------------------------------------------------------------===// 989def Tosa_LogOp : Tosa_Op<"log", [ 990 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 991 ["inferReturnTypeComponents"]>, 992 NoSideEffect]> { 993 let summary = "Elementwise log op"; 994 995 let description = [{ 996 Elementwise natural logarithm operation 997 }]; 998 999 let arguments = (ins 1000 Tosa_Tensor:$input1 1001 ); 1002 1003 let results = (outs 1004 Tosa_Tensor:$output 1005 ); 1006} 1007 1008//===----------------------------------------------------------------------===// 1009// Operator: logical_not 1010//===----------------------------------------------------------------------===// 1011def Tosa_LogicalNotOp : Tosa_Op<"logical_not", [ 1012 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1013 ["inferReturnTypeComponents"]>, 1014 NoSideEffect]> { 1015 let summary = "Returns the truth value of NOT x element-wise."; 1016 1017 let description = [{ 1018 Elementwise logical NOT of input. 1019 }]; 1020 1021 let arguments = (ins 1022 I1Tensor:$input1 1023 ); 1024 1025 let results = (outs 1026 I1Tensor:$output 1027 ); 1028} 1029 1030//===----------------------------------------------------------------------===// 1031// Operator: negate 1032//===----------------------------------------------------------------------===// 1033def Tosa_NegateOp : Tosa_Op<"negate", [ 1034 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1035 ["inferReturnTypeComponents"]>, 1036 NoSideEffect]> { 1037 let summary = "Elementwise negate op"; 1038 1039 let description = [{ 1040 Elementwise negation operation 1041 }]; 1042 1043 let arguments = (ins 1044 Tosa_Tensor:$input1, 1045 OptionalAttr<Tosa_UnaryOpQuantizationAttr>:$quantization_info 1046 ); 1047 1048 let results = (outs 1049 Tosa_Tensor:$output 1050 ); 1051 1052 let builders = [Tosa_UnaryOpQuantInfoBuilder]; 1053} 1054 1055//===----------------------------------------------------------------------===// 1056// Operator: reciprocal 1057//===----------------------------------------------------------------------===// 1058def Tosa_ReciprocalOp : Tosa_Op<"reciprocal", [ 1059 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1060 ["inferReturnTypeComponents"]>, 1061 NoSideEffect]> { 1062 let summary = "Elementwise reciprocal op"; 1063 1064 let description = [{ 1065 Elementwise reciprocal operation. For integer operation, a TABLE should be 1066 used with the appropriate ranges. 1067 }]; 1068 1069 let arguments = (ins 1070 Tosa_Tensor:$input1 1071 ); 1072 1073 let results = (outs 1074 Tosa_Tensor:$output 1075 ); 1076} 1077 1078//===----------------------------------------------------------------------===// 1079// Operator: rsqrt 1080//===----------------------------------------------------------------------===// 1081def Tosa_RsqrtOp : Tosa_Op<"rsqrt", [ 1082 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1083 ["inferReturnTypeComponents"]>, 1084 NoSideEffect]> { 1085 let summary = "Elementwise 1/sqrt op"; 1086 1087 let description = [{ 1088 Elementwise reciprocal square root operation. For integer operation, a TABLE 1089 should be used with the appropriate ranges. 1090 }]; 1091 1092 let arguments = (ins 1093 Tosa_Tensor:$input1 1094 ); 1095 1096 let results = (outs 1097 Tosa_Tensor:$output 1098 ); 1099} 1100 1101//===----------------------------------------------------------------------===// 1102// TOSA Spec Section 2.6 1103// Operator Class: Elementwise unary/binary/ternary operators. 1104// Operator Subclass: Elementwise ternary ops. 1105//===----------------------------------------------------------------------===// 1106 1107//===----------------------------------------------------------------------===// 1108// Operator: select 1109//===----------------------------------------------------------------------===// 1110def Tosa_SelectOp : Tosa_Op<"select", [ 1111 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1112 ["inferReturnTypeComponents"]>, NoSideEffect]> { 1113 let summary = "Elementwise select operator"; 1114 1115 let description = [{ 1116 Elementwise select of the output based on a condition. 1117 }]; 1118 1119 let arguments = (ins 1120 I1Tensor:$input1, 1121 Tosa_Tensor:$input2, 1122 Tosa_Tensor:$input3 1123 ); 1124 1125 let results = (outs 1126 Tosa_Tensor:$output 1127 ); 1128} 1129 1130//===----------------------------------------------------------------------===// 1131// TOSA Spec Section 2.7 1132// Operator Class: Logical Operations. 1133//===----------------------------------------------------------------------===// 1134 1135//===----------------------------------------------------------------------===// 1136// Operator: equal 1137//===----------------------------------------------------------------------===// 1138def Tosa_EqualOp : Tosa_Op<"equal", [ 1139 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1140 ["inferReturnTypeComponents"]>, 1141 ResultsBroadcastableShape, Commutative, NoSideEffect]> { 1142 let summary = "Returns the truth value of (x == y) element-wise."; 1143 1144 let description = [{ 1145 Elementwise comparison operation 1146 }]; 1147 1148 let arguments = (ins 1149 Tosa_Tensor:$input1, 1150 Tosa_Tensor:$input2 1151 ); 1152 1153 let results = (outs 1154 I1Tensor:$output 1155 ); 1156} 1157 1158//===----------------------------------------------------------------------===// 1159// Operator: greater 1160//===----------------------------------------------------------------------===// 1161def Tosa_GreaterOp : Tosa_Op<"greater", [ 1162 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1163 ["inferReturnTypeComponents"]>, 1164 ResultsBroadcastableShape, NoSideEffect]> { 1165 let summary = "Returns the truth value of (x > y) element-wise."; 1166 1167 let description = [{ 1168 Elementwise greater than comparison operation 1169 }]; 1170 1171 let arguments = (ins 1172 Tosa_Tensor:$input1, 1173 Tosa_Tensor:$input2 1174 ); 1175 1176 let results = (outs 1177 I1Tensor:$output 1178 ); 1179} 1180 1181//===----------------------------------------------------------------------===// 1182// Operator: greater_equal 1183//===----------------------------------------------------------------------===// 1184def Tosa_GreaterEqualOp : Tosa_Op<"greater_equal", [ 1185 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1186 ["inferReturnTypeComponents"]>, 1187 ResultsBroadcastableShape, NoSideEffect]> { 1188 let summary = "Returns the truth value of (x >= y) element-wise."; 1189 1190 let description = [{ 1191 Elementwise comparison operation 1192 }]; 1193 1194 let arguments = (ins 1195 Tosa_Tensor:$input1, 1196 Tosa_Tensor:$input2 1197 ); 1198 1199 let results = (outs 1200 I1Tensor:$output 1201 ); 1202} 1203 1204//===----------------------------------------------------------------------===// 1205// TOSA Spec Section 2.8 1206// Operator Class: Reduction Ops. 1207//===----------------------------------------------------------------------===// 1208 1209//===----------------------------------------------------------------------===// 1210// Operator: reduce_all 1211//===----------------------------------------------------------------------===// 1212def Tosa_ReduceAllOp : Tosa_Op<"reduce_all", [ 1213 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1214 ["inferReturnTypeComponents"]>, 1215 NoSideEffect]> { 1216 let summary = "Reduce All operator"; 1217 1218 let description = [{ 1219 Reduce a tensor along the given axis with a logical AND operation 1220 }]; 1221 1222 let arguments = (ins 1223 Tosa_Tensor1Dto4D:$input, 1224 I64Attr:$axis 1225 ); 1226 1227 let results = (outs 1228 Tosa_Tensor1Dto4D:$output 1229 ); 1230} 1231 1232//===----------------------------------------------------------------------===// 1233// Operator: reduce_any 1234//===----------------------------------------------------------------------===// 1235def Tosa_ReduceAnyOp : Tosa_Op<"reduce_any", [ 1236 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1237 ["inferReturnTypeComponents"]>, 1238 NoSideEffect]> { 1239 let summary = "Reduce Any operator"; 1240 1241 let description = [{ 1242 Reduce a tensor along the given axis with a logical OR operation 1243 }]; 1244 1245 let arguments = (ins 1246 Tosa_Tensor1Dto4D:$input, 1247 I64Attr:$axis 1248 ); 1249 1250 let results = (outs 1251 Tosa_Tensor1Dto4D:$output 1252 ); 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 1278//===----------------------------------------------------------------------===// 1279// Operator: reduce_min 1280//===----------------------------------------------------------------------===// 1281def Tosa_ReduceMinOp : Tosa_Op<"reduce_min", [ 1282 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1283 ["inferReturnTypeComponents"]>, 1284 NoSideEffect]> { 1285 let summary = "Reduce Min operator"; 1286 1287 let description = [{ 1288 Reduce a tensor along the given axis with a minimum operation 1289 }]; 1290 1291 let arguments = (ins 1292 Tosa_Tensor1Dto4D:$input, 1293 I64Attr:$axis 1294 ); 1295 1296 let results = (outs 1297 Tosa_Tensor1Dto4D:$output 1298 ); 1299} 1300 1301//===----------------------------------------------------------------------===// 1302// Operator: reduce_prod 1303//===----------------------------------------------------------------------===// 1304def Tosa_ReduceProdOp : Tosa_Op<"reduce_prod", [ 1305 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1306 ["inferReturnTypeComponents"]>, 1307 NoSideEffect]> { 1308 let summary = "Reduce Prod operator"; 1309 1310 let description = [{ 1311 Reduce a tensor along the given axis by computing the product of the axis. 1312 }]; 1313 1314 let arguments = (ins 1315 Tosa_Tensor1Dto4D:$input, 1316 I64Attr:$axis 1317 ); 1318 1319 let results = (outs 1320 Tosa_Tensor1Dto4D:$output 1321 ); 1322} 1323 1324//===----------------------------------------------------------------------===// 1325// Operator: reduce_sum 1326//===----------------------------------------------------------------------===// 1327def Tosa_ReduceSumOp : Tosa_Op<"reduce_sum", [ 1328 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1329 ["inferReturnTypeComponents"]>, 1330 NoSideEffect]> { 1331 let summary = "Reduce Sum operator"; 1332 1333 let description = [{ 1334 Reduce a tensor along the given axis by computing the sum of the axis. 1335 }]; 1336 1337 let arguments = (ins 1338 Tosa_Tensor1Dto4D:$input, 1339 I64Attr:$axis 1340 ); 1341 1342 let results = (outs 1343 Tosa_Tensor1Dto4D:$output 1344 ); 1345} 1346 1347//===----------------------------------------------------------------------===// 1348// TOSA Spec Section 2.9 1349// Operator Class: Data Layout / Memory Reinterpretation. 1350//===----------------------------------------------------------------------===// 1351 1352//===----------------------------------------------------------------------===// 1353// Operator: concat 1354//===----------------------------------------------------------------------===// 1355def Tosa_ConcatOp : Tosa_Op<"concat", [ 1356 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1357 ["inferReturnTypeComponents"]>, 1358 NoSideEffect]> { 1359 let summary = "Concatenates tensors along one dimension."; 1360 1361 let description = [{ 1362 Concatenate a variadic amount of tensors along a given axis. No data 1363 conversion happens during a concat operation. 1364 }]; 1365 1366 let arguments = (ins 1367 Variadic<Tosa_RankedTensor>:$input1, 1368 I64Attr:$axis 1369 ); 1370 1371 let results = (outs 1372 Tosa_RankedTensor:$output 1373 ); 1374} 1375 1376//===----------------------------------------------------------------------===// 1377// Operator: pad 1378//===----------------------------------------------------------------------===// 1379def Tosa_PadOp : Tosa_Op<"pad", [ 1380 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1381 ["inferReturnTypeComponents"]>, 1382 NoSideEffect]> { 1383 let summary = "Pads a tensor with zeros."; 1384 1385 let description = [{ 1386 Zero-pads a tensor along borders of each dimension. 1387 }]; 1388 1389 let arguments = (ins 1390 Tosa_RankedTensor:$input1, 1391 Tosa_Int32Or64Tensor:$padding, 1392 OptionalAttr<Tosa_PadOpQuantizationAttr>:$quantization_info 1393 ); 1394 1395 let results = (outs 1396 Tosa_RankedTensor:$output 1397 ); 1398 1399 let builders = [Tosa_PadOpQuantInfoBuilder]; 1400} 1401 1402//===----------------------------------------------------------------------===// 1403// Operator: reshape 1404//===----------------------------------------------------------------------===// 1405def Tosa_ReshapeOp: Tosa_Op<"reshape", [ 1406 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1407 ["inferReturnTypeComponents"]>, 1408 NoSideEffect]> { 1409 let summary = "Reshape operator"; 1410 1411 let description = [{ 1412 Returns a tensor with the same type/values as the input, with a new shape 1413 specified by the shape argument. Reshape may operate on tensors of any rank. 1414 No data conversion happens during a reshape operation. 1415 }]; 1416 1417 let arguments = (ins 1418 Tosa_Tensor:$input1, 1419 I64ArrayAttr:$new_shape 1420 ); 1421 1422 let results = (outs 1423 Tosa_RankedTensor:$output 1424 ); 1425} 1426 1427//===----------------------------------------------------------------------===// 1428// Operator: reverse 1429//===----------------------------------------------------------------------===// 1430def Tosa_ReverseOp: Tosa_Op<"reverse", [ 1431 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1432 ["inferReturnTypeComponents"]>, NoSideEffect]> { 1433 let summary = "Reverse operator"; 1434 1435 let description = [{ 1436 Returns a tensor with the same type/values as the input, with the data 1437 reversed along the given axis. No data conversion happens during a reverse 1438 operation. 1439 }]; 1440 1441 let arguments = (ins 1442 Tosa_Tensor1Dto4D:$input, 1443 I64Attr:$axis 1444 ); 1445 1446 let results = (outs 1447 Tosa_Tensor1Dto4D:$output 1448 ); 1449} 1450 1451//===----------------------------------------------------------------------===// 1452// Operator: slice 1453//===----------------------------------------------------------------------===// 1454def Tosa_SliceOp: Tosa_Op<"slice", [ 1455 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1456 ["inferReturnTypeComponents"]>, NoSideEffect]> { 1457 let summary = "Slice operator"; 1458 1459 let description = [{ 1460 Extracts a slice of the input1 on the given axis, beginning at the 1461 start coordinates, and extending for size elements in each direction. No 1462 data conversion happens during a slice operation. 1463 }]; 1464 1465 let arguments = (ins 1466 Tosa_Tensor1Dto6D:$input, 1467 I64ArrayAttr:$start, 1468 I64ArrayAttr:$size 1469 ); 1470 1471 let results = (outs 1472 Tosa_Tensor1Dto6D:$output 1473 ); 1474} 1475 1476//===----------------------------------------------------------------------===// 1477// Operator: tile 1478//===----------------------------------------------------------------------===// 1479def Tosa_TileOp: Tosa_Op<"tile", [ 1480 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1481 ["inferReturnTypeComponents"]>, 1482 NoSideEffect]> { 1483 let summary = "Tile operator"; 1484 1485 let description = [{ 1486 Replicates input 0 multiplies times along each dimension. 1487 }]; 1488 1489 let arguments = (ins 1490 Tosa_Tensor1Dto4D:$input1, 1491 I64ArrayAttr:$multiples); 1492 1493 let results = (outs 1494 Tosa_Tensor1Dto4D:$output 1495 ); 1496} 1497 1498//===----------------------------------------------------------------------===// 1499// Operator: transpose 1500//===----------------------------------------------------------------------===// 1501def Tosa_TransposeOp : Tosa_Op<"transpose", [ 1502 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1503 ["inferReturnTypeComponents"]>, 1504 NoSideEffect]> { 1505 let summary = "Transpose operator"; 1506 1507 let description = [{ 1508 Permutes the dimensions based on perm. 1509 }]; 1510 1511 let arguments = (ins 1512 Tosa_Tensor1Dto6D:$input1, 1513 Tosa_Int32Or64Tensor:$perms 1514 ); 1515 1516 let results = ( 1517 outs Tosa_Tensor1Dto6D:$output 1518 ); 1519} 1520 1521//===----------------------------------------------------------------------===// 1522// TOSA Spec Section 2.10 1523// Operator Class: Scatter/gather Operations. 1524//===----------------------------------------------------------------------===// 1525 1526//===----------------------------------------------------------------------===// 1527// Operator: gather 1528//===----------------------------------------------------------------------===// 1529def Tosa_GatherOp : Tosa_Op<"gather", [ 1530 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1531 ["inferReturnTypeComponents"]>, 1532 NoSideEffect]> { 1533 let summary = "Gather operation,"; 1534 1535 let description = [{ 1536 Generate a tensor for which each element in the output is a slice of the 1537 values tensor based on the value of indices. 1538 }]; 1539 1540 let arguments = (ins 1541 Tosa_Tensor3D:$values, 1542 2DTensorOf<[Tosa_Int32]>:$indices 1543 ); 1544 1545 let results = (outs 1546 Tosa_Tensor3D:$output 1547 ); 1548} 1549 1550//===----------------------------------------------------------------------===// 1551// Operator: scatter 1552//===----------------------------------------------------------------------===// 1553def Tosa_ScatterOp : Tosa_Op<"scatter", [ 1554 DeclareOpInterfaceMethods<InferShapedTypeOpInterface, 1555 ["inferReturnTypeComponents"]>, 1556 NoSideEffect]> { 1557 let summary = "Scatter operation,"; 1558 1559 let description = [{ 1560 The values_out tensor is set to the values_in tensor with data modified as follows: 1561 data from the input tensor is inserted at the positions specified by the indices tensor. 1562 }]; 1563 1564 let arguments = (ins 1565 Tosa_Tensor3D:$values_in, 1566 2DTensorOf<[Tosa_Int32]>:$indices, 1567 Tosa_Tensor3D:$input 1568 ); 1569 1570 let results = (outs 1571 Tosa_Tensor3D:$values_out 1572 ); 1573} 1574 1575//===----------------------------------------------------------------------===// 1576// TOSA Spec Section 2.11 1577// Operator Class: Image Frontend Functions. 1578//===----------------------------------------------------------------------===// 1579 1580//===----------------------------------------------------------------------===// 1581// Operator: resize 1582//===----------------------------------------------------------------------===// 1583def Tosa_ResizeOp : Tosa_Op<"resize", [NoSideEffect]> { 1584 1585 let summary = "Resize operation, supports various resize/upsample modes"; 1586 1587 let description = [{ 1588 Resizes a tensor. Resize is only allowed in the H and W dimensions. In 1589 expected use, stride_y is approximately (IH<<shift)/OH and stride_x is 1590 approximately (IW<<shift)/OW. OH and OW are also supplied as inputs since 1591 there may be off by one errors if calculating OH and OW from the strides. 1592 }]; 1593 1594 let arguments = (ins 1595 Tosa_Tensor4D:$input, 1596 Tosa_IntArrayAttr2:$output_size, 1597 Tosa_IntArrayAttr2:$stride, 1598 Tosa_IntArrayAttr2:$offset, 1599 I32Attr:$shift, 1600 Tosa_Fp32ArrayAttr2:$stride_fp, 1601 Tosa_Fp32ArrayAttr2:$offset_fp, 1602 Tosa_ResizeTypeAttr:$mode 1603 ); 1604 1605 let results = (outs 1606 Tosa_Tensor4D:$output 1607 ); 1608} 1609 1610//===----------------------------------------------------------------------===// 1611// TOSA Spec Section 2.12 1612// Operator Class: Type Conversion. 1613//===----------------------------------------------------------------------===// 1614 1615//===----------------------------------------------------------------------===// 1616// Operator: cast 1617//===----------------------------------------------------------------------===// 1618def Tosa_CastOp: Tosa_Op<"cast", [NoSideEffect]> { 1619 1620 let summary = "Cast operation"; 1621 1622 let description = [{ 1623 Performs a set of permissible cast operations 1624 Mode Input Output 1625 --------------------------------------- 1626 signed 8 to bool int8 Boolean 1627 signed 16 to bool int16 Boolean 1628 signed 32 to bool int32 Boolean 1629 bool to 8 Boolean int8 1630 bool to 16 Boolean int16 1631 bool to 32 Boolean int32 1632 signed 8 to signed 16 int8 int16 1633 signed 8 to signed 32 int8 int32 1634 signed 16 to signed 8 int16 int8 1635 signed 16 to signed 32 int16 int32 1636 signed 32 to signed 8 int32 int8 1637 signed 32 to signed 16 int32 int16 1638 float to signed 8 float int8 1639 float to signed 16 float int16 1640 signed 8 to float int8 float 1641 signed 16 to float int16 float 1642 }]; 1643 1644 let arguments = (ins 1645 Tosa_Tensor:$input 1646 ); 1647 1648 let results = (outs 1649 Tosa_Tensor:$output 1650 ); 1651} 1652 1653//===----------------------------------------------------------------------===// 1654// Operator: rescale 1655//===----------------------------------------------------------------------===// 1656def Tosa_RescaleOp: Tosa_Op<"rescale", [NoSideEffect]> { 1657 let summary = "Tosa rescale operator"; 1658 1659 let description = [{ 1660 Rescale quantized values into a new domain. Supported rescalings are: 1661 Mode Input Output 1662 signed 8 to 8 int8 int8 1663 signed 8 to 16 int8 int16 1664 signed 8 to 32 int8 int32 1665 signed 16 to 8 int16 int8 1666 signed 16 to 16 int16 int16 1667 signed 16 to 32 int16 int32 1668 signed 32 to 8 int32 int8 1669 signed 32 to 16 int32 int16 1670 signed 32 to 32 int32 int32 1671 signed 48 to 8 int48 int8 1672 signed 48 to 16 int48 int16 1673 signed 48 to 32 int48 int32 1674 unsigned 8 to signed 8 uint8 int8 1675 signed 8 to unsigned 8 int8 uint8 1676 }]; 1677 1678 let arguments = (ins 1679 Tosa_Tensor:$input, 1680 I32Attr:$input_zp, 1681 I32Attr:$output_zp, 1682 I32ArrayAttr:$multiplier, 1683 I32ArrayAttr:$shift, 1684 BoolAttr:$scale32, 1685 BoolAttr:$double_round, 1686 BoolAttr:$per_channel 1687 ); 1688 1689 let results = (outs 1690 Tosa_Tensor:$output 1691 ); 1692} 1693 1694//===----------------------------------------------------------------------===// 1695// TOSA Spec Section 2.13 1696// Operator Class: Data Node Ops. 1697//===----------------------------------------------------------------------===// 1698 1699//===----------------------------------------------------------------------===// 1700// Operator: const 1701//===----------------------------------------------------------------------===// 1702def Tosa_ConstOp : Tosa_Op<"const", [ConstantLike, NoSideEffect, 1703 FirstAttrDerivedResultType]> { 1704 let summary = "Constant op."; 1705 1706 let description = [{ 1707 A node containing constant data for use as the input to an operation. May 1708 hold data in any of the supported data formats. 1709 }]; 1710 1711 let arguments = (ins 1712 ElementsAttr:$value 1713 ); 1714 1715 let results = (outs 1716 Tosa_Tensor:$output 1717 ); 1718 let hasFolder = 1; 1719} 1720 1721//===----------------------------------------------------------------------===// 1722// Operator: identity 1723//===----------------------------------------------------------------------===// 1724def Tosa_IdentityOp: Tosa_Op<"identity", [NoSideEffect]> { 1725 let summary = "Identity operator"; 1726 let description = [{ 1727 Returns a tensor with the same shape, size, type 1728 and content as the input. 1729 }]; 1730 1731 let arguments = (ins 1732 Tosa_Tensor:$input1 1733 ); 1734 1735 let results = (outs 1736 Tosa_Tensor:$output 1737 ); 1738} 1739 1740//===----------------------------------------------------------------------===// 1741// TOSA Spec Section 2.14 1742// Operator Class: Custom Operators. 1743//===----------------------------------------------------------------------===// 1744 1745//===----------------------------------------------------------------------===// 1746// Operator: custom 1747//===----------------------------------------------------------------------===// 1748def Tosa_CustomOp : Tosa_Op<"custom"> { 1749 1750 let summary = "Custom operator wrapper for Tosa"; 1751 1752 let description = [{ 1753 Hardware implementing TOSA may choose to add additional custom operators 1754 that are not expressed in the existing TOSA operations. These operators are 1755 not expected to be portable across TOSA implementations. The input and 1756 output signatures must be expressed in the corresponding TOSA node. 1757 }]; 1758 1759 let arguments = (ins 1760 StrAttr:$identifier, 1761 Variadic<Tosa_Tensor>:$inputs 1762 ); 1763 1764 let results = (outs 1765 Variadic<Tosa_Tensor>:$outputs 1766 ); 1767} 1768 1769//===----------------------------------------------------------------------===// 1770// TOSA Spec Section 2.15 1771// Operator Class: Control Flow Operators. 1772//===----------------------------------------------------------------------===// 1773 1774//===----------------------------------------------------------------------===// 1775// Operator: cond_if 1776//===----------------------------------------------------------------------===// 1777//===----------------------------------------------------------------------===// 1778// Further described in docs/Rationale/RationaleTOSADialect.md . 1779//===----------------------------------------------------------------------===// 1780def Tosa_IfOp : Tosa_Op<"cond_if", [ 1781 SingleBlockImplicitTerminator<"YieldOp">, 1782 RecursiveSideEffects]> { 1783 let summary = "Conditional if operator"; 1784 1785 let description = [{ 1786 Evaluates a Boolean condition and then takes one of two distinct execution 1787 paths. This implements the semantic If-then-else structure. 1788 }]; 1789 1790 let arguments = (ins 1791 I1Tensor:$cond, 1792 Variadic<Tosa_Tensor>:$inputs 1793 ); 1794 1795 let results = (outs 1796 Variadic<Tosa_Tensor>:$output 1797 ); 1798 1799 let regions = (region 1800 SizedRegion<1>:$then_branch, 1801 SizedRegion<1>:$else_branch 1802 ); 1803} 1804 1805//===----------------------------------------------------------------------===// 1806// Operator: while_loop 1807//===----------------------------------------------------------------------===// 1808//===----------------------------------------------------------------------===// 1809// Further described in docs/Rationale/RationaleTOSADialect.md . 1810//===----------------------------------------------------------------------===// 1811def Tosa_WhileOp : Tosa_Op<"while_loop", [ 1812 DeclareOpInterfaceMethods<LoopLikeOpInterface>, 1813 SingleBlockImplicitTerminator<"YieldOp">, 1814 RecursiveSideEffects]> { 1815 let summary = "output = input; While (Cond(output)) {output = Body(output)}"; 1816 1817 let description = [{ 1818 Generates and evaluates a Bool condition and either executes a loop body or 1819 exits to another control point. This action is performed repeatedly after 1820 updating and re-evaluating the Boolean condition every iteration. This 1821 implements the semantic foreach or while iterative loop structure. 1822 }]; 1823 1824 let arguments = (ins 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>:$cond, 1834 SizedRegion<1>:$body 1835 ); 1836} 1837 1838include "mlir/Dialect/Tosa/IR/TosaUtilOps.td" 1839 1840#endif // TOSA_OPS 1841