| 1 |
// RUN: mlir-opt -split-input-file -transform-interpreter %s | FileCheck %s |
| 2 |
|
| 3 |
///---------------------------------------------------------------------------------------- |
| 4 |
/// Tests for vectorizing depthwise convolutions (with patterns) with the |
| 5 |
/// flattening of the channel dim enabled. This approach is beneficial when the |
| 6 |
/// number of channel dimensions is low. |
| 7 |
///---------------------------------------------------------------------------------------- |
| 8 |
|
| 9 |
func.func @depthwise_conv1d_nwc_wc_1x8x3xi8_tensor(%input: tensor<1x8x3xi8>, |
| 10 |
%filter: tensor<1x3xi8>, |
| 11 |
%output: tensor<1x8x3xi8>) -> (tensor<1x8x3xi8>) { |
| 12 |
%res = linalg.depthwise_conv_1d_nwc_wc |
| 13 |
{dilations = dense<1> : vector<1xi64>, |
| 14 |
strides = dense<1> : vector<1xi64>} |
| 15 |
ins(%input, %filter : tensor<1x8x3xi8>, tensor<1x3xi8>) |
| 16 |
outs(%output : tensor<1x8x3xi8>) -> tensor<1x8x3xi8> |
| 17 |
return %res : tensor<1x8x3xi8> |
| 18 |
} |
| 19 |
|
| 20 |
module attributes {transform.with_named_sequence} { |
| 21 |
transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) { |
| 22 |
%0 = transform.structured.match ops{["linalg.depthwise_conv_1d_nwc_wc"]} in %arg0 : (!transform.any_op) -> !transform.any_op |
| 23 |
%1 = transform.get_parent_op %0 {isolated_from_above} : (!transform.any_op) -> !transform.any_op |
| 24 |
%2 = transform.structured.vectorize_children_and_apply_patterns %1 {flatten_1d_depthwise_conv} : (!transform.any_op) -> !transform.any_op |
| 25 |
transform.yield |
| 26 |
} |
| 27 |
} |
| 28 |
// CHECK-LABEL: func.func @depthwise_conv1d_nwc_wc_1x8x3xi8_tensor |
| 29 |
// CHECK-SAME: %[[INPUT:.*]]: tensor<1x8x3xi8>, |
| 30 |
// CHECK-SAME: %[[FILTER:.*]]: tensor<1x3xi8>, |
| 31 |
// CHECK-SAME: %[[OUTPUT:.*]]: tensor<1x8x3xi8>) -> tensor<1x8x3xi8> { |
| 32 |
|
| 33 |
// CHECK-DAG: %[[C0_IDX:.*]] = arith.constant 0 : index |
| 34 |
|
| 35 |
/// Read the whole data in one shot. |
| 36 |
// CHECK: %[[V_INPUT_R:.*]] = vector.transfer_read %[[INPUT]][%[[C0_IDX]], %[[C0_IDX]], %[[C0_IDX]]] |
| 37 |
// CHECK: %[[V_FILTER_R:.*]] = vector.transfer_read %[[FILTER]][%[[C0_IDX]], %[[C0_IDX]]] |
| 38 |
// CHECK: %[[V_OUTPUT_R:.*]] = vector.transfer_read %[[OUTPUT]][%[[C0_IDX]], %[[C0_IDX]], %[[C0_IDX]]] |
| 39 |
|
| 40 |
// CHECK: %[[V_FILTER_0:.*]] = vector.extract %[[V_FILTER_R]][0] : vector<3xi8> from vector<1x3xi8> |
| 41 |
|
| 42 |
/// w == 0, kw = 0 |
| 43 |
// CHECK: %[[SC_INPUT:.*]] = vector.shape_cast %[[V_INPUT_R]] : vector<1x8x3xi8> to vector<1x24xi8> |
| 44 |
// CHECK: %[[SC_OUTPUT:.*]] = vector.shape_cast %[[V_OUTPUT_R]] : vector<1x8x3xi8> to vector<1x24xi8> |
| 45 |
// CHECK: %[[SH_FILTER_0:.*]] = vector.shuffle %[[V_FILTER_0]], %[[V_FILTER_0]] |
| 46 |
// CHECK-SAME: [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2] : vector<3xi8>, vector<3xi8> |
| 47 |
// CHECK: %[[B_FILTER:.*]] = vector.broadcast %[[SH_FILTER_0]] : vector<24xi8> to vector<1x24xi8> |
| 48 |
// CHECK: %[[MULI:.*]] = arith.muli %[[SC_INPUT]], %[[B_FILTER]] : vector<1x24xi8> |
| 49 |
// CHECK: %[[ADDI:.*]] = arith.addi %[[MULI]], %[[SC_OUTPUT]] : vector<1x24xi8> |
| 50 |
|
| 51 |
// Write the result back in one shot. |
| 52 |
// CHECK: %[[SC_ADDI:.*]] = vector.shape_cast %[[ADDI]] : vector<1x24xi8> to vector<1x8x3xi8> |
| 53 |
// CHECK: vector.transfer_write %[[SC_ADDI]], %[[OUTPUT]][%[[C0_IDX]], %[[C0_IDX]], %[[C0_IDX]]] |
| 54 |
|
| 55 |
//------ |
| 56 |
|
| 57 |
func.func @depthwise_conv1d_nwc_wc_3x5x4xf32_memref_dillation_2(%input: memref<3x5x4xf32>, |
| 58 |
%filter: memref<2x4xf32>, |
| 59 |
%output: memref<3x2x4xf32>) { |
| 60 |
linalg.depthwise_conv_1d_nwc_wc |
| 61 |
{dilations = dense<2> : tensor<1xi64>, strides = dense<1> : tensor<1xi64>} |
| 62 |
ins(%input, %filter : memref<3x5x4xf32>, memref<2x4xf32>) |
| 63 |
outs(%output : memref<3x2x4xf32>) |
| 64 |
return |
| 65 |
} |
| 66 |
|
| 67 |
// CHECK: func @depthwise_conv1d_nwc_wc_3x5x4xf32_memref_dillation_2 |
| 68 |
// CHECK-SAME: (%[[INPUT:[0-9a-z]+]]: memref<3x5x4xf32>, %[[FILTER:[0-9a-z]+]]: memref<2x4xf32>, %[[OUTPUT:[0-9a-z]+]]: memref<3x2x4xf32>) |
| 69 |
|
| 70 |
// CHECK-DAG: %[[C0:.+]] = arith.constant 0 : index |
| 71 |
// CHECK-DAG: %[[F0:.+]] = arith.constant 0.000000e+00 : f32 |
| 72 |
|
| 73 |
/// Read the whole data in one shot. |
| 74 |
// CHECK-DAG: %[[V_INPUT_R:.+]] = vector.transfer_read %[[INPUT]][%[[C0]], %[[C0]], %[[C0]]] |
| 75 |
// CHECK-DAG: %[[V_FILTER_R:.+]] = vector.transfer_read %[[FILTER]][%[[C0]], %[[C0]]] |
| 76 |
// CHECK-DAG: %[[V_OUTPUT_R:.+]] = vector.transfer_read %[[OUTPUT]][%[[C0]], %[[C0]], %[[C0]]] |
| 77 |
|
| 78 |
// CHECK: %[[V_INPUT_0:.+]] = vector.extract_strided_slice %[[V_INPUT_R]] |
| 79 |
// CHECK-SAME: {offsets = [0, 0, 0], sizes = [3, 2, 4], strides = [1, 1, 1]} : vector<3x4x4xf32> to vector<3x2x4xf32> |
| 80 |
// CHECK: %[[V_INPUT_1:.+]] = vector.extract_strided_slice %[[V_INPUT_R]] |
| 81 |
// CHECK-SAME: {offsets = [0, 2, 0], sizes = [3, 2, 4], strides = [1, 1, 1]} : vector<3x4x4xf32> to vector<3x2x4xf32> |
| 82 |
|
| 83 |
// CHECK: %[[V_FILTER_0:.+]] = vector.extract %[[V_FILTER_R]][0] : vector<4xf32> from vector<2x4xf32> |
| 84 |
// CHECK: %[[V_FILTER_1:.+]] = vector.extract %[[V_FILTER_R]][1] : vector<4xf32> from vector<2x4xf32> |
| 85 |
|
| 86 |
|
| 87 |
/// w == 0, kw = 0 |
| 88 |
// CHECK: %[[SC_V_INPUT_0:.*]] = vector.shape_cast %[[V_INPUT_0]] : vector<3x2x4xf32> to vector<3x8xf32> |
| 89 |
// CHECK: %[[SC_V_OUTPUT_R:.*]] = vector.shape_cast %[[V_OUTPUT_R]] : vector<3x2x4xf32> to vector<3x8xf32> |
| 90 |
// CHECK: %[[SH_FILTER_0:.*]] = vector.shuffle %[[V_FILTER_0]], %[[V_FILTER_0]] |
| 91 |
// CHECK-SAME: [0, 1, 2, 3, 0, 1, 2, 3] : vector<4xf32>, vector<4xf32> |
| 92 |
// CHECK: %[[B_FILTER_0:.*]] = vector.broadcast %[[SH_FILTER_0]] : vector<8xf32> to vector<3x8xf32> |
| 93 |
// CHECK: %[[FMA_0:.*]] = vector.fma %[[SC_V_INPUT_0]], %[[B_FILTER_0]], %[[SC_V_OUTPUT_R]] : vector<3x8xf32> |
| 94 |
|
| 95 |
/// w == 0, kw = 1 |
| 96 |
// CHECK: %[[SC_V_INPUT_1:.*]] = vector.shape_cast %[[V_INPUT_1]] : vector<3x2x4xf32> to vector<3x8xf32> |
| 97 |
// CHECK: %[[SH_FILTER_1:.*]] = vector.shuffle %[[V_FILTER_1]], %[[V_FILTER_1]] |
| 98 |
// CHECK-SAME: [0, 1, 2, 3, 0, 1, 2, 3] : vector<4xf32>, vector<4xf32> |
| 99 |
// CHECK: %[[B_FILTER_1:.*]] = vector.broadcast %[[SH_FILTER_1]] : vector<8xf32> to vector<3x8xf32> |
| 100 |
// CHECK: %[[FMA_1:.*]] = vector.fma %[[SC_V_INPUT_1]], %[[B_FILTER_1]], %[[FMA_0]] : vector<3x8xf32> |
| 101 |
|
| 102 |
// Write the result back in one shot. |
| 103 |
// CHECK: %[[SC_FMA_1:.*]] = vector.shape_cast %[[FMA_1]] : vector<3x8xf32> to vector<3x2x4xf32> |
| 104 |
// CHECK: vector.transfer_write %[[SC_FMA_1]], %[[OUTPUT]][%[[C0]], %[[C0]], %[[C0]]] |
| 105 |
|
| 106 |
|
| 107 |
module attributes {transform.with_named_sequence} { |
| 108 |
transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) { |
| 109 |
%0 = transform.structured.match ops{["linalg.depthwise_conv_1d_nwc_wc"]} in %arg0 : (!transform.any_op) -> !transform.any_op |
| 110 |
%1 = transform.get_parent_op %0 {isolated_from_above} : (!transform.any_op) -> !transform.any_op |
| 111 |
%2 = transform.structured.vectorize_children_and_apply_patterns %1 {flatten_1d_depthwise_conv} : (!transform.any_op) -> !transform.any_op |
| 112 |
transform.yield |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
// ----- |
| 117 |
|
| 118 |
func.func @depthwise_conv1d_nwc_wc_3x5x4xi8_memref_dilation_2(%input: memref<3x5x4xi8>, |
| 119 |
%filter: memref<2x4xi8>, |
| 120 |
%output: memref<3x2x4xi32>) { |
| 121 |
linalg.depthwise_conv_1d_nwc_wc |
| 122 |
{dilations = dense<2> : tensor<1xi64>, strides = dense<1> : tensor<1xi64>} |
| 123 |
ins(%input, %filter : memref<3x5x4xi8>, memref<2x4xi8>) |
| 124 |
outs(%output : memref<3x2x4xi32>) |
| 125 |
return |
| 126 |
} |
| 127 |
|
| 128 |
// CHECK: func @depthwise_conv1d_nwc_wc_3x5x4xi8_memref_dilation_2 |
| 129 |
// CHECK-SAME: (%[[INPUT:[0-9a-z]+]]: memref<3x5x4xi8>, %[[FILTER:[0-9a-z]+]]: memref<2x4xi8>, %[[OUTPUT:[0-9a-z]+]]: memref<3x2x4xi32>) |
| 130 |
|
| 131 |
// CHECK-DAG: %[[C0:.+]] = arith.constant 0 : index |
| 132 |
|
| 133 |
/// Read the whole data in one shot. |
| 134 |
// CHECK-DAG: %[[V_INPUT_R:.+]] = vector.transfer_read %[[INPUT]][%[[C0]], %[[C0]], %[[C0]]] |
| 135 |
// CHECK-DAG: %[[V_FILTER_R:.+]] = vector.transfer_read %[[FILTER]][%[[C0]], %[[C0]]] |
| 136 |
// CHECK-DAG: %[[V_OUTPUT_R:.+]] = vector.transfer_read %[[OUTPUT]][%[[C0]], %[[C0]], %[[C0]]] |
| 137 |
|
| 138 |
// CHECK: %[[V_INPUT_0:.+]] = vector.extract_strided_slice %[[V_INPUT_R]] |
| 139 |
// CHECK-SAME: {offsets = [0, 0, 0], sizes = [3, 2, 4], strides = [1, 1, 1]} : vector<3x4x4xi8> to vector<3x2x4xi8> |
| 140 |
// CHECK: %[[V_INPUT_1:.+]] = vector.extract_strided_slice %[[V_INPUT_R]] |
| 141 |
// CHECK-SAME: {offsets = [0, 2, 0], sizes = [3, 2, 4], strides = [1, 1, 1]} : vector<3x4x4xi8> to vector<3x2x4xi8> |
| 142 |
|
| 143 |
// CHECK: %[[V_FILTER_0:.+]] = vector.extract %[[V_FILTER_R]][0] : vector<4xi8> from vector<2x4xi8> |
| 144 |
// CHECK: %[[V_FILTER_1:.+]] = vector.extract %[[V_FILTER_R]][1] : vector<4xi8> from vector<2x4xi8> |
| 145 |
|
| 146 |
/// w == 0, kw = 0 |
| 147 |
// CHECK: %[[SC_V_INPUT_0:.*]] = vector.shape_cast %[[V_INPUT_0]] : vector<3x2x4xi8> to vector<3x8xi8> |
| 148 |
// CHECK: %[[SC_V_OUTPUT_R:.*]] = vector.shape_cast %[[V_OUTPUT_R]] : vector<3x2x4xi32> to vector<3x8xi32> |
| 149 |
// CHECK: %[[EXT_INPUT_0:.*]] = arith.extsi %[[SC_V_INPUT_0]] : vector<3x8xi8> to vector<3x8xi32> |
| 150 |
// CHECK: %[[SH_FILTER_0:.*]] = vector.shuffle %[[V_FILTER_0]], %[[V_FILTER_0]] |
| 151 |
// CHECK-SAME: [0, 1, 2, 3, 0, 1, 2, 3] : vector<4xi8>, vector<4xi8> |
| 152 |
// CHECK: %[[EXT_FILTER_0:.*]] = arith.extsi %[[SH_FILTER_0]] : vector<8xi8> to vector<8xi32> |
| 153 |
// CHECK: %[[B_FILTER_0:.*]] = vector.broadcast %[[EXT_FILTER_0]] : vector<8xi32> to vector<3x8xi32> |
| 154 |
// CHECK: %[[MUL_0:.*]] = arith.muli %[[EXT_INPUT_0]], %[[B_FILTER_0]] : vector<3x8xi32> |
| 155 |
// CHECK: %[[ADD_0:.*]] = arith.addi %[[MUL_0]], %[[SC_V_OUTPUT_R]] : vector<3x8xi32> |
| 156 |
|
| 157 |
/// w == 0, kw = 1 |
| 158 |
// CHECK: %[[SC_V_INPUT_1:.*]] = vector.shape_cast %[[V_INPUT_1]] : vector<3x2x4xi8> to vector<3x8xi8> |
| 159 |
// CHECK: %[[EXT_INPUT_1:.*]] = arith.extsi %[[SC_V_INPUT_1]] : vector<3x8xi8> to vector<3x8xi32> |
| 160 |
// CHECK: %[[SH_FILTER_1:.*]] = vector.shuffle %[[V_FILTER_1]], %[[V_FILTER_1]] |
| 161 |
// CHECK-SAME: [0, 1, 2, 3, 0, 1, 2, 3] : vector<4xi8>, vector<4xi8> |
| 162 |
// CHECK: %[[EXT_FILTER_1:.*]] = arith.extsi %[[SH_FILTER_1]] : vector<8xi8> to vector<8xi32> |
| 163 |
// CHECK: %[[B_FILTER_1:.*]] = vector.broadcast %[[EXT_FILTER_1]] : vector<8xi32> to vector<3x8xi32> |
| 164 |
// CHECK: %[[MUL_1:.*]] = arith.muli %[[EXT_INPUT_1]], %[[B_FILTER_1]] : vector<3x8xi32> |
| 165 |
// CHECK: %[[ADD_1:.*]] = arith.addi %[[MUL_1]], %[[ADD_0]] : vector<3x8xi32> |
| 166 |
|
| 167 |
// Write the result back in one shot. |
| 168 |
// CHECK: %[[SC_ADD_1:.*]] = vector.shape_cast %[[ADD_1]] : vector<3x8xi32> to vector<3x2x4xi32> |
| 169 |
// CHECK: vector.transfer_write %[[SC_ADD_1]], %[[OUTPUT]][%[[C0]], %[[C0]], %[[C0]]] |
| 170 |
|
| 171 |
module attributes {transform.with_named_sequence} { |
| 172 |
transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) { |
| 173 |
%0 = transform.structured.match ops{["linalg.depthwise_conv_1d_nwc_wc"]} in %arg0 : (!transform.any_op) -> !transform.any_op |
| 174 |
%1 = transform.get_parent_op %0 {isolated_from_above} : (!transform.any_op) -> !transform.any_op |
| 175 |
%2 = transform.structured.vectorize_children_and_apply_patterns %1 {flatten_1d_depthwise_conv} : (!transform.any_op) -> !transform.any_op |
| 176 |
transform.yield |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
// ----- |
| 181 |
|
| 182 |
func.func @depthwise_conv1d_nwc_wc_3x9x4xi8_tensor_stride_2(%input: tensor<3x9x4xi8>, |
| 183 |
%filter: tensor<3x4xi8>, |
| 184 |
%output: tensor<3x3x4xi8>) -> tensor<3x3x4xi8> { |
| 185 |
%res = linalg.depthwise_conv_1d_nwc_wc |
| 186 |
{dilations = dense<1> : tensor<1xi64>, strides = dense<2> : tensor<1xi64>} |
| 187 |
ins(%input, %filter : tensor<3x9x4xi8>, tensor<3x4xi8>) |
| 188 |
outs(%output : tensor<3x3x4xi8>) -> tensor<3x3x4xi8> |
| 189 |
return %res : tensor<3x3x4xi8> |
| 190 |
} |
| 191 |
// CHECK-LABEL: func.func @depthwise_conv1d_nwc_wc_3x9x4xi8_tensor_stride_2 |
| 192 |
// CHECK-SAME: %[[INPUT:.*]]: tensor<3x9x4xi8>, |
| 193 |
// CHECK-SAME: %[[FILTER:.*]]: tensor<3x4xi8>, |
| 194 |
// CHECK-SAME: %[[OUTPUT:.*]]: tensor<3x3x4xi8>) -> tensor<3x3x4xi8> { |
| 195 |
|
| 196 |
// CHECK-DAG: %[[C0_IDX:.*]] = arith.constant 0 : index |
| 197 |
// CHECK-DAG: %[[C0_I8:.*]] = arith.constant 0 : i8 |
| 198 |
|
| 199 |
/// Read the whole data in one shot. |
| 200 |
// CHECK: %[[V_INPUT_R:.*]] = vector.transfer_read %[[INPUT]][%[[C0_IDX]], %[[C0_IDX]], %[[C0_IDX]]], %[[C0_I8]] |
| 201 |
// CHECK: %[[V_FILTER_R:.*]] = vector.transfer_read %[[FILTER]][%[[C0_IDX]], %[[C0_IDX]]], %[[C0_I8]] |
| 202 |
// CHECK: %[[V_OUTPUT_R:.*]] = vector.transfer_read %[[OUTPUT]][%[[C0_IDX]], %[[C0_IDX]], %[[C0_IDX]]], %[[C0_I8]] |
| 203 |
|
| 204 |
// CHECK: %[[V_INPUT_0:.*]] = vector.extract_strided_slice %[[V_INPUT_R]] |
| 205 |
// CHECK-SAME: {offsets = [0, 0, 0], sizes = [3, 1, 4], strides = [1, 1, 1]} : vector<3x7x4xi8> to vector<3x1x4xi8> |
| 206 |
// CHECK: %[[V_INPUT_1:.*]] = vector.extract_strided_slice %[[V_INPUT_R]] |
| 207 |
// CHECK-SAME: {offsets = [0, 2, 0], sizes = [3, 1, 4], strides = [1, 1, 1]} : vector<3x7x4xi8> to vector<3x1x4xi8> |
| 208 |
// CHECK: %[[V_INPUT_2:.*]] = vector.extract_strided_slice %[[V_INPUT_R]] |
| 209 |
// CHECK-SAME: {offsets = [0, 4, 0], sizes = [3, 1, 4], strides = [1, 1, 1]} : vector<3x7x4xi8> to vector<3x1x4xi8> |
| 210 |
// CHECK: %[[V_INPUT_3:.*]] = vector.extract_strided_slice %[[V_INPUT_R]] |
| 211 |
// CHECK-SAME: {offsets = [0, 1, 0], sizes = [3, 1, 4], strides = [1, 1, 1]} : vector<3x7x4xi8> to vector<3x1x4xi8> |
| 212 |
// CHECK: %[[V_INPUT_4:.*]] = vector.extract_strided_slice %[[V_INPUT_R]] |
| 213 |
// CHECK-SAME: {offsets = [0, 3, 0], sizes = [3, 1, 4], strides = [1, 1, 1]} : vector<3x7x4xi8> to vector<3x1x4xi8> |
| 214 |
// CHECK: %[[V_INPUT_5:.*]] = vector.extract_strided_slice %[[V_INPUT_R]] |
| 215 |
// CHECK-SAME: {offsets = [0, 5, 0], sizes = [3, 1, 4], strides = [1, 1, 1]} : vector<3x7x4xi8> to vector<3x1x4xi8> |
| 216 |
// CHECK: %[[V_INPUT_6:.*]] = vector.extract_strided_slice %[[V_INPUT_R]] |
| 217 |
// CHECK-SAME: {offsets = [0, 2, 0], sizes = [3, 1, 4], strides = [1, 1, 1]} : vector<3x7x4xi8> to vector<3x1x4xi8> |
| 218 |
// CHECK: %[[V_INPUT_7:.*]] = vector.extract_strided_slice %[[V_INPUT_R]] |
| 219 |
// CHECK-SAME: {offsets = [0, 4, 0], sizes = [3, 1, 4], strides = [1, 1, 1]} : vector<3x7x4xi8> to vector<3x1x4xi8> |
| 220 |
// CHECK: %[[V_INPUT_8:.*]] = vector.extract_strided_slice %[[V_INPUT_R]] |
| 221 |
// CHECK-SAME: {offsets = [0, 6, 0], sizes = [3, 1, 4], strides = [1, 1, 1]} : vector<3x7x4xi8> to vector<3x1x4xi8> |
| 222 |
|
| 223 |
// CHECK: %[[V_FILTER_0:.*]] = vector.extract %[[V_FILTER_R]][0] : vector<4xi8> from vector<3x4xi8> |
| 224 |
// CHECK: %[[V_FILTER_1:.*]] = vector.extract %[[V_FILTER_R]][1] : vector<4xi8> from vector<3x4xi8> |
| 225 |
// CHECK: %[[V_FILTER_2:.*]] = vector.extract %[[V_FILTER_R]][2] : vector<4xi8> from vector<3x4xi8> |
| 226 |
|
| 227 |
// CHECK: %[[V_OUTPUT_0:.*]] = vector.extract_strided_slice %[[V_OUTPUT_R]] |
| 228 |
// CHECK-SAME: {offsets = [0, 0, 0], sizes = [3, 1, 4], strides = [1, 1, 1]} : vector<3x3x4xi8> to vector<3x1x4xi8> |
| 229 |
// CHECK: %[[V_OUTPUT_1:.*]] = vector.extract_strided_slice %[[V_OUTPUT_R]] |
| 230 |
// CHECK-SAME: {offsets = [0, 1, 0], sizes = [3, 1, 4], strides = [1, 1, 1]} : vector<3x3x4xi8> to vector<3x1x4xi8> |
| 231 |
// CHECK: %[[V_OUTPUT_2:.*]] = vector.extract_strided_slice %[[V_OUTPUT_R]] |
| 232 |
// CHECK-SAME: {offsets = [0, 2, 0], sizes = [3, 1, 4], strides = [1, 1, 1]} : vector<3x3x4xi8> to vector<3x1x4xi8> |
| 233 |
|
| 234 |
/// w == 0, kw == 0 |
| 235 |
// CHECK: %[[VAL_23:.*]] = vector.shape_cast %[[V_INPUT_0]] : vector<3x1x4xi8> to vector<3x4xi8> |
| 236 |
// CHECK: %[[VAL_24:.*]] = vector.shape_cast %[[V_OUTPUT_0]] : vector<3x1x4xi8> to vector<3x4xi8> |
| 237 |
// CHECK: %[[B_FILTER_0:.*]] = vector.broadcast %[[V_FILTER_0]] : vector<4xi8> to vector<3x4xi8> |
| 238 |
// CHECK: %[[VAL_27:.*]] = arith.muli %[[VAL_23]], %[[B_FILTER_0]] : vector<3x4xi8> |
| 239 |
// CHECK: %[[VAL_28:.*]] = arith.addi %[[VAL_27]], %[[VAL_24]] : vector<3x4xi8> |
| 240 |
|
| 241 |
/// w == 1, kw == 0 |
| 242 |
// CHECK: %[[VAL_29:.*]] = vector.shape_cast %[[V_INPUT_1]] : vector<3x1x4xi8> to vector<3x4xi8> |
| 243 |
// CHECK: %[[VAL_30:.*]] = vector.shape_cast %[[V_OUTPUT_1]] : vector<3x1x4xi8> to vector<3x4xi8> |
| 244 |
// CHECK: %[[B_FILTER_0_1:.*]] = vector.broadcast %[[V_FILTER_0]] : vector<4xi8> to vector<3x4xi8> |
| 245 |
// CHECK: %[[VAL_33:.*]] = arith.muli %[[VAL_29]], %[[B_FILTER_0_1]] : vector<3x4xi8> |
| 246 |
// CHECK: %[[VAL_34:.*]] = arith.addi %[[VAL_33]], %[[VAL_30]] : vector<3x4xi8> |
| 247 |
|
| 248 |
/// w == 2, kw == 0 |
| 249 |
// CHECK: %[[VAL_35:.*]] = vector.shape_cast %[[V_INPUT_2]] : vector<3x1x4xi8> to vector<3x4xi8> |
| 250 |
// CHECK: %[[VAL_36:.*]] = vector.shape_cast %[[V_OUTPUT_2]] : vector<3x1x4xi8> to vector<3x4xi8> |
| 251 |
// CHECK: %[[B_FILTER_0_2:.*]] = vector.broadcast %[[V_FILTER_0]] : vector<4xi8> to vector<3x4xi8> |
| 252 |
// CHECK: %[[VAL_39:.*]] = arith.muli %[[VAL_35]], %[[B_FILTER_0_2]] : vector<3x4xi8> |
| 253 |
// CHECK: %[[VAL_40:.*]] = arith.addi %[[VAL_39]], %[[VAL_36]] : vector<3x4xi8> |
| 254 |
|
| 255 |
/// w == 3, kw == 1 |
| 256 |
// CHECK: %[[VAL_41:.*]] = vector.shape_cast %[[V_INPUT_3]] : vector<3x1x4xi8> to vector<3x4xi8> |
| 257 |
// CHECK: %[[B_FILTER_1:.*]] = vector.broadcast %[[V_FILTER_1]] : vector<4xi8> to vector<3x4xi8> |
| 258 |
// CHECK: %[[VAL_44:.*]] = arith.muli %[[VAL_41]], %[[B_FILTER_1]] : vector<3x4xi8> |
| 259 |
// CHECK: %[[VAL_45:.*]] = arith.addi %[[VAL_44]], %[[VAL_28]] : vector<3x4xi8> |
| 260 |
|
| 261 |
/// w == 4, kw == 1 |
| 262 |
// CHECK: %[[VAL_46:.*]] = vector.shape_cast %[[V_INPUT_4]] : vector<3x1x4xi8> to vector<3x4xi8> |
| 263 |
// CHECK: %[[B_FILTER_1_1:.*]] = vector.broadcast %[[V_FILTER_1]] : vector<4xi8> to vector<3x4xi8> |
| 264 |
// CHECK: %[[VAL_49:.*]] = arith.muli %[[VAL_46]], %[[B_FILTER_1_1]] : vector<3x4xi8> |
| 265 |
// CHECK: %[[VAL_50:.*]] = arith.addi %[[VAL_49]], %[[VAL_34]] : vector<3x4xi8> |
| 266 |
|
| 267 |
/// w == 5, kw == 1 |
| 268 |
// CHECK: %[[VAL_51:.*]] = vector.shape_cast %[[V_INPUT_5]] : vector<3x1x4xi8> to vector<3x4xi8> |
| 269 |
// CHECK: %[[B_FILTER_1_2:.*]] = vector.broadcast %[[V_FILTER_1]] : vector<4xi8> to vector<3x4xi8> |
| 270 |
// CHECK: %[[VAL_54:.*]] = arith.muli %[[VAL_51]], %[[B_FILTER_1_2]] : vector<3x4xi8> |
| 271 |
// CHECK: %[[VAL_55:.*]] = arith.addi %[[VAL_54]], %[[VAL_40]] : vector<3x4xi8> |
| 272 |
|
| 273 |
/// w == 6, kw == 2 |
| 274 |
// CHECK: %[[VAL_56:.*]] = vector.shape_cast %[[V_INPUT_6]] : vector<3x1x4xi8> to vector<3x4xi8> |
| 275 |
// CHECK: %[[B_FILTER_2:.*]] = vector.broadcast %[[V_FILTER_2]] : vector<4xi8> to vector<3x4xi8> |
| 276 |
// CHECK: %[[VAL_59:.*]] = arith.muli %[[VAL_56]], %[[B_FILTER_2]] : vector<3x4xi8> |
| 277 |
// CHECK: %[[VAL_60:.*]] = arith.addi %[[VAL_59]], %[[VAL_45]] : vector<3x4xi8> |
| 278 |
|
| 279 |
/// w == 7, kw == 2 |
| 280 |
// CHECK: %[[VAL_61:.*]] = vector.shape_cast %[[VAL_60]] : vector<3x4xi8> to vector<3x1x4xi8> |
| 281 |
// CHECK: %[[VAL_62:.*]] = vector.shape_cast %[[V_INPUT_7]] : vector<3x1x4xi8> to vector<3x4xi8> |
| 282 |
// CHECK: %[[B_FILTER_2_1:.*]] = vector.broadcast %[[V_FILTER_2]] : vector<4xi8> to vector<3x4xi8> |
| 283 |
// CHECK: %[[VAL_65:.*]] = arith.muli %[[VAL_62]], %[[B_FILTER_2_1]] : vector<3x4xi8> |
| 284 |
// CHECK: %[[VAL_66:.*]] = arith.addi %[[VAL_65]], %[[VAL_50]] : vector<3x4xi8> |
| 285 |
|
| 286 |
/// w == 8, kw == 2 |
| 287 |
// CHECK: %[[VAL_67:.*]] = vector.shape_cast %[[VAL_66]] : vector<3x4xi8> to vector<3x1x4xi8> |
| 288 |
// CHECK: %[[VAL_68:.*]] = vector.shape_cast %[[V_INPUT_8]] : vector<3x1x4xi8> to vector<3x4xi8> |
| 289 |
// CHECK: %[[B_FILTER_2_2:.*]] = vector.broadcast %[[V_FILTER_2]] : vector<4xi8> to vector<3x4xi8> |
| 290 |
// CHECK: %[[VAL_71:.*]] = arith.muli %[[VAL_68]], %[[B_FILTER_2_2]] : vector<3x4xi8> |
| 291 |
// CHECK: %[[VAL_72:.*]] = arith.addi %[[VAL_71]], %[[VAL_55]] : vector<3x4xi8> |
| 292 |
|
| 293 |
// Write the result back. |
| 294 |
// CHECK: %[[VAL_73:.*]] = vector.shape_cast %[[VAL_72]] : vector<3x4xi8> to vector<3x1x4xi8> |
| 295 |
// CHECK: %[[VAL_74:.*]] = vector.insert_strided_slice %[[VAL_61]], %[[V_OUTPUT_R]] |
| 296 |
// CHECK-SAME: {offsets = [0, 0, 0], strides = [1, 1, 1]} : vector<3x1x4xi8> into vector<3x3x4xi8> |
| 297 |
// CHECK: %[[VAL_75:.*]] = vector.insert_strided_slice %[[VAL_67]], %[[VAL_74]] |
| 298 |
// CHECK-SAME: {offsets = [0, 1, 0], strides = [1, 1, 1]} : vector<3x1x4xi8> into vector<3x3x4xi8> |
| 299 |
// CHECK: %[[VAL_76:.*]] = vector.insert_strided_slice %[[VAL_73]], %[[VAL_75]] |
| 300 |
// CHECK-SAME: {offsets = [0, 2, 0], strides = [1, 1, 1]} : vector<3x1x4xi8> into vector<3x3x4xi8> |
| 301 |
// CHECK: %[[VAL_77:.*]] = vector.transfer_write %[[VAL_76]], %[[OUTPUT]][%[[C0_IDX]], %[[C0_IDX]], %[[C0_IDX]]] |
| 302 |
|
| 303 |
module attributes {transform.with_named_sequence} { |
| 304 |
transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) { |
| 305 |
%0 = transform.structured.match ops{["linalg.depthwise_conv_1d_nwc_wc"]} in %arg0 : (!transform.any_op) -> !transform.any_op |
| 306 |
%1 = transform.get_parent_op %0 {isolated_from_above} : (!transform.any_op) -> !transform.any_op |
| 307 |
%2 = transform.structured.vectorize_children_and_apply_patterns %1 {flatten_1d_depthwise_conv} : (!transform.any_op) -> !transform.any_op |
| 308 |
transform.yield |
| 309 |
} |
| 310 |
} |
| 311 |
|