|
| 1 | +// RUN: mlir-opt -transform-interpreter %s --split-input-file --allow-unregistered-dialect -verify-diagnostics | FileCheck %s |
| 2 | + |
| 3 | +// CHECK: func.func @linalg_copy_to_memref_copy(%[[INPUT:.*]]: memref<128x64xf32>, %[[OUTPUT:.*]]: memref<128x64xf32>) { |
| 4 | +// CHECK: memref.copy %[[INPUT]], %[[OUTPUT]] : memref<128x64xf32> to memref<128x64xf32> |
| 5 | +// CHECK: return |
| 6 | +// CHECK: } |
| 7 | + |
| 8 | +func.func @linalg_copy_to_memref_copy(%input : memref<128x64xf32>, %output : memref<128x64xf32>) { |
| 9 | + linalg.copy ins(%input : memref<128x64xf32>) outs(%output : memref<128x64xf32>) |
| 10 | + return |
| 11 | +} |
| 12 | + |
| 13 | +module attributes {transform.with_named_sequence} { |
| 14 | + transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) { |
| 15 | + %0 = transform.structured.match ops{["linalg.copy"]} in %arg1 : (!transform.any_op) -> !transform.any_op |
| 16 | + %1 = transform.structured.linalg_copy_to_memref %0 : (!transform.any_op) -> !transform.any_op |
| 17 | + transform.yield |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +// ----- |
| 22 | + |
| 23 | +// CHECK: func.func @linalg_copy_to_memref_copy_strides(%[[INPUT:.*]]: memref<128x32xf32>, %[[OUTPUT:.*]]: memref<128x64xf32>) { |
| 24 | +// CHECK: %[[ALLOC:.*]] = memref.alloc() {alignment = 64 : i64} : memref<128x64xf32> |
| 25 | +// CHECK: %[[SUBVIEW:.*]] = memref.subview %[[ALLOC]][0, 32] [128, 32] [1, 1] : memref<128x64xf32> to memref<128x32xf32, strided<[64, 1], offset: 32>> |
| 26 | +// CHECK: memref.copy %[[INPUT]], %[[SUBVIEW]] : memref<128x32xf32> to memref<128x32xf32, strided<[64, 1], offset: 32>> |
| 27 | +// CHECK: return |
| 28 | +// CHECK: } |
| 29 | + |
| 30 | +func.func @linalg_copy_to_memref_copy_strides(%input : memref<128x32xf32>, %output : memref<128x64xf32>) { |
| 31 | + %alloc = memref.alloc() {alignment = 64 : i64} : memref<128x64xf32> |
| 32 | + %subview = memref.subview %alloc[0, 32] [128, 32] [1, 1] : memref<128x64xf32> to memref<128x32xf32, strided<[64, 1], offset: 32>> |
| 33 | + linalg.copy ins(%input : memref<128x32xf32>) outs(%subview : memref<128x32xf32, strided<[64, 1], offset: 32>>) |
| 34 | + return |
| 35 | +} |
| 36 | + |
| 37 | +module attributes {transform.with_named_sequence} { |
| 38 | + transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) { |
| 39 | + %0 = transform.structured.match ops{["linalg.copy"]} in %arg1 : (!transform.any_op) -> !transform.any_op |
| 40 | + %1 = transform.structured.linalg_copy_to_memref %0 : (!transform.any_op) -> !transform.any_op |
| 41 | + transform.yield |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +// ----- |
| 46 | + |
| 47 | +func.func @linalg_copy_to_memref_copy_tensors(%input : tensor<128x64xf32>, %output : tensor<128x64xf32>) -> tensor<128x64xf32> { |
| 48 | + // expected-note @below {{target op}} |
| 49 | + %0 = linalg.copy ins(%input : tensor<128x64xf32>) outs(%output : tensor<128x64xf32>) -> tensor<128x64xf32> |
| 50 | + return %0 : tensor<128x64xf32> |
| 51 | +} |
| 52 | + |
| 53 | +module attributes {transform.with_named_sequence} { |
| 54 | + transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) { |
| 55 | + %0 = transform.structured.match ops{["linalg.copy"]} in %arg1 : (!transform.any_op) -> !transform.any_op |
| 56 | + // expected-error @below {{cannot transform a linalg.copy on tensors into a memref.copy}} |
| 57 | + %1 = transform.structured.linalg_copy_to_memref %0 : (!transform.any_op) -> !transform.any_op |
| 58 | + transform.yield |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +// ----- |
| 63 | + |
| 64 | +func.func @linalg_copy_to_memref_copy_different_element(%input : memref<128x64xf32>, %output : memref<128x64xf64>) { |
| 65 | + // expected-note @below {{target op}} |
| 66 | + linalg.copy ins(%input : memref<128x64xf32>) outs(%output : memref<128x64xf64>) |
| 67 | + return |
| 68 | +} |
| 69 | + |
| 70 | +module attributes {transform.with_named_sequence} { |
| 71 | + transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) { |
| 72 | + %0 = transform.structured.match ops{["linalg.copy"]} in %arg1 : (!transform.any_op) -> !transform.any_op |
| 73 | + // expected-error @below {{cannot transform a linalg.copy with different source and destination element types}} |
| 74 | + %1 = transform.structured.linalg_copy_to_memref %0 : (!transform.any_op) -> !transform.any_op |
| 75 | + transform.yield |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +// ----- |
| 80 | + |
| 81 | +func.func @linalg_copy_to_memref_copy_scalar(%input : f64, %output : memref<128x64xf64>) { |
| 82 | + // expected-note @below {{target op}} |
| 83 | + linalg.copy ins(%input : f64) outs(%output : memref<128x64xf64>) |
| 84 | + return |
| 85 | +} |
| 86 | + |
| 87 | +module attributes {transform.with_named_sequence} { |
| 88 | + transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) { |
| 89 | + %0 = transform.structured.match ops{["linalg.copy"]} in %arg1 : (!transform.any_op) -> !transform.any_op |
| 90 | + // expected-error @below {{cannot transform a linalg.copy which input has no shape}} |
| 91 | + %1 = transform.structured.linalg_copy_to_memref %0 : (!transform.any_op) -> !transform.any_op |
| 92 | + transform.yield |
| 93 | + } |
| 94 | +} |
0 commit comments