Tensor
tensor
¶
Tensor = Dialect('tensor', [CastOp, CollapseShapeOp, ConcatOp, DimOp, EmptyOp, ExpandShapeOp, ExtractOp, ExtractSliceOp, FromElementsOp, InsertOp, InsertSliceOp, ReshapeOp, SplatOp, PadOp, YieldOp], [])
module-attribute
¶
CastOp
¶
Bases: IRDLOperation
Tensor cast operation.
Convert a tensor from one type to an equivalent type without changing any data elements. The source and destination types must both be tensor types with the same element type. If both are ranked, then the rank should be the same and static dimensions should match. The operation is invalid if converting to a mismatching constant dimension.
https://mlir.llvm.org/docs/Dialects/TensorOps/#tensorcast-tensorcastop
Source code in xdsl/dialects/tensor.py
name = 'tensor.cast'
class-attribute
instance-attribute
¶
source = operand_def(base(TensorType[Attribute]) | base(UnrankedTensorType[Attribute]))
class-attribute
instance-attribute
¶
dest = result_def(base(TensorType[Attribute]) | base(UnrankedTensorType[Attribute]))
class-attribute
instance-attribute
¶
assembly_format = '$source attr-dict `:` type($source) `to` type($dest)'
class-attribute
instance-attribute
¶
traits = traits_def(Pure())
class-attribute
instance-attribute
¶
__init__(source: SSAValue | Operation, dest: TensorType[Attribute])
¶
verify_()
¶
Source code in xdsl/dialects/tensor.py
ConcatOp
¶
Bases: IRDLOperation
Tensor concatenation operation.
The “concat” operation constructs a tensor out of a variadic list of input tensors, concatenated along a static dimension number. All inputs and the result type must share the same rank.
dim specifies the dimension along which to concatenate. The size of the concatenated
dimension in the result must be equal to the sum of the sizes of the inputs along that
dimension. All other dimensions in both the inputs and result must be the same size.
https://mlir.llvm.org/docs/Dialects/TensorOps/#tensorconcat-tensorconcatop
Source code in xdsl/dialects/tensor.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
name = 'tensor.concat'
class-attribute
instance-attribute
¶
inputs = var_operand_def(RangeOf(TensorType.constr(_TENSOR_ELEMENT, ArrayOfConstraint(RangeOf(AnyAttr()).of_length(_RANK)))).of_length(AtLeast(1)))
class-attribute
instance-attribute
¶
dim = prop_def(IntegerAttr[I64])
class-attribute
instance-attribute
¶
result = result_def(TensorType.constr(_TENSOR_ELEMENT, ArrayOfConstraint(RangeOf(AnyAttr()).of_length(_RANK))))
class-attribute
instance-attribute
¶
traits = traits_def(Pure())
class-attribute
instance-attribute
¶
assembly_format = ' `dim` `(` $dim `)` $inputs attr-dict `:` functional-type(operands, results)'
class-attribute
instance-attribute
¶
__init__(inputs: Sequence[SSAValue | Operation], dim: IntegerAttr | int, result_type: TensorType, attributes: Mapping[str, Attribute] | None = None)
¶
Source code in xdsl/dialects/tensor.py
verify_() -> None
¶
Source code in xdsl/dialects/tensor.py
DimOp
¶
Bases: IRDLOperation
Dimension index operation.
The tensor.dim operation takes a tensor and a dimension operand of type index. It returns the size of the requested dimension of the given tensor. If the dimension index is out of bounds, the behavior is undefined.
https://mlir.llvm.org/docs/Dialects/TensorOps/#tensordim-tensordimop
Source code in xdsl/dialects/tensor.py
name = 'tensor.dim'
class-attribute
instance-attribute
¶
source = operand_def(base(TensorType[Attribute]) | base(UnrankedTensorType[Attribute]))
class-attribute
instance-attribute
¶
index = operand_def(IndexType)
class-attribute
instance-attribute
¶
result = result_def(IndexType)
class-attribute
instance-attribute
¶
traits = traits_def(NoMemoryEffect())
class-attribute
instance-attribute
¶
assembly_format = 'attr-dict $source `,` $index `:` type($source)'
class-attribute
instance-attribute
¶
__init__(source: SSAValue | Operation, index: SSAValue | Operation, attributes: Mapping[str, Attribute] | None = None)
¶
Source code in xdsl/dialects/tensor.py
EmptyOp
¶
Bases: IRDLOperation
Empty tensor operation.
Defines a tensor of a particular shape which could be dynamic or static. The contents of the tensor are unspecified and the only purpose of the op result is to materialize the specified shape in IR and make it available to other transformations.
https://mlir.llvm.org/docs/Dialects/TensorOps/#tensorempty-tensoremptyop
Source code in xdsl/dialects/tensor.py
name = 'tensor.empty'
class-attribute
instance-attribute
¶
dynamic_sizes = var_operand_def(IndexType)
class-attribute
instance-attribute
¶
tensor = result_def(TensorType[Attribute])
class-attribute
instance-attribute
¶
traits = traits_def(NoMemoryEffect())
class-attribute
instance-attribute
¶
__init__(dynamic_sizes: Sequence[SSAValue], tensor_type: Attribute)
¶
print(printer: Printer)
¶
Source code in xdsl/dialects/tensor.py
parse(parser: Parser) -> Self
classmethod
¶
Source code in xdsl/dialects/tensor.py
CollapseShapeOp
dataclass
¶
Bases: IRDLOperation
Operation to produce a tensor with a smaller rank.
The collapse_shape operation produces a new tensor of lower (or equal) rank whose dimension sizes are a reassociation of the original src dimensions.
https://mlir.llvm.org/docs/Dialects/TensorOps/#tensorcollapse_shape-tensorcollapseshapeop
Source code in xdsl/dialects/tensor.py
name = 'tensor.collapse_shape'
class-attribute
instance-attribute
¶
src = operand_def(TensorType[Attribute])
class-attribute
instance-attribute
¶
result = result_def(TensorType[Attribute])
class-attribute
instance-attribute
¶
reassociation = prop_def(ContiguousArrayOfIntArray())
class-attribute
instance-attribute
¶
assembly_format = '$src $reassociation attr-dict `:` type($src) `into` type($result)'
class-attribute
instance-attribute
¶
traits = traits_def(Pure())
class-attribute
instance-attribute
¶
ReshapeOp
¶
Bases: IRDLOperation
Tensor reshape operation.
The reshape operation converts a tensor from one type to an equivalent type with a provided shape. The source and destination types are compatible if both have the same element type, same number of elements.
https://mlir.llvm.org/docs/Dialects/TensorOps/#tensorreshape-tensorreshapeop
Source code in xdsl/dialects/tensor.py
name = 'tensor.reshape'
class-attribute
instance-attribute
¶
source = operand_def(TensorType[Attribute])
class-attribute
instance-attribute
¶
shape = operand_def(TensorType[AnySignlessIntegerType | IndexType])
class-attribute
instance-attribute
¶
result = result_def(TensorType[Attribute])
class-attribute
instance-attribute
¶
assembly_format = 'attr-dict $source `(` $shape `)` `:` `(` type($source) `,` type($shape) `)` `->` type($result)'
class-attribute
instance-attribute
¶
traits = traits_def(Pure())
class-attribute
instance-attribute
¶
__init__(source: SSAValue, shape: SSAValue, result_type: Attribute)
¶
verify_() -> None
¶
Source code in xdsl/dialects/tensor.py
ExpandShapeOp
¶
Bases: IRDLOperation
Operation to produce a tensor with a higher rank.
The tensor.expand_shape op produces a tensor of higher (or equal) rank than the operand src whose dimension sizes are a reassociation of src.
https://mlir.llvm.org/docs/Dialects/TensorOps/#tensorexpand_shape-tensorexpandshapeop
Source code in xdsl/dialects/tensor.py
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 | |
name = 'tensor.expand_shape'
class-attribute
instance-attribute
¶
src = operand_def(TensorType)
class-attribute
instance-attribute
¶
dynamic_output_shape = var_operand_def(IndexType)
class-attribute
instance-attribute
¶
reassociation = prop_def(ContiguousArrayOfIntArray())
class-attribute
instance-attribute
¶
static_output_shape = prop_def(DenseArrayBase.constr(i64))
class-attribute
instance-attribute
¶
result = result_def(TensorType[Attribute])
class-attribute
instance-attribute
¶
traits = traits_def(Pure())
class-attribute
instance-attribute
¶
__init__(src: SSAValue | Operation, dynamic_output_shape: Sequence[SSAValue], reassociation: ArrayAttr[ArrayAttr[IntegerAttr]], static_output_shape: Sequence[int] | DenseArrayBase, result_type: TensorType[Attribute], attributes: dict[str, Attribute] | None = None)
¶
Source code in xdsl/dialects/tensor.py
verify_()
¶
Source code in xdsl/dialects/tensor.py
parse(parser: Parser) -> Self
classmethod
¶
Source code in xdsl/dialects/tensor.py
print(printer: Printer)
¶
Source code in xdsl/dialects/tensor.py
ExtractSliceOp
¶
Bases: IRDLOperation
Extract slice operation.
Extracts a tensor from another tensor as specified by the operation’s offsets, sizes and strides arguments.
https://mlir.llvm.org/docs/Dialects/TensorOps/#tensorextract_slice-tensorextractsliceop
Source code in xdsl/dialects/tensor.py
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
name = 'tensor.extract_slice'
class-attribute
instance-attribute
¶
source = operand_def(TensorType)
class-attribute
instance-attribute
¶
offsets = var_operand_def(IndexType)
class-attribute
instance-attribute
¶
sizes = var_operand_def(IndexType)
class-attribute
instance-attribute
¶
strides = var_operand_def(IndexType)
class-attribute
instance-attribute
¶
static_offsets = prop_def(DenseArrayBase.constr(i64))
class-attribute
instance-attribute
¶
static_sizes = prop_def(DenseArrayBase.constr(i64))
class-attribute
instance-attribute
¶
static_strides = prop_def(DenseArrayBase.constr(i64))
class-attribute
instance-attribute
¶
result = result_def(TensorType)
class-attribute
instance-attribute
¶
irdl_options = (AttrSizedOperandSegments(as_property=True),)
class-attribute
instance-attribute
¶
traits = traits_def(Pure())
class-attribute
instance-attribute
¶
assembly_format = '$source ``custom<DynamicIndexList>($offsets, $static_offsets)custom<DynamicIndexList>($sizes, $static_sizes)custom<DynamicIndexList>($strides, $static_strides)attr-dict `:` type($source) `to` type($result)'
class-attribute
instance-attribute
¶
custom_directives = (DynamicIndexList,)
class-attribute
instance-attribute
¶
verify_() -> None
¶
Source code in xdsl/dialects/tensor.py
__init__(source: SSAValue | Operation, offsets: Sequence[SSAValue | int], sizes: Sequence[SSAValue | int], strides: Sequence[SSAValue | int], result_type: Attribute)
¶
Build a tensor.extract_slice from offsets, sizes, and strides that may each be a static integer or a dynamic SSA value.
Source code in xdsl/dialects/tensor.py
infer_result_type(source_type: TensorType[Attribute], sizes: Sequence[SSAValue | int]) -> TensorType[Attribute]
staticmethod
¶
Infer the result type of a tensor.extract_slice from its source type and sizes. Offsets and strides do not affect the result shape.
Raises:
| Type | Description |
|---|---|
ValueError
|
If sizes do not match the source rank. |
Source code in xdsl/dialects/tensor.py
from_static_parameters(source: SSAValue | Operation, offsets: Sequence[int], sizes: Sequence[int], strides: Sequence[int] | None = None, reduce_rank: bool = False) -> ExtractSliceOp
staticmethod
¶
Source code in xdsl/dialects/tensor.py
InsertSliceOp
dataclass
¶
Bases: IRDLOperation
Insert_slice operation.
The insert_slice operation insert a tensor, source, into another tensor, dest, as specified by the operation’s offsets, sizes and strides arguments. It returns a copy of dest with the proper slice updated with the value of source.
https://mlir.llvm.org/docs/Dialects/TensorOps/#tensorinsert_slice-tensorinsertsliceop
Source code in xdsl/dialects/tensor.py
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 | |
name = 'tensor.insert_slice'
class-attribute
instance-attribute
¶
DEST_TYPE: ClassVar = VarConstraint('DEST_TYPE', base(TensorType))
class-attribute
instance-attribute
¶
source = operand_def(TensorType)
class-attribute
instance-attribute
¶
dest = operand_def(DEST_TYPE)
class-attribute
instance-attribute
¶
offsets = var_operand_def(IndexType)
class-attribute
instance-attribute
¶
sizes = var_operand_def(IndexType)
class-attribute
instance-attribute
¶
strides = var_operand_def(IndexType)
class-attribute
instance-attribute
¶
static_offsets = prop_def(DenseArrayBase.constr(i64))
class-attribute
instance-attribute
¶
static_sizes = prop_def(DenseArrayBase.constr(i64))
class-attribute
instance-attribute
¶
static_strides = prop_def(DenseArrayBase.constr(i64))
class-attribute
instance-attribute
¶
result = result_def(DEST_TYPE)
class-attribute
instance-attribute
¶
irdl_options = (AttrSizedOperandSegments(as_property=True),)
class-attribute
instance-attribute
¶
traits = traits_def(Pure())
class-attribute
instance-attribute
¶
assembly_format = '$source `into` $dest ``custom<DynamicIndexList>($offsets, $static_offsets)custom<DynamicIndexList>($sizes, $static_sizes)custom<DynamicIndexList>($strides, $static_strides)attr-dict `:` type($source) `into` type($dest)'
class-attribute
instance-attribute
¶
custom_directives = (DynamicIndexList,)
class-attribute
instance-attribute
¶
verify_() -> None
¶
Source code in xdsl/dialects/tensor.py
get(source: Operand, dest: Operand, static_sizes: Sequence[int], static_offsets: Sequence[int] | None = None, static_strides: Sequence[int] | None = None, offsets: Sequence[Operand] | None = None, sizes: Sequence[Operand] | None = None, strides: Sequence[Operand] | None = None, result_type: Attribute | None = None) -> InsertSliceOp
staticmethod
¶
Source code in xdsl/dialects/tensor.py
from_static_parameters(source: SSAValue | Operation, dest: SSAValue | Operation, offsets: Sequence[int], sizes: Sequence[int], strides: Sequence[int] | None = None) -> InsertSliceOp
staticmethod
¶
Source code in xdsl/dialects/tensor.py
ExtractOp
¶
Bases: IRDLOperation
Element extraction operation.
The tensor.extract op reads a ranked tensor and returns one element as specified by the given indices. The result of the op is a value with the same type as the elements of the tensor. The arity of indices must match the rank of the accessed value. All indices should all be of index type.
https://mlir.llvm.org/docs/Dialects/TensorOps/#tensorextract-tensorextractop
Source code in xdsl/dialects/tensor.py
name = 'tensor.extract'
class-attribute
instance-attribute
¶
ELEMENT: ClassVar = VarConstraint('ELEMENT', AnyAttr())
class-attribute
instance-attribute
¶
tensor = operand_def(TensorType.constr(ELEMENT))
class-attribute
instance-attribute
¶
indices = var_operand_def(IndexType)
class-attribute
instance-attribute
¶
result = result_def(ELEMENT)
class-attribute
instance-attribute
¶
assembly_format = '$tensor `[` $indices `]` attr-dict `:` type($tensor)'
class-attribute
instance-attribute
¶
traits = traits_def(Pure())
class-attribute
instance-attribute
¶
__init__(tensor: SSAValue, indices: Sequence[SSAValue] | SSAValue, result_type: Attribute)
¶
Source code in xdsl/dialects/tensor.py
InsertOp
¶
Bases: IRDLOperation
Element insertion operation.
The tensor.insert op inserts a scalar into a ranked tensor, dest, as specified by the operation’s indices. It returns a copy of dest with the indexed position updated to the value of scalar.
https://mlir.llvm.org/docs/Dialects/TensorOps/#tensorinsert-tensorinsertop
Source code in xdsl/dialects/tensor.py
name = 'tensor.insert'
class-attribute
instance-attribute
¶
ELEMENT: ClassVar = VarConstraint('ELEMENT', AnyAttr())
class-attribute
instance-attribute
¶
TENSOR: ClassVar = VarConstraint('TENSOR', TensorType.constr(ELEMENT))
class-attribute
instance-attribute
¶
scalar = operand_def(ELEMENT)
class-attribute
instance-attribute
¶
dest = operand_def(TENSOR)
class-attribute
instance-attribute
¶
indices = var_operand_def(IndexType)
class-attribute
instance-attribute
¶
result = result_def(TENSOR)
class-attribute
instance-attribute
¶
assembly_format = '$scalar `into` $dest `[` $indices `]` attr-dict `:` type($dest)'
class-attribute
instance-attribute
¶
traits = traits_def(Pure())
class-attribute
instance-attribute
¶
__init__(scalar: SSAValue, dest: SSAValue, indices: Sequence[SSAValue] | SSAValue)
¶
Source code in xdsl/dialects/tensor.py
FromElementsOp
¶
Bases: IRDLOperation
Tensor from elements operation.
Create a N-D tensor from a range of same-type arguments. The number of provided elements should equal to the number of the elements in the result type. The elements correspond to a flattened tensor.
https://mlir.llvm.org/docs/Dialects/TensorOps/#tensorfrom_elements-tensorfromelementsop
Source code in xdsl/dialects/tensor.py
name = 'tensor.from_elements'
class-attribute
instance-attribute
¶
ELEMENT_TYPE: ClassVar = VarConstraint('ELEMENT_TYPE', AnyAttr())
class-attribute
instance-attribute
¶
elements = var_operand_def(ELEMENT_TYPE)
class-attribute
instance-attribute
¶
result = result_def(TensorType.constr(ELEMENT_TYPE))
class-attribute
instance-attribute
¶
assembly_format = '$elements attr-dict `:` type($result)'
class-attribute
instance-attribute
¶
traits = traits_def(Pure())
class-attribute
instance-attribute
¶
__init__(head_element: SSAValue, *tail_elements: SSAValue, result_type: Attribute | None = None)
¶
Source code in xdsl/dialects/tensor.py
SplatOp
¶
Bases: IRDLOperation
Tensor splat or broadcast operation.
Broadcast the operand to all elements of the result tensor. An additional argument of type index must be provided for each dynamic dimension present in the result type.
https://mlir.llvm.org/docs/Dialects/TensorOps/#tensorsplat-tensorsplatop
Source code in xdsl/dialects/tensor.py
name = 'tensor.splat'
class-attribute
instance-attribute
¶
SPLAT_TYPE: ClassVar = VarConstraint('SPLAT_TYPE', AnyAttr())
class-attribute
instance-attribute
¶
input = operand_def(SPLAT_TYPE)
class-attribute
instance-attribute
¶
dynamicSizes = var_operand_def(IndexType)
class-attribute
instance-attribute
¶
result = result_def(TensorType.constr(SPLAT_TYPE))
class-attribute
instance-attribute
¶
assembly_format = '$input (`[` $dynamicSizes^ `]`)? attr-dict `:` type($result)'
class-attribute
instance-attribute
¶
traits = traits_def(Pure())
class-attribute
instance-attribute
¶
__init__(input: SSAValue, dynamicSizes: Sequence[SSAValue | Operation], result_type: TensorType[Attribute])
¶
YieldOp
dataclass
¶
Bases: AbstractYieldOperation[Attribute]
Source code in xdsl/dialects/tensor.py
PadOp
¶
Bases: IRDLOperation
Tensor pad operation.
tensor.pad is an operation that pads the source tensor with given low and high padding config.
https://mlir.llvm.org/docs/Dialects/TensorOps/#tensorpad-tensorpadop
Source code in xdsl/dialects/tensor.py
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 | |