brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.9 KiB · 8ede2e0 Raw
182 lines · plain
1// RUN: mlir-opt --transform-interpreter --split-input-file --verify-diagnostics %s | FileCheck %s2 3#map = affine_map<(d0, d1) -> (d0, d1)>4#map1 = affine_map<(d0, d1) -> (d0)>5#map2 = affine_map<(d0, d1) -> (d1, d0)>6 7func.func @not_a_copy_expect_no_match(%arg0: memref<?x?xf32>, %arg1: memref<?x?xf32>) {8  // expected-note @below {{when applied to this op}}9  linalg.generic {10    indexing_maps = [#map, #map], 11    iterator_types = ["parallel", "parallel"]}12    ins(%arg0 : memref<?x?xf32>) outs(%arg1 : memref<?x?xf32>) {13    ^bb0(%in: f32, %out: f32):14      %0 = arith.addf %in, %out : f3215      linalg.yield %0 : f3216  }17  return18}19 20func.func @transpose_op_expect_no_match(%arg0: memref<?x?xf32>, %arg1: memref<?x?xf32>) {21  // expected-note @below {{when applied to this op}}22  linalg.generic {23    indexing_maps = [#map, #map2], 24    iterator_types = ["parallel", "parallel"]} 25    ins(%arg0 : memref<?x?xf32>) outs(%arg1 : memref<?x?xf32>) {26    ^bb0(%in: f32, %out: f32):27      linalg.yield %in : f3228  }29  return30}31 32func.func @copy_with_up_cast(%arg0: memref<?x?xf16>, %arg1: memref<?x?xf32>) {33  // expected-note @below {{when applied to this op}}34  linalg.generic {35    indexing_maps = [#map, #map], 36    iterator_types = ["parallel", "parallel"]} 37    ins(%arg0 : memref<?x?xf16>) outs(%arg1 : memref<?x?xf32>) {38    ^bb0(%in: f16, %out: f32):39      %0 = arith.extf %in : f16 to f3240      linalg.yield %0 : f3241  }42  return43}44 45func.func @copy_with_down_cast(%arg0: memref<?x?xf32>, %arg1: memref<?x?xf16>) {46  // expected-note @below {{when applied to this op}}47  linalg.generic {48    indexing_maps = [#map, #map], 49    iterator_types = ["parallel", "parallel"]} 50    ins(%arg0 : memref<?x?xf32>) outs(%arg1 : memref<?x?xf16>) {51    ^bb0(%in: f32, %out: f16):52      %0 = arith.truncf %in : f32 to f1653      linalg.yield %0 : f1654  }55  return56}57 58module attributes {transform.with_named_sequence} {59  transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {60    %0 = transform.structured.match interface{LinalgOp} in %arg1 : (!transform.any_op) -> !transform.any_op61    // expected-error @below {{failed to apply}}62    %1 = transform.structured.specialize %0 : (!transform.any_op) -> !transform.any_op63    transform.yield64  }65}66 67// -----68 69#map = affine_map<(d0, d1) -> (d0, d1)>70 71func.func @specialize_trivial_copy_memref(%arg0: memref<?x?xf32>, %arg1: memref<?x?xf32>) {72  linalg.generic {73    indexing_maps = [#map, #map], 74    iterator_types = ["parallel", "parallel"]} 75    ins(%arg0 : memref<?x?xf32>) outs(%arg1 : memref<?x?xf32>) {76    ^bb0(%in: f32, %out: f32):77      linalg.yield %in : f3278  }79  return80}81 82// CHECK-LABEL: specialize_trivial_copy_memref83// CHECK-SAME: %[[ARG0:.+]]: memref<?x?xf32>, %[[ARG1:.+]]: memref<?x?xf32>84// CHECK-NOT: linalg.generic85// CHECK: linalg.copy ins(%[[ARG0]] : memref<?x?xf32>) outs(%[[ARG1]] : memref<?x?xf32>)86 87#map1 = affine_map<(d0, d1, d2) -> (d0, d1, d2)>88 89func.func @specialize_trivial_copy_tensor(%arg0: tensor<?x?x?xf32>, 90    %arg1: tensor<?x?x?xf32>) -> tensor<?x?x?xf32> {91  %0 = linalg.generic {92    indexing_maps = [#map1, #map1], 93    iterator_types = ["parallel", "parallel", "parallel"]}94    ins(%arg0 : tensor<?x?x?xf32>) outs(%arg1 : tensor<?x?x?xf32>) {95    ^bb0(%in: f32, %out: f32):96      linalg.yield %in : f3297  } -> tensor<?x?x?xf32>98  return %0 : tensor<?x?x?xf32>99}100 101// CHECK-LABEL: specialize_trivial_copy_tensor102// CHECK-SAME: %[[ARG0:.+]]: tensor<?x?x?xf32>, %[[ARG1:.+]]: tensor<?x?x?xf32>103// CHECK-NOT: linalg.generic104// CHECK: %{{.+}} = linalg.copy ins(%[[ARG0]] : tensor<?x?x?xf32>) outs(%[[ARG1]] : tensor<?x?x?xf32>)105 106func.func @already_trivial_copy_memref(%arg0: memref<?x?xf32>, %arg1: memref<?x?xf32>) {107  linalg.copy ins(%arg0: memref<?x?xf32>) outs(%arg1: memref<?x?xf32>)108  return109}110 111// CHECK-LABEL: already_trivial_copy_memref112// CHECK-SAME: %[[ARG0:.+]]: memref<?x?xf32>, %[[ARG1:.+]]: memref<?x?xf32>113// CHECK: linalg.copy ins(%[[ARG0]] : memref<?x?xf32>) outs(%[[ARG1]] : memref<?x?xf32>)114 115func.func @already_trivial_copy_tensor(%arg0: tensor<?x?x?xf32>,116    %arg1: tensor<?x?x?xf32>) -> tensor<?x?x?xf32> {117  %0 = linalg.copy ins(%arg0: tensor<?x?x?xf32>) outs(%arg1: tensor<?x?x?xf32>) -> tensor<?x?x?xf32>118  return %0 : tensor<?x?x?xf32>119}120 121// CHECK-LABEL: already_trivial_copy_tensor122// CHECK-SAME: %[[ARG0:.+]]: tensor<?x?x?xf32>, %[[ARG1:.+]]: tensor<?x?x?xf32>123// CHECK: %{{.+}} = linalg.copy ins(%[[ARG0]] : tensor<?x?x?xf32>) outs(%[[ARG1]] : tensor<?x?x?xf32>)124 125module attributes {transform.with_named_sequence} {126  transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {127    %0 = transform.structured.match interface{LinalgOp} in %arg1 : (!transform.any_op) -> !transform.any_op128    %1 = transform.structured.specialize %0 : (!transform.any_op) -> !transform.any_op129    transform.yield130  }131}132 133// -----134 135#map = affine_map<(d0, d1) -> ()>136#map1 = affine_map<(d0, d1) -> (d0, d1)>137func.func @linalg_generic_fill(%arg0: tensor<7x7xf32>) -> tensor<7x7xf32> {138  %cst = arith.constant 0.000000e+00 : f32139  %0 = linalg.generic {indexing_maps = [#map, #map1], iterator_types = ["parallel", "parallel"]} ins(%cst : f32) outs(%arg0 : tensor<7x7xf32>) {140  ^bb0(%in: f32, %out: f32):141    linalg.yield %in : f32142  } -> tensor<7x7xf32>143  return %0 : tensor<7x7xf32>144}145// CHECK-LABEL: linalg_generic_fill146// CHECK-SAME: %[[ARG0:.+]]: tensor<7x7xf32>) -> tensor<7x7xf32>147// CHECK:  %[[CST:.+]] = arith.constant 0.000000e+00 : f32148// CHECK: %{{.*}} = linalg.fill ins(%[[CST]] : f32) outs(%[[ARG0]] : tensor<7x7xf32>) -> tensor<7x7xf32>149 150module attributes {transform.with_named_sequence} {151  transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {152    %0 = transform.structured.match interface{LinalgOp} in %arg1 : (!transform.any_op) -> !transform.any_op153    %1 = transform.structured.specialize %0 : (!transform.any_op) -> !transform.any_op154    transform.yield155  }156}157 158// -----159 160#map = affine_map<(d0, d1) -> (d0, d1)>161func.func @linalg_generic_inlined_constant_fill(%arg0: tensor<7x7xf32>) -> tensor<7x7xf32> {162  %cst = arith.constant 0.000000e+00 : f32163  %0 = linalg.generic {indexing_maps = [#map], iterator_types = ["parallel", "parallel"]} outs(%arg0 : tensor<7x7xf32>) {164  ^bb0(%out: f32):165    linalg.yield %cst : f32166  } -> tensor<7x7xf32>167  return %0 : tensor<7x7xf32>168}169 170// CHECK-LABEL: linalg_generic_inlined_constant_fill171// CHECK-SAME: %[[ARG0:.+]]: tensor<7x7xf32>) -> tensor<7x7xf32>172// CHECK:  %[[CST:.+]] = arith.constant 0.000000e+00 : f32173// CHECK: %{{.*}} = linalg.fill ins(%[[CST]] : f32) outs(%[[ARG0]] : tensor<7x7xf32>) -> tensor<7x7xf32>174 175module attributes {transform.with_named_sequence} {176  transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {177    %0 = transform.structured.match interface{LinalgOp} in %arg1 : (!transform.any_op) -> !transform.any_op178    %1 = transform.structured.specialize %0 : (!transform.any_op) -> !transform.any_op179    transform.yield180  }181}182