brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · bd4c655 Raw
60 lines · plain
1// RUN: mlir-opt --transform-interpreter --split-input-file --verify-diagnostics %s | FileCheck %s2 3#map = affine_map<(d0, d1, d2) -> (d0, d2)>4#map1 = affine_map<(d0, d1, d2) -> (d2, d1)>5#map2 = affine_map<(d0, d1, d2) -> (d0, d1)>6func.func @specialize_matmul(%arg0: tensor<?x?xf32>, %arg1: tensor<?x?xf32>, %arg2: tensor<?x?xf32>) -> tensor<?x?xf32> {7  %0 = linalg.generic8          {indexing_maps = [#map, #map1, #map2], iterator_types = ["parallel", "parallel", "reduction"]}9          ins(%arg0, %arg1 : tensor<?x?xf32>, tensor<?x?xf32>) outs(%arg2 : tensor<?x?xf32>) {10    ^bb0(%in: f32, %in_0: f32, %out: f32):11      %0 = arith.mulf %in, %in_0 : f3212      %1 = arith.addf %out, %0 : f3213      linalg.yield %1 : f3214    } -> tensor<?x?xf32>15 return %0 : tensor<?x?xf32>16}17 18// CHECK-LABEL: @specialize_matmul19// CHECK-SAME: %[[ARG0:.+]]: tensor<?x?xf32>, %[[ARG1:.+]]: tensor<?x?xf32>, %[[ARG2:.+]]: tensor<?x?xf32>) -> tensor<?x?xf32>20// CHECK-NOT: linalg.generic21// CHECK: linalg.matmul ins(%[[ARG0]], %[[ARG1]] : tensor<?x?xf32>, tensor<?x?xf32>) outs(%[[ARG2]] : tensor<?x?xf32>) -> tensor<?x?xf32>22 23module attributes {transform.with_named_sequence} {24  transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) {25    %0 = transform.structured.match interface{LinalgOp} in %arg0 : (!transform.any_op) -> !transform.any_op26    %1 = transform.structured.specialize %0 : (!transform.any_op) -> !transform.any_op27    transform.yield28  }29}30 31// -----32 33#map = affine_map<(d0, d1, d2, d3) -> (d0, d1, d3)>34#map1 = affine_map<(d0, d1, d2, d3) -> (d0, d3, d2)>35#map2 = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2)>36func.func @batch_matmul(%arg0: tensor<2x16x8xf32>, %arg1: tensor<2x8x16xf32>, %arg2: tensor<2x16x16xf32>) -> tensor<2x16x16xf32> {37  %0 = linalg.generic38           {indexing_maps = [#map, #map1, #map2], iterator_types = ["parallel", "parallel", "parallel", "reduction"]}39           ins(%arg0, %arg1 : tensor<2x16x8xf32>, tensor<2x8x16xf32>) outs(%arg2 : tensor<2x16x16xf32>) {40    ^bb0(%in: f32, %in_0: f32, %out: f32):41      %1 = arith.mulf %in, %in_0 : f3242      %2 = arith.addf %out, %1 : f3243      linalg.yield %2 : f3244  } -> tensor<2x16x16xf32>45  return %0 : tensor<2x16x16xf32>46}47 48// CHECK-LABEL: @batch_matmul49// CHECK-SAME: %[[ARG0:.+]]: tensor<2x16x8xf32>, %[[ARG1:.+]]: tensor<2x8x16xf32>, %[[ARG2:.+]]: tensor<2x16x16xf32>) -> tensor<2x16x16xf32>50// CHECK-NOT: linalg.generic51// CHECK: linalg.batch_matmul ins(%[[ARG0]], %[[ARG1]] : tensor<2x16x8xf32>, tensor<2x8x16xf32>) outs(%[[ARG2]] : tensor<2x16x16xf32>) -> tensor<2x16x16xf32>52 53module attributes {transform.with_named_sequence} {54  transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) {55    %0 = transform.structured.match interface{LinalgOp} in %arg0 : (!transform.any_op) -> !transform.any_op56    %1 = transform.structured.specialize %0 : (!transform.any_op) -> !transform.any_op57    transform.yield58  }59}60