|
| 1 | +// RUN: mlir-opt -test-transform-dialect-interpreter %s --split-input-file | FileCheck %s |
| 2 | + |
| 3 | +// CHECK-LABEL: func @insert_slice_to_copy |
| 4 | + // CHECK-SAME: %[[I:.*]]: tensor<2x3xf32> |
| 5 | + // CHECK-SAME: %[[O:.*]]: tensor<?x?xf32>, |
| 6 | + // CHECK-SAME: %[[OFF0:[0-9a-zA-Z]+]]: index, |
| 7 | + // CHECK-SAME: %[[OFF1:[0-9a-zA-Z]+]]: index, |
| 8 | + // CHECK-SAME: %[[SZ0:[0-9a-zA-Z]+]]: index, |
| 9 | + // CHECK-SAME: %[[SZ1:[0-9a-zA-Z]+]]: index, |
| 10 | + // CHECK-SAME: %[[ST0:[0-9a-zA-Z]+]]: index, |
| 11 | + // CHECK-SAME: %[[ST1:[0-9a-zA-Z]+]]: index) |
| 12 | +func.func @insert_slice_to_copy( |
| 13 | + %I : tensor<2x3xf32>, %O : tensor<?x?xf32>, |
| 14 | + %off0 : index, %off1 : index, |
| 15 | + %sz0 : index, %sz1 : index, |
| 16 | + %st0 : index, %st1 : index) -> tensor<?x?xf32> { |
| 17 | + |
| 18 | + // CHECK: %[[EXTRACTED_SLICE:.*]] = tensor.extract_slice %[[O]][%[[OFF0]], %[[OFF1]]] [2, 3] [%[[ST0]], %[[ST1]]] |
| 19 | + // CHECK-SAME: : tensor<?x?xf32> to tensor<2x3xf32> |
| 20 | + // CHECK: linalg.copy ins(%[[I]] : tensor<2x3xf32>) outs(%[[EXTRACTED_SLICE]] : tensor<2x3xf32>) -> tensor<2x3xf32> |
| 21 | + // CHECK: tensor.insert_slice %{{.*}} into %[[O]][%[[OFF0]], %[[OFF1]]] [2, 3] [%[[ST0]], %[[ST1]]] |
| 22 | + // CHECK-SAME: : tensor<2x3xf32> into tensor<?x?xf32> |
| 23 | + |
| 24 | + %0 = tensor.insert_slice %I into %O[%off0, %off1] [2, 3] [%st0, %st1] |
| 25 | + : tensor<2x3xf32> into tensor<?x?xf32> |
| 26 | + return %0 : tensor<?x?xf32> |
| 27 | +} |
| 28 | + |
| 29 | +transform.sequence failures(propagate) { |
| 30 | +^bb1(%arg1: !transform.any_op): |
| 31 | + %0 = transform.structured.match ops{["tensor.insert_slice"]} in %arg1 : (!transform.any_op) -> !transform.any_op |
| 32 | + %1 = transform.structured.insert_slice_to_copy %0 : (!transform.any_op) -> !transform.any_op |
| 33 | + transform.cast %1 : !transform.any_op to !transform.op<"linalg.copy"> |
| 34 | +} |
| 35 | + |
| 36 | +// ----- |
| 37 | + |
| 38 | +// CHECK-LABEL: func @insert_slice_to_copy |
| 39 | + // CHECK-SAME: %[[I:[0-9a-zA-Z]+]]: tensor<?x?xf32> |
| 40 | + // CHECK-SAME: %[[O:[0-9a-zA-Z]+]]: tensor<?x?xf32>, |
| 41 | + // CHECK-SAME: %[[OFF0:[0-9a-zA-Z]+]]: index, |
| 42 | + // CHECK-SAME: %[[OFF1:[0-9a-zA-Z]+]]: index, |
| 43 | + // CHECK-SAME: %[[SZ0:[0-9a-zA-Z]+]]: index, |
| 44 | + // CHECK-SAME: %[[SZ1:[0-9a-zA-Z]+]]: index, |
| 45 | + // CHECK-SAME: %[[ST0:[0-9a-zA-Z]+]]: index, |
| 46 | + // CHECK-SAME: %[[ST1:[0-9a-zA-Z]+]]: index) |
| 47 | +func.func @insert_slice_to_copy( |
| 48 | + %I : tensor<?x?xf32>, %O : tensor<?x?xf32>, |
| 49 | + %off0 : index, %off1 : index, |
| 50 | + %sz0 : index, %sz1 : index, |
| 51 | + %st0 : index, %st1 : index) -> tensor<?x?xf32> { |
| 52 | + |
| 53 | + // CHECK: %[[EXTRACTED_SLICE:.*]] = tensor.extract_slice %[[O]][%[[OFF0]], %[[OFF1]]] [%[[SZ0]], %[[SZ1]]] [1, 1] |
| 54 | + // CHECK-SAME: : tensor<?x?xf32> to tensor<?x?xf32> |
| 55 | + // CHECK: linalg.copy ins(%[[I]] : tensor<?x?xf32>) outs(%[[EXTRACTED_SLICE]] : tensor<?x?xf32>) -> tensor<?x?xf32> |
| 56 | + // CHECK: tensor.insert_slice %{{.*}} into %[[O]][%[[OFF0]], %[[OFF1]]] [%[[SZ0]], %[[SZ1]]] [1, 1] |
| 57 | + // CHECK-SAME: : tensor<?x?xf32> into tensor<?x?xf32> |
| 58 | + |
| 59 | + %0 = tensor.insert_slice %I into %O[%off0, %off1] [%sz0, %sz1] [1, 1] |
| 60 | + : tensor<?x?xf32> into tensor<?x?xf32> |
| 61 | + return %0 : tensor<?x?xf32> |
| 62 | +} |
| 63 | + |
| 64 | +transform.sequence failures(propagate) { |
| 65 | +^bb1(%arg1: !transform.any_op): |
| 66 | + %0 = transform.structured.match ops{["tensor.insert_slice"]} in %arg1 : (!transform.any_op) -> !transform.any_op |
| 67 | + %1 = transform.structured.insert_slice_to_copy %0 : (!transform.any_op) -> !transform.any_op |
| 68 | + transform.cast %1 : !transform.any_op to !transform.op<"linalg.copy"> |
| 69 | +} |
| 70 | + |
| 71 | +// ----- |
| 72 | +// CHECK-LABEL: func @insert_slice_to_copy |
| 73 | + // CHECK-SAME: %[[I:.*]]: tensor<2x3xf32> |
| 74 | + // CHECK-SAME: %[[O:.*]]: tensor<?x?xf32>, |
| 75 | + // CHECK-SAME: %[[OFF0:[0-9a-zA-Z]+]]: index, |
| 76 | + // CHECK-SAME: %[[OFF1:[0-9a-zA-Z]+]]: index, |
| 77 | + // CHECK-SAME: %[[SZ0:[0-9a-zA-Z]+]]: index, |
| 78 | + // CHECK-SAME: %[[SZ1:[0-9a-zA-Z]+]]: index, |
| 79 | + // CHECK-SAME: %[[ST0:[0-9a-zA-Z]+]]: index, |
| 80 | + // CHECK-SAME: %[[ST1:[0-9a-zA-Z]+]]: index) |
| 81 | +func.func @insert_slice_to_copy( |
| 82 | + %I : tensor<2x3xf32>, %O : tensor<?x?xf32>, |
| 83 | + %off0 : index, %off1 : index, |
| 84 | + %sz0 : index, %sz1 : index, |
| 85 | + %st0 : index, %st1 : index) -> tensor<?x?xf32> { |
| 86 | + |
| 87 | + // CHECK: %[[EXTRACTED_SLICE:.*]] = tensor.extract_slice %[[O]][%[[OFF0]], %[[OFF1]]] [2, 3] [%[[ST0]], %[[ST1]]] |
| 88 | + // CHECK-SAME: : tensor<?x?xf32> to tensor<2x3xf32> |
| 89 | + // CHECK: linalg.copy ins(%[[I]] : tensor<2x3xf32>) outs(%[[EXTRACTED_SLICE]] : tensor<2x3xf32>) -> tensor<2x3xf32> |
| 90 | + // CHECK-NOT: linalg.copy |
| 91 | + // CHECK: tensor.insert_slice %{{.*}} into %[[O]][%[[OFF0]], %[[OFF1]]] [2, 3] [%[[ST0]], %[[ST1]]] |
| 92 | + // CHECK-SAME: : tensor<2x3xf32> into tensor<?x?xf32> |
| 93 | + |
| 94 | + %extracted_slice = tensor.extract_slice %O[%off0, %off1] [2, 3] [%st0, %st1] |
| 95 | + : tensor<?x?xf32> to tensor<2x3xf32> |
| 96 | + %0 = linalg.copy ins(%I : tensor<2x3xf32>) outs(%extracted_slice |
| 97 | + : tensor<2x3xf32>) -> tensor<2x3xf32> |
| 98 | + %inserted_slice = tensor.insert_slice %0 into %O[%off0, %off1] [2, 3] [%st0, %st1] |
| 99 | + : tensor<2x3xf32> into tensor<?x?xf32> |
| 100 | + |
| 101 | + return %inserted_slice : tensor<?x?xf32> |
| 102 | +} |
| 103 | + |
| 104 | +transform.sequence failures(propagate) { |
| 105 | +^bb1(%arg1: !transform.any_op): |
| 106 | + %0 = transform.structured.match ops{["tensor.insert_slice"]} in %arg1 : (!transform.any_op) -> !transform.any_op |
| 107 | + %1 = transform.structured.insert_slice_to_copy %0 : (!transform.any_op) -> !transform.any_op |
| 108 | + transform.cast %1 : !transform.any_op to !transform.op<"linalg.copy"> |
| 109 | +} |
| 110 | + |
0 commit comments