|
| 1 | +// RUN: mlir-opt %s -transform-interpreter -canonicalize --split-input-file -verify-diagnostics| FileCheck %s |
| 2 | + |
| 3 | +func.func @conv2d(%arg0: tensor<2x10x10x5xf32>, %arg1: tensor<2x3x3x5xf32>, %arg2: tensor<1xf32>, %arg3: tensor<2x8x8x2xf32>) -> tensor<2x8x8x2xf32> { |
| 4 | + %0 = linalg.conv_2d_nhwc_fhwc {dilations = dense<1> : tensor<2xi64>, strides = dense<1> : tensor<2xi64>} ins(%arg0, %arg1 : tensor<2x10x10x5xf32>, tensor<2x3x3x5xf32>) outs(%arg3 : tensor<2x8x8x2xf32>) -> tensor<2x8x8x2xf32> |
| 5 | + return %0 : tensor<2x8x8x2xf32> |
| 6 | +} |
| 7 | + |
| 8 | +module attributes {transform.with_named_sequence} { |
| 9 | + transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) { |
| 10 | + %0 = transform.structured.match ops{["linalg.conv_2d_nhwc_fhwc"]} in %arg1 : (!transform.any_op) -> !transform.any_op |
| 11 | + %1 = transform.structured.winograd_conv2d %0 { m = 4, r = 3 } : (!transform.any_op) -> (!transform.any_op) |
| 12 | + transform.yield |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +// CHECK-LABEL: func.func @conv2d |
| 17 | +// CHECK: linalg.winograd_filter_transform m(4) r(3) |
| 18 | +// CHECK: linalg.winograd_input_transform m(4) r(3) |
| 19 | +// CHECK: linalg.batch_matmul |
| 20 | +// CHECK: linalg.winograd_output_transform m(4) r(3) |
| 21 | + |
| 22 | +// ----- |
| 23 | + |
| 24 | +func.func @conv2d_unaligned(%arg0: tensor<2x11x11x5xf32>, %arg1: tensor<2x3x3x5xf32>, %arg2: tensor<1xf32>, %arg3: tensor<2x9x9x2xf32>) -> tensor<2x9x9x2xf32> { |
| 25 | + %0 = linalg.conv_2d_nhwc_fhwc {dilations = dense<1> : tensor<2xi64>, strides = dense<1> : tensor<2xi64>} ins(%arg0, %arg1 : tensor<2x11x11x5xf32>, tensor<2x3x3x5xf32>) outs(%arg3 : tensor<2x9x9x2xf32>) -> tensor<2x9x9x2xf32> |
| 26 | + return %0 : tensor<2x9x9x2xf32> |
| 27 | +} |
| 28 | + |
| 29 | +module attributes {transform.with_named_sequence} { |
| 30 | + transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) { |
| 31 | + %0 = transform.structured.match ops{["linalg.conv_2d_nhwc_fhwc"]} in %arg1 : (!transform.any_op) -> !transform.any_op |
| 32 | + %1 = transform.structured.winograd_conv2d %0 { m = 4, r = 3 } : (!transform.any_op) -> (!transform.any_op) |
| 33 | + transform.yield |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +// CHECK-LABEL: func.func @conv2d_unaligned |
| 38 | +// CHECK: linalg.winograd_filter_transform m(4) r(3) |
| 39 | +// CHECK: tensor.pad |
| 40 | +// CHECK-SAME: low[0, 0, 0, 0] high[0, 3, 3, 0] |
| 41 | +// CHECK: linalg.winograd_input_transform m(4) r(3) |
| 42 | +// CHECK: tensor.pad |
| 43 | +// CHECK-SAME: low[0, 0, 0, 0] high[0, 3, 3, 0] |
| 44 | +// CHECK: linalg.winograd_output_transform m(4) r(3) |
| 45 | + |
| 46 | +// ----- |
| 47 | + |
| 48 | +func.func @conv2d_unsupported(%arg0: tensor<2x10x10x5xf32>, %arg1: tensor<3x3x5x2xf32>, %arg2: tensor<1xf32>, %arg3: tensor<2x8x8x2xf32>) -> tensor<2x8x8x2xf32> { |
| 49 | + %0 = linalg.conv_2d_nhwc_hwcf {dilations = dense<1> : tensor<2xi64>, strides = dense<1> : tensor<2xi64>} ins(%arg0, %arg1 : tensor<2x10x10x5xf32>, tensor<3x3x5x2xf32>) outs(%arg3 : tensor<2x8x8x2xf32>) -> tensor<2x8x8x2xf32> |
| 50 | + return %0 : tensor<2x8x8x2xf32> |
| 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.conv_2d_nhwc_hwcf"]} in %arg1 : (!transform.any_op) -> !transform.any_op |
| 56 | + // expected-error @+1 {{this operation is not supported to convert to Winograd Conv2D}} |
| 57 | + %1 = transform.structured.winograd_conv2d %0 { m = 4, r = 3 } : (!transform.any_op) -> (!transform.any_op) |
| 58 | + transform.yield |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +// ----- |
| 63 | + |
| 64 | +func.func @conv2d(%arg0: tensor<2x?x?x5xf32>, %arg1: tensor<2x3x3x5xf32>, %arg2: tensor<1xf32>, %arg3: tensor<2x?x?x2xf32>) -> tensor<2x?x?x2xf32> { |
| 65 | + %0 = linalg.conv_2d_nhwc_fhwc {dilations = dense<1> : tensor<2xi64>, strides = dense<1> : tensor<2xi64>} ins(%arg0, %arg1 : tensor<2x?x?x5xf32>, tensor<2x3x3x5xf32>) outs(%arg3 : tensor<2x?x?x2xf32>) -> tensor<2x?x?x2xf32> |
| 66 | + return %0 : tensor<2x?x?x2xf32> |
| 67 | +} |
| 68 | + |
| 69 | +module attributes {transform.with_named_sequence} { |
| 70 | + transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) { |
| 71 | + %0 = transform.structured.match ops{["linalg.conv_2d_nhwc_fhwc"]} in %arg1 : (!transform.any_op) -> !transform.any_op |
| 72 | + // expected-error @+1 {{apply Winograd Conv2D failed}} |
| 73 | + %1 = transform.structured.winograd_conv2d %0 { m = 4, r = 3 } : (!transform.any_op) -> (!transform.any_op) |
| 74 | + transform.yield |
| 75 | + } |
| 76 | +} |
0 commit comments