Tiling
tiling
OperandTileInfo
dataclass
This records how one operand should be sliced when we enter a tile.
- source_type keeps the original type.
- loop_dims the loop dimension each indexing-map result reads, where it
reads exactly one, and None where it reads an expression over several or
none, which no single loop range can be read back from.
Source code in xdsl/dialects/linalg/transforms/tiling.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
source_type: MemRefType[Attribute] | TensorType[Attribute]
instance-attribute
loop_dims: tuple[int | None, ...]
instance-attribute
__init__(source_type: MemRefType[Attribute] | TensorType[Attribute], loop_dims: tuple[int | None, ...]) -> None
analyze(indexing_map: AffineMap, source_type: MemRefType[Attribute] | TensorType[Attribute]) -> OperandTileInfo
staticmethod
Analyze how one operand should be sliced for each tile.
Source code in xdsl/dialects/linalg/transforms/tiling.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
TilingPlan
dataclass
This stores the information needed to turn one op into tiled loop and tiled subview.
- loop_ranges are original static loop ranges.
- tiled_dims the dimensions that really get tiled.
- partial_tiled_dims the tiled dimensions whose loop range is not divisible
by the tile size, so that their last tile is smaller than the rest.
- operand_infos stores one OperandTileInfo per operand.
- tile_sizes are the normalized tile sizes, padded to match the op loop
count. A tile size that is not known until the op runs is a value.
Source code in xdsl/dialects/linalg/transforms/tiling.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
loop_ranges: tuple[int, ...]
instance-attribute
tiled_dims: tuple[int, ...]
instance-attribute
partial_tiled_dims: frozenset[int]
instance-attribute
operand_infos: tuple[OperandTileInfo, ...]
instance-attribute
tile_sizes: tuple[SSAValue | int, ...]
instance-attribute
__init__(loop_ranges: tuple[int, ...], tiled_dims: tuple[int, ...], partial_tiled_dims: frozenset[int], operand_infos: tuple[OperandTileInfo, ...], tile_sizes: tuple[SSAValue | int, ...]) -> None
analyze(op: linalg.abstract_ops.LinalgStructuredOperation, tile_sizes: Sequence[SSAValue | int]) -> TilingPlan
staticmethod
Analyze one supported structured linalg op and return a TilingPlan.
Source code in xdsl/dialects/linalg/transforms/tiling.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
SliceParameters
dataclass
Where one operand's tile sits within that operand.
This is the geometry of the tile, which is the same whether the operand is a memref or a tensor, and so does not depend on which op ends up materializing the slice.
Source code in xdsl/dialects/linalg/transforms/tiling.py
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 | |
offsets: tuple[SSAValue | int, ...]
instance-attribute
sizes: tuple[SSAValue | int, ...]
instance-attribute
strides: tuple[SSAValue | int, ...]
instance-attribute
__init__(offsets: tuple[SSAValue | int, ...], sizes: tuple[SSAValue | int, ...], strides: tuple[SSAValue | int, ...]) -> None
compute(rewriter: PatternRewriter, insertion_point: InsertPoint, indexing_map: AffineMap, operand_info: OperandTileInfo, tiled_loop_ivs: dict[int, SSAValue], effective_tile_sizes: dict[int, SSAValue | int], loop_ranges: Sequence[int]) -> SliceParameters
staticmethod
Compute the offsets and sizes for one operand's memref.subview or
tensor.extract_slice.
There is one offset and one size per operand dimension, and the indexing map has one result per operand dimension saying how the loops reach it.
- A result that no tiled loop appears in is not sliced at all: offset 0, and the whole dimension for its size.
- A result that is just
dN, for a tiled loop, takes that loop's induction variable as its offset and its tile size as its size. - Any other result,
d0 + d1ord0 * 2, gets both from anaffine.apply. Its offset evaluates the result with each tiled loop at its induction variable and the rest at zero, less what it evaluates to with every loop at zero. Its size evaluates it at the last index each loop reaches inside the tile, plus one to turn that index back into a count.
Source code in xdsl/dialects/linalg/transforms/tiling.py
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 | |
tile_structured_op(rewriter: PatternRewriter, op: linalg.abstract_ops.LinalgStructuredOperation, tile_sizes: Sequence[SSAValue | int]) -> bool
Rewrite supported structured linalg ops into tiled form.
Source code in xdsl/dialects/linalg/transforms/tiling.py
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 | |