|
| 1 | +# RUN: %PYTHON %s | FileCheck %s |
| 2 | + |
| 3 | +from mlir.ir import * |
| 4 | +from mlir.dialects import transform |
| 5 | +from mlir.dialects.transform import vector |
| 6 | + |
| 7 | + |
| 8 | +def run_apply_patterns(f): |
| 9 | + with Context(), Location.unknown(): |
| 10 | + module = Module.create() |
| 11 | + with InsertionPoint(module.body): |
| 12 | + sequence = transform.SequenceOp( |
| 13 | + transform.FailurePropagationMode.PROPAGATE, |
| 14 | + [], |
| 15 | + transform.AnyOpType.get(), |
| 16 | + ) |
| 17 | + with InsertionPoint(sequence.body): |
| 18 | + apply = transform.ApplyPatternsOp(sequence.bodyTarget) |
| 19 | + with InsertionPoint(apply.patterns): |
| 20 | + f() |
| 21 | + transform.YieldOp() |
| 22 | + print("\nTEST:", f.__name__) |
| 23 | + print(module) |
| 24 | + return f |
| 25 | + |
| 26 | + |
| 27 | +@run_apply_patterns |
| 28 | +def non_configurable_patterns(): |
| 29 | + # CHECK-LABEL: TEST: non_configurable_patterns |
| 30 | + # CHECK: apply_patterns |
| 31 | + # CHECK: transform.apply_patterns.vector.cast_away_vector_leading_one_dim |
| 32 | + vector.ApplyCastAwayVectorLeadingOneDimPatternsOp() |
| 33 | + # CHECK: transform.apply_patterns.vector.rank_reducing_subview_patterns |
| 34 | + vector.ApplyRankReducingSubviewPatternsOp() |
| 35 | + # CHECK: transform.apply_patterns.vector.transfer_permutation_patterns |
| 36 | + vector.ApplyTransferPermutationPatternsOp() |
| 37 | + # CHECK: transform.apply_patterns.vector.lower_broadcast |
| 38 | + vector.ApplyLowerBroadcastPatternsOp() |
| 39 | + # CHECK: transform.apply_patterns.vector.lower_masks |
| 40 | + vector.ApplyLowerMasksPatternsOp() |
| 41 | + # CHECK: transform.apply_patterns.vector.lower_masked_transfers |
| 42 | + vector.ApplyLowerMaskedTransfersPatternsOp() |
| 43 | + # CHECK: transform.apply_patterns.vector.materialize_masks |
| 44 | + vector.ApplyMaterializeMasksPatternsOp() |
| 45 | + # CHECK: transform.apply_patterns.vector.lower_outerproduct |
| 46 | + vector.ApplyLowerOuterProductPatternsOp() |
| 47 | + # CHECK: transform.apply_patterns.vector.lower_gather |
| 48 | + vector.ApplyLowerGatherPatternsOp() |
| 49 | + # CHECK: transform.apply_patterns.vector.lower_scan |
| 50 | + vector.ApplyLowerScanPatternsOp() |
| 51 | + # CHECK: transform.apply_patterns.vector.lower_shape_cast |
| 52 | + vector.ApplyLowerShapeCastPatternsOp() |
| 53 | + |
| 54 | + |
| 55 | +@run_apply_patterns |
| 56 | +def configurable_patterns(): |
| 57 | + # CHECK-LABEL: TEST: configurable_patterns |
| 58 | + # CHECK: apply_patterns |
| 59 | + # CHECK: transform.apply_patterns.vector.lower_transfer |
| 60 | + # CHECK-SAME: max_transfer_rank = 4 |
| 61 | + vector.ApplyLowerTransferPatternsOp(max_transfer_rank=4) |
| 62 | + # CHECK: transform.apply_patterns.vector.transfer_to_scf |
| 63 | + # CHECK-SAME: max_transfer_rank = 3 |
| 64 | + # CHECK-SAME: full_unroll = true |
| 65 | + vector.ApplyTransferToScfPatternsOp(max_transfer_rank=3, full_unroll=True) |
| 66 | + |
| 67 | + |
| 68 | +@run_apply_patterns |
| 69 | +def enum_configurable_patterns(): |
| 70 | + # CHECK: transform.apply_patterns.vector.lower_contraction |
| 71 | + vector.ApplyLowerContractionPatternsOp() |
| 72 | + # CHECK: transform.apply_patterns.vector.lower_contraction |
| 73 | + # CHECK-SAME: lowering_strategy = matmulintrinsics |
| 74 | + vector.ApplyLowerContractionPatternsOp( |
| 75 | + lowering_strategy=vector.VectorContractLowering.MATMUL |
| 76 | + ) |
| 77 | + # CHECK: transform.apply_patterns.vector.lower_contraction |
| 78 | + # CHECK-SAME: lowering_strategy = parallelarith |
| 79 | + vector.ApplyLowerContractionPatternsOp( |
| 80 | + lowering_strategy=vector.VectorContractLowering.PARALLEL_ARITH |
| 81 | + ) |
| 82 | + |
| 83 | + # CHECK: transform.apply_patterns.vector.lower_multi_reduction |
| 84 | + vector.ApplyLowerMultiReductionPatternsOp() |
| 85 | + # CHECK: transform.apply_patterns.vector.lower_multi_reduction |
| 86 | + # This is the default mode, not printed. |
| 87 | + vector.ApplyLowerMultiReductionPatternsOp( |
| 88 | + lowering_strategy=vector.VectorMultiReductionLowering.INNER_PARALLEL |
| 89 | + ) |
| 90 | + # CHECK: transform.apply_patterns.vector.lower_multi_reduction |
| 91 | + # CHECK-SAME: lowering_strategy = innerreduction |
| 92 | + vector.ApplyLowerMultiReductionPatternsOp( |
| 93 | + lowering_strategy=vector.VectorMultiReductionLowering.INNER_REDUCTION |
| 94 | + ) |
| 95 | + |
| 96 | + # CHECK: transform.apply_patterns.vector.lower_transpose |
| 97 | + # CHECK-SAME: lowering_strategy = eltwise |
| 98 | + # CHECK-SAME: avx2_lowering_strategy = false |
| 99 | + vector.ApplyLowerTransposePatternsOp() |
| 100 | + # CHECK: transform.apply_patterns.vector.lower_transpose |
| 101 | + # CHECK-SAME: lowering_strategy = eltwise |
| 102 | + # CHECK-SAME: avx2_lowering_strategy = false |
| 103 | + vector.ApplyLowerTransposePatternsOp( |
| 104 | + lowering_strategy=vector.VectorTransposeLowering.ELT_WISE |
| 105 | + ) |
| 106 | + # CHECK: transform.apply_patterns.vector.lower_transpose |
| 107 | + # CHECK-SAME: lowering_strategy = flat_transpose |
| 108 | + # CHECK-SAME: avx2_lowering_strategy = false |
| 109 | + vector.ApplyLowerTransposePatternsOp( |
| 110 | + lowering_strategy=vector.VectorTransposeLowering.FLAT |
| 111 | + ) |
| 112 | + # CHECK: transform.apply_patterns.vector.lower_transpose |
| 113 | + # CHECK-SAME: lowering_strategy = shuffle_1d |
| 114 | + # CHECK-SAME: avx2_lowering_strategy = false |
| 115 | + vector.ApplyLowerTransposePatternsOp( |
| 116 | + lowering_strategy=vector.VectorTransposeLowering.SHUFFLE1_D |
| 117 | + ) |
| 118 | + # CHECK: transform.apply_patterns.vector.lower_transpose |
| 119 | + # CHECK-SAME: lowering_strategy = shuffle_16x16 |
| 120 | + # CHECK-SAME: avx2_lowering_strategy = false |
| 121 | + vector.ApplyLowerTransposePatternsOp( |
| 122 | + lowering_strategy=vector.VectorTransposeLowering.SHUFFLE16X16 |
| 123 | + ) |
| 124 | + # CHECK: transform.apply_patterns.vector.lower_transpose |
| 125 | + # CHECK-SAME: lowering_strategy = flat_transpose |
| 126 | + # CHECK-SAME: avx2_lowering_strategy = true |
| 127 | + vector.ApplyLowerTransposePatternsOp( |
| 128 | + lowering_strategy=vector.VectorTransposeLowering.FLAT, |
| 129 | + avx2_lowering_strategy=True, |
| 130 | + ) |
| 131 | + |
| 132 | + # CHECK: transform.apply_patterns.vector.split_transfer_full_partial |
| 133 | + vector.ApplySplitTransferFullPartialPatternsOp() |
| 134 | + # CHECK: transform.apply_patterns.vector.split_transfer_full_partial |
| 135 | + # CHECK-SAME: split_transfer_strategy = none |
| 136 | + vector.ApplySplitTransferFullPartialPatternsOp( |
| 137 | + split_transfer_strategy=vector.VectorTransferSplit.NONE |
| 138 | + ) |
| 139 | + # CHECK: transform.apply_patterns.vector.split_transfer_full_partial |
| 140 | + # CHECK-SAME: split_transfer_strategy = "vector-transfer" |
| 141 | + vector.ApplySplitTransferFullPartialPatternsOp( |
| 142 | + split_transfer_strategy=vector.VectorTransferSplit.VECTOR_TRANSFER |
| 143 | + ) |
| 144 | + # CHECK: transform.apply_patterns.vector.split_transfer_full_partial |
| 145 | + # This is the default mode, not printed. |
| 146 | + vector.ApplySplitTransferFullPartialPatternsOp( |
| 147 | + split_transfer_strategy=vector.VectorTransferSplit.LINALG_COPY |
| 148 | + ) |
| 149 | + # CHECK: transform.apply_patterns.vector.split_transfer_full_partial |
| 150 | + # CHECK-SAME: split_transfer_strategy = "force-in-bounds" |
| 151 | + vector.ApplySplitTransferFullPartialPatternsOp( |
| 152 | + split_transfer_strategy=vector.VectorTransferSplit.FORCE_IN_BOUNDS |
| 153 | + ) |
0 commit comments