|
| 1 | +// RUN: mlir-opt --tosa-layerwise-constant-fold %s | FileCheck %s |
| 2 | + |
| 3 | +// CHECK-LABEL: func.func @concat_i32_axis0 |
| 4 | +// CHECK-SAME: () -> tensor<4x2xi32> { |
| 5 | +// CHECK: [[VAR_0_:%.+]] = "tosa.const"() <{value = dense<{{.}}[1, 2], [3, 4], [5, 6], [7, 8]{{.}}> : tensor<4x2xi32>}> : () -> tensor<4x2xi32> |
| 6 | +// CHECK: return [[VAR_0_]] : tensor<4x2xi32> |
| 7 | +func.func @concat_i32_axis0() -> (tensor<4x2xi32>) { |
| 8 | + %c0 = "tosa.const"() {value = dense<[[1, 2], [3, 4]]> : tensor<2x2xi32>} : () -> tensor<2x2xi32> |
| 9 | + %c1 = "tosa.const"() {value = dense<[[5, 6], [7, 8]]> : tensor<2x2xi32>} : () -> tensor<2x2xi32> |
| 10 | + %0 = "tosa.concat"(%c0, %c1) {axis = 0 : i32} : (tensor<2x2xi32>, tensor<2x2xi32>) -> tensor<4x2xi32> |
| 11 | + return %0 : tensor<4x2xi32> |
| 12 | +} |
| 13 | + |
| 14 | +// CHECK-LABEL: func.func @concat_f32_axis1 |
| 15 | +// CHECK-SAME: () -> tensor<2x3xf32> { |
| 16 | +// CHECK: [[VAR_0_:%.+]] = "tosa.const"() <{value = dense<{{.}}[1.000000e+00, 2.000000e+00, 3.000000e+00], [4.000000e+00, 5.000000e+00, 6.000000e+00]{{.}}> : tensor<2x3xf32>}> : () -> tensor<2x3xf32> |
| 17 | +// CHECK: return [[VAR_0_]] : tensor<2x3xf32> |
| 18 | +func.func @concat_f32_axis1() -> (tensor<2x3xf32>) { |
| 19 | + %c0 = "tosa.const"() {value = dense<[[1.0, 2.0], [4.0, 5.0]]> : tensor<2x2xf32>} : () -> tensor<2x2xf32> |
| 20 | + %c1 = "tosa.const"() {value = dense<[[3.0], [6.0]]> : tensor<2x1xf32>} : () -> tensor<2x1xf32> |
| 21 | + %0 = "tosa.concat"(%c0, %c1) {axis = 1 : i32} : (tensor<2x2xf32>, tensor<2x1xf32>) -> tensor<2x3xf32> |
| 22 | + return %0 : tensor<2x3xf32> |
| 23 | +} |
| 24 | + |
| 25 | +// CHECK-LABEL: func.func @concat_i8_three_inputs_axis1 |
| 26 | +// CHECK-SAME: () -> tensor<1x5xi8> { |
| 27 | +// CHECK: [[VAR_0_:%.+]] = "tosa.const"() <{value = dense<{{.}}[1, 2, 3, 4, 5]{{.}}> : tensor<1x5xi8>}> : () -> tensor<1x5xi8> |
| 28 | +// CHECK: return [[VAR_0_]] : tensor<1x5xi8> |
| 29 | +func.func @concat_i8_three_inputs_axis1() -> (tensor<1x5xi8>) { |
| 30 | + %c0 = "tosa.const"() {value = dense<[[1, 2]]> : tensor<1x2xi8>} : () -> tensor<1x2xi8> |
| 31 | + %c1 = "tosa.const"() {value = dense<[[3]]> : tensor<1x1xi8>} : () -> tensor<1x1xi8> |
| 32 | + %c2 = "tosa.const"() {value = dense<[[4, 5]]> : tensor<1x2xi8>} : () -> tensor<1x2xi8> |
| 33 | + %0 = "tosa.concat"(%c0, %c1, %c2) {axis = 1 : i32} : (tensor<1x2xi8>, tensor<1x1xi8>, tensor<1x2xi8>) -> tensor<1x5xi8> |
| 34 | + return %0 : tensor<1x5xi8> |
| 35 | +} |
| 36 | + |
| 37 | +// CHECK-LABEL: func.func @concat_i32_with_splat_axis0 |
| 38 | +// CHECK-SAME: () -> tensor<3x1xi32> { |
| 39 | +// CHECK: [[VAR_0_:%.+]] = "tosa.const"() <{value = dense<{{.}}[7], [7], [8]{{.}}> : tensor<3x1xi32>}> : () -> tensor<3x1xi32> |
| 40 | +// CHECK: return [[VAR_0_]] : tensor<3x1xi32> |
| 41 | +func.func @concat_i32_with_splat_axis0() -> (tensor<3x1xi32>) { |
| 42 | + %c0 = "tosa.const"() {value = dense<7> : tensor<2x1xi32>} : () -> tensor<2x1xi32> |
| 43 | + %c1 = "tosa.const"() {value = dense<[[8]]> : tensor<1x1xi32>} : () -> tensor<1x1xi32> |
| 44 | + %0 = "tosa.concat"(%c0, %c1) {axis = 0 : i32} : (tensor<2x1xi32>, tensor<1x1xi32>) -> tensor<3x1xi32> |
| 45 | + return %0 : tensor<3x1xi32> |
| 46 | +} |
| 47 | + |
| 48 | +// CHECK-LABEL: func.func @concat_bool_axis0 |
| 49 | +// CHECK-SAME: () -> tensor<2x2xi1> { |
| 50 | +// CHECK: [[VAR_0_:%.+]] = "tosa.const"() <{value = dense<{{.}}[true, false], [false, true]{{.}}> : tensor<2x2xi1>}> : () -> tensor<2x2xi1> |
| 51 | +// CHECK: return [[VAR_0_]] : tensor<2x2xi1> |
| 52 | +func.func @concat_bool_axis0() -> (tensor<2x2xi1>) { |
| 53 | + %c0 = "tosa.const"() {value = dense<[[true], [false]]> : tensor<2x1xi1>} : () -> tensor<2x1xi1> |
| 54 | + %c1 = "tosa.const"() {value = dense<[[false], [true]]> : tensor<2x1xi1>} : () -> tensor<2x1xi1> |
| 55 | + %0 = "tosa.concat"(%c0, %c1) {axis = 1 : i32} : (tensor<2x1xi1>, tensor<2x1xi1>) -> tensor<2x2xi1> |
| 56 | + return %0 : tensor<2x2xi1> |
| 57 | +} |
| 58 | + |
| 59 | +// CHECK-LABEL: func.func @concat_rank1_i32_axis0 |
| 60 | +// CHECK-SAME: () -> tensor<5xi32> { |
| 61 | +// CHECK: [[VAR_0_:%.+]] = "tosa.const"() <{value = dense<[1, 2, 3, 4, 5]> : tensor<5xi32>}> : () -> tensor<5xi32> |
| 62 | +// CHECK: return [[VAR_0_]] : tensor<5xi32> |
| 63 | +func.func @concat_rank1_i32_axis0() -> (tensor<5xi32>) { |
| 64 | + %c0 = "tosa.const"() {value = dense<[1, 2, 3]> : tensor<3xi32>} : () -> tensor<3xi32> |
| 65 | + %c1 = "tosa.const"() {value = dense<[4, 5]> : tensor<2xi32>} : () -> tensor<2xi32> |
| 66 | + %0 = "tosa.concat"(%c0, %c1) {axis = 0 : i32} : (tensor<3xi32>, tensor<2xi32>) -> tensor<5xi32> |
| 67 | + return %0 : tensor<5xi32> |
| 68 | +} |
| 69 | + |
| 70 | +// CHECK-LABEL: func.func @concat_empty_tensor_axis0 |
| 71 | +// CHECK-SAME: () -> tensor<2x2xi32> { |
| 72 | +// CHECK: [[VAR_0_:%.+]] = "tosa.const"() <{value = dense<{{.}}[1, 2], [3, 4]{{.}}> : tensor<2x2xi32>}> : () -> tensor<2x2xi32> |
| 73 | +// CHECK: return [[VAR_0_]] : tensor<2x2xi32> |
| 74 | +func.func @concat_empty_tensor_axis0() -> (tensor<2x2xi32>) { |
| 75 | + %c0 = "tosa.const"() {value = dense<[[1, 2], [3, 4]]> : tensor<2x2xi32>} : () -> tensor<2x2xi32> |
| 76 | + %c1 = "tosa.const"() {value = dense<> : tensor<0x2xi32>} : () -> tensor<0x2xi32> |
| 77 | + %0 = "tosa.concat"(%c0, %c1) {axis = 0 : i32} : (tensor<2x2xi32>, tensor<0x2xi32>) -> tensor<2x2xi32> |
| 78 | + return %0 : tensor<2x2xi32> |
| 79 | +} |
| 80 | + |
| 81 | +// CHECK-LABEL: func.func @concat_all_empty_tensors_axis1 |
| 82 | +// CHECK-SAME: () -> tensor<2x0xi32> { |
| 83 | +// CHECK: [[VAR_0_:%.+]] = "tosa.const"() <{value = dense<> : tensor<2x0xi32>}> : () -> tensor<2x0xi32> |
| 84 | +// CHECK: return [[VAR_0_]] : tensor<2x0xi32> |
| 85 | +func.func @concat_all_empty_tensors_axis1() -> (tensor<2x0xi32>) { |
| 86 | + %c0 = "tosa.const"() {value = dense<> : tensor<2x0xi32>} : () -> tensor<2x0xi32> |
| 87 | + %c1 = "tosa.const"() {value = dense<> : tensor<2x0xi32>} : () -> tensor<2x0xi32> |
| 88 | + %0 = "tosa.concat"(%c0, %c1) {axis = 1 : i32} : (tensor<2x0xi32>, tensor<2x0xi32>) -> tensor<2x0xi32> |
| 89 | + return %0 : tensor<2x0xi32> |
| 90 | +} |
| 91 | + |
| 92 | +// CHECK-LABEL: func.func @concat_i32_axis1_three_inputs_two_splats |
| 93 | +// CHECK-SAME: () -> tensor<2x4xi32> { |
| 94 | +// CHECK: [[VAR_0_:%.+]] = "tosa.const"() <{value = dense<{{.}}[1, 10, 11, 2], [1, 12, 13, 2]{{.}}> : tensor<2x4xi32>}> : () -> tensor<2x4xi32> |
| 95 | +// CHECK: return [[VAR_0_]] : tensor<2x4xi32> |
| 96 | +func.func @concat_i32_axis1_three_inputs_two_splats() -> (tensor<2x4xi32>) { |
| 97 | + %c0_splat = "tosa.const"() {value = dense<1> : tensor<2x1xi32>} : () -> tensor<2x1xi32> |
| 98 | + %c1_dense = "tosa.const"() {value = dense<[[10, 11], [12, 13]]> : tensor<2x2xi32>} : () -> tensor<2x2xi32> |
| 99 | + %c2_splat = "tosa.const"() {value = dense<2> : tensor<2x1xi32>} : () -> tensor<2x1xi32> |
| 100 | + %0 = "tosa.concat"(%c0_splat, %c1_dense, %c2_splat) {axis = 1 : i32} : (tensor<2x1xi32>, tensor<2x2xi32>, tensor<2x1xi32>) -> tensor<2x4xi32> |
| 101 | + return %0 : tensor<2x4xi32> |
| 102 | +} |
| 103 | + |
| 104 | +// CHECK-LABEL: func.func @concat_ui16_axis0 |
| 105 | +// CHECK-SAME: () -> tensor<3x2xui16> { |
| 106 | +// CHECK: [[VAR_0_:%.+]] = "tosa.const"() <{value = dense<{{.}}[100, 200], [300, 400], [500, 600]{{.}}> : tensor<3x2xui16>}> : () -> tensor<3x2xui16> |
| 107 | +// CHECK: return [[VAR_0_]] : tensor<3x2xui16> |
| 108 | +func.func @concat_ui16_axis0() -> (tensor<3x2xui16>) { |
| 109 | + %c0 = "tosa.const"() {value = dense<[[100, 200], [300, 400]]> : tensor<2x2xui16>} : () -> tensor<2x2xui16> |
| 110 | + %c1 = "tosa.const"() {value = dense<[[500, 600]]> : tensor<1x2xui16>} : () -> tensor<1x2xui16> |
| 111 | + %0 = "tosa.concat"(%c0, %c1) {axis = 0 : i32} : (tensor<2x2xui16>, tensor<1x2xui16>) -> tensor<3x2xui16> |
| 112 | + return %0 : tensor<3x2xui16> |
| 113 | +} |
| 114 | + |
| 115 | +// CHECK-LABEL: func.func @concat_3d_bf16_axis1 |
| 116 | +// CHECK-SAME: () -> tensor<2x3x2xbf16> { |
| 117 | +// CHECK: [[VAR_0_:%.+]] = "tosa.const"() <{value = dense<{{.}}{{.}}[1.000000e+00, 2.000000e+00], [5.000000e+00, 6.000000e+00], [7.000000e+00, 8.000000e+00]{{.}}, {{.}}[3.000000e+00, 4.000000e+00], [9.000000e+00, 1.000000e+01], [1.100000e+01, 1.200000e+01]{{.}}{{.}}> : tensor<2x3x2xbf16>}> : () -> tensor<2x3x2xbf16> |
| 118 | +// CHECK: return [[VAR_0_]] : tensor<2x3x2xbf16> |
| 119 | +func.func @concat_3d_bf16_axis1() -> (tensor<2x3x2xbf16>) { |
| 120 | + %c0 = "tosa.const"() {value = dense<[[[1.0, 2.0]], [[3.0, 4.0]]]> : tensor<2x1x2xbf16>} : () -> tensor<2x1x2xbf16> |
| 121 | + %c1 = "tosa.const"() {value = dense<[[[5.0, 6.0], [7.0, 8.0]], [[9.0, 10.0], [11.0, 12.0]]]> : tensor<2x2x2xbf16>} : () -> tensor<2x2x2xbf16> |
| 122 | + %0 = "tosa.concat"(%c0, %c1) {axis = 1 : i32} : (tensor<2x1x2xbf16>, tensor<2x2x2xbf16>) -> tensor<2x3x2xbf16> |
| 123 | + return %0 : tensor<2x3x2xbf16> |
| 124 | +} |
0 commit comments