|
| 1 | +// RUN: iree-opt --split-input-file --mlir-print-local-scope -iree-global-opt-convert-strided-contraction-to-contraction %s | FileCheck %s |
| 2 | + |
| 3 | +util.func public @strided_from_output_static(%input: tensor<2x118x182x448xbf16>, %filter: tensor<896x448xbf16>) -> tensor<2x59x91x896xf32> { |
| 4 | + %cst = arith.constant 0.000000e+00 : f32 |
| 5 | + %0 = tensor.empty() : tensor<2x59x91x896xf32> |
| 6 | + %1 = linalg.fill ins(%cst : f32) outs(%0 : tensor<2x59x91x896xf32>) -> tensor<2x59x91x896xf32> |
| 7 | + %2 = linalg.generic {indexing_maps = [affine_map<(d0, d1, d2, d3, d4) -> (d0, 2 * d1, d2 * 2, d4)>, affine_map<(d0, d1, d2, d3, d4) -> (d3, d4)>, affine_map<(d0, d1, d2, d3, d4) -> (d0, d1, d2, d3)>], iterator_types = ["parallel", "parallel", "parallel", "parallel", "reduction"]} ins(%input, %filter : tensor<2x118x182x448xbf16>, tensor<896x448xbf16>) outs(%1 : tensor<2x59x91x896xf32>) { |
| 8 | + ^bb0(%in: bf16, %in_0: bf16, %out: f32): |
| 9 | + %3 = arith.extf %in : bf16 to f32 |
| 10 | + %4 = arith.extf %in_0 : bf16 to f32 |
| 11 | + %5 = arith.mulf %3, %4 : f32 |
| 12 | + %6 = arith.addf %out, %5 : f32 |
| 13 | + linalg.yield %6 : f32 |
| 14 | + } -> tensor<2x59x91x896xf32> |
| 15 | + util.return %2 : tensor<2x59x91x896xf32> |
| 16 | +} |
| 17 | + |
| 18 | +// CHECK-LABEL: @strided_from_output_static( |
| 19 | +// CHECK-SAME: %[[INPUT:.*]]: tensor<2x118x182x448xbf16> |
| 20 | +// CHECK-SAME: %[[FILTER:.*]]: tensor<896x448xbf16> |
| 21 | +// CHECK: %[[SLICE:.*]] = tensor.extract_slice %[[INPUT]][0, 0, 0, 0] [2, 59, 91, 448] [1, 2, 2, 1] |
| 22 | +// CHECK-SAME: tensor<2x118x182x448xbf16> to tensor<2x59x91x448xbf16> |
| 23 | +// CHECK: %[[GEN:.*]] = linalg.generic |
| 24 | +// CHECK-SAME: affine_map<(d0, d1, d2, d3, d4) -> (d0, d1, d2, d4)> |
| 25 | +// CHECK-SAME: affine_map<(d0, d1, d2, d3, d4) -> (d3, d4)> |
| 26 | +// CHECK-SAME: affine_map<(d0, d1, d2, d3, d4) -> (d0, d1, d2, d3)> |
| 27 | +// CHECK-SAME: ins(%[[SLICE]], %[[FILTER]] |
| 28 | +// CHECK: util.return %[[GEN]] |
| 29 | + |
| 30 | + |
| 31 | +// ----- |
| 32 | + |
| 33 | +util.func public @strided_from_output_dynamic_batch(%input: tensor<?x118x182x448xbf16>, %filter: tensor<896x448xbf16>) -> tensor<?x59x91x896xf32> { |
| 34 | + %cst = arith.constant 0.000000e+00 : f32 |
| 35 | + %c0 = arith.constant 0 : index |
| 36 | + %dim = tensor.dim %input, %c0 : tensor<?x118x182x448xbf16> |
| 37 | + %0 = tensor.empty(%dim) : tensor<?x59x91x896xf32> |
| 38 | + %1 = linalg.fill ins(%cst : f32) outs(%0 : tensor<?x59x91x896xf32>) -> tensor<?x59x91x896xf32> |
| 39 | + %2 = linalg.generic {indexing_maps = [affine_map<(d0, d1, d2, d3, d4) -> (d0, d1 * 2, d2 * 2, d4)>, affine_map<(d0, d1, d2, d3, d4) -> (d3, d4)>, affine_map<(d0, d1, d2, d3, d4) -> (d0, d1, d2, d3)>], iterator_types = ["parallel", "parallel", "parallel", "parallel", "reduction"]} ins(%input, %filter : tensor<?x118x182x448xbf16>, tensor<896x448xbf16>) outs(%1 : tensor<?x59x91x896xf32>) { |
| 40 | + ^bb0(%in: bf16, %in_0: bf16, %out: f32): |
| 41 | + %3 = arith.extf %in : bf16 to f32 |
| 42 | + %4 = arith.extf %in_0 : bf16 to f32 |
| 43 | + %5 = arith.mulf %3, %4 : f32 |
| 44 | + %6 = arith.addf %out, %5 : f32 |
| 45 | + linalg.yield %6 : f32 |
| 46 | + } -> tensor<?x59x91x896xf32> |
| 47 | + util.return %2 : tensor<?x59x91x896xf32> |
| 48 | +} |
| 49 | + |
| 50 | +// CHECK-LABEL: @strided_from_output_dynamic_batch( |
| 51 | +// CHECK-SAME: %[[INPUT:.*]]: tensor<?x118x182x448xbf16> |
| 52 | +// CHECK-SAME: %[[FILTER:.*]]: tensor<896x448xbf16> |
| 53 | +// CHECK: %[[SLICE:.*]] = tensor.extract_slice %[[INPUT]][0, 0, 0, 0] [%[[DIM:.*]], 59, 91, 448] [1, 2, 2, 1] |
| 54 | +// CHECK-SAME: tensor<?x118x182x448xbf16> to tensor<?x59x91x448xbf16> |
| 55 | +// CHECK: %[[GEN:.*]] = linalg.generic |
| 56 | +// CHECK-SAME: affine_map<(d0, d1, d2, d3, d4) -> (d0, d1, d2, d4)> |
| 57 | +// CHECK-SAME: affine_map<(d0, d1, d2, d3, d4) -> (d3, d4)> |
| 58 | +// CHECK-SAME: affine_map<(d0, d1, d2, d3, d4) -> (d0, d1, d2, d3)> |
| 59 | +// CHECK-SAME: ins(%[[SLICE]], %[[FILTER]] |
| 60 | +// CHECK: util.return %[[GEN]] |
| 61 | + |
| 62 | +// ----- |
| 63 | + |
| 64 | +util.func public @strided_from_output_partial_conv(%input: tensor<2x118x182x448xbf16>, %filter: tensor<896x2x448xbf16>) -> tensor<2x59x91x896xf32> { |
| 65 | + %cst = arith.constant 0.000000e+00 : f32 |
| 66 | + %0 = tensor.empty() : tensor<2x59x91x896xf32> |
| 67 | + %1 = linalg.fill ins(%cst : f32) outs(%0 : tensor<2x59x91x896xf32>) -> tensor<2x59x91x896xf32> |
| 68 | + %2 = linalg.generic {indexing_maps = [affine_map<(d0, d1, d2, d3, d4, d5) -> (d0, d1 * 2, d2 * 2 + d4, d5)>, affine_map<(d0, d1, d2, d3, d4, d5) -> (d3, d4, d5)>, affine_map<(d0, d1, d2, d3, d4, d5) -> (d0, d1, d2, d3)>], iterator_types = ["parallel", "parallel", "parallel", "parallel", "reduction", "reduction"]} ins(%input, %filter : tensor<2x118x182x448xbf16>, tensor<896x2x448xbf16>) outs(%1 : tensor<2x59x91x896xf32>) { |
| 69 | + ^bb0(%in: bf16, %in_0: bf16, %out: f32): |
| 70 | + %3 = arith.extf %in : bf16 to f32 |
| 71 | + %4 = arith.extf %in_0 : bf16 to f32 |
| 72 | + %5 = arith.mulf %3, %4 : f32 |
| 73 | + %6 = arith.addf %out, %5 : f32 |
| 74 | + linalg.yield %6 : f32 |
| 75 | + } -> tensor<2x59x91x896xf32> |
| 76 | + util.return %2 : tensor<2x59x91x896xf32> |
| 77 | +} |
| 78 | + |
| 79 | +// CHECK-LABEL: @strided_from_output_partial_conv |
| 80 | +// CHECK-SAME: %[[INPUT:.*]]: tensor<2x118x182x448xbf16> |
| 81 | +// CHECK-SAME: %[[FILTER:.*]]: tensor<896x2x448xbf16> |
| 82 | +// CHECK: %[[SLICE:.*]] = tensor.extract_slice %[[INPUT]][0, 0, 0, 0] [2, 59, 182, 448] [1, 2, 1, 1] |
| 83 | +// CHECK-SAME: tensor<2x118x182x448xbf16> to tensor<2x59x182x448xbf16> |
| 84 | +// CHECK: linalg.generic |
| 85 | +// CHECK-SAME: affine_map<(d0, d1, d2, d3, d4, d5) -> (d0, d1, d2 * 2 + d4, d5)> |
| 86 | +// CHECK-SAME: affine_map<(d0, d1, d2, d3, d4, d5) -> (d3, d4, d5)> |
| 87 | +// CHECK-SAME: affine_map<(d0, d1, d2, d3, d4, d5) -> (d0, d1, d2, d3)> |
| 88 | +// CHECK-SAME: ins(%[[SLICE]], %[[FILTER]] |
| 89 | + |
| 90 | +// ----- |
| 91 | + |
| 92 | +util.func public @strided_from_filter_static(%input: tensor<896x118x16xbf16>, %filter: tensor<448x59x16xbf16>) -> tensor<896x448xf32> { |
| 93 | + %cst = arith.constant 0.000000e+00 : f32 |
| 94 | + %0 = tensor.empty() : tensor<896x448xf32> |
| 95 | + %1 = linalg.fill ins(%cst : f32) outs(%0 : tensor<896x448xf32>) -> tensor<896x448xf32> |
| 96 | + %2 = linalg.generic {indexing_maps = [affine_map<(d0, d1, d2, d3) -> (d0, d2 * 2, d3)>, affine_map<(d0, d1, d2, d3) -> (d1, d2, d3)>, affine_map<(d0, d1, d2, d3) -> (d0, d1)>], iterator_types = ["parallel", "parallel", "reduction", "reduction"]} ins(%input, %filter : tensor<896x118x16xbf16>, tensor<448x59x16xbf16>) outs(%1 : tensor<896x448xf32>) { |
| 97 | + ^bb0(%in: bf16, %in_0: bf16, %out: f32): |
| 98 | + %3 = arith.extf %in : bf16 to f32 |
| 99 | + %4 = arith.extf %in_0 : bf16 to f32 |
| 100 | + %5 = arith.mulf %3, %4 : f32 |
| 101 | + %6 = arith.addf %out, %5 : f32 |
| 102 | + linalg.yield %6 : f32 |
| 103 | + } -> tensor<896x448xf32> |
| 104 | + util.return %2 : tensor<896x448xf32> |
| 105 | +} |
| 106 | + |
| 107 | +// CHECK-LABEL: @strided_from_filter_static( |
| 108 | +// CHECK-SAME: %[[INPUT:.*]]: tensor<896x118x16xbf16> |
| 109 | +// CHECK-SAME: %[[FILTER:.*]]: tensor<448x59x16xbf16> |
| 110 | +// CHECK: %[[SLICE:.*]] = tensor.extract_slice %[[INPUT]][0, 0, 0] [896, 59, 16] [1, 2, 1] |
| 111 | +// CHECK-SAME: tensor<896x118x16xbf16> to tensor<896x59x16xbf16> |
| 112 | +// CHECK: %[[GEN:.*]] = linalg.generic |
| 113 | +// CHECK-SAME: affine_map<(d0, d1, d2, d3) -> (d0, d2, d3)> |
| 114 | +// CHECK-SAME: affine_map<(d0, d1, d2, d3) -> (d1, d2, d3)> |
| 115 | +// CHECK-SAME: affine_map<(d0, d1, d2, d3) -> (d0, d1)> |
| 116 | +// CHECK-SAME: ins(%[[SLICE]], %[[FILTER]] |
| 117 | +// CHECK: util.return %[[GEN]] |
0 commit comments