• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: mlir-opt %s -test-linalg-greedy-fusion -split-input-file | FileCheck %s
2
3#map0 = affine_map<(d0)[s0] -> (2, -d0 + s0)>
4#map1 = affine_map<(d0)[s0] -> (4, -d0 + s0)>
5#map2 = affine_map<(d0)[s0] -> (3, -d0 + s0)>
6#map3 = affine_map<(d0, d1) -> (2, d0 - d1)>
7#map4 = affine_map<(d0, d1) -> (3, d0 - d1)>
8
9func @matmul_tensors(%arg0: tensor<?x?xf32>, %arg1: tensor<?x?xf32>, %arg2: tensor<?x?xf32>) -> tensor<?x?xf32> {
10  %t0 = linalg.matmul ins(%arg0, %arg1: tensor<?x?xf32>, tensor<?x?xf32>)
11                     init(%arg2: tensor<?x?xf32>)
12    -> tensor<?x?xf32>
13
14  %c4 = constant 4 : index
15  %c2 = constant 2 : index
16  %c0 = constant 0 : index
17  %c3 = constant 3 : index
18  %c1 = constant 1 : index
19  %0 = dim %t0, %c0 : tensor<?x?xf32>
20  %1 = dim %t0, %c1 : tensor<?x?xf32>
21  %2 = dim %arg1, %c1 : tensor<?x?xf32>
22  %3 = scf.for %arg3 = %c0 to %0 step %c2 iter_args(%arg4 = %arg2) -> (tensor<?x?xf32>) {
23    %4 = scf.for %arg5 = %c0 to %2 step %c3 iter_args(%arg6 = %arg4) -> (tensor<?x?xf32>) {
24      %5 = scf.for %arg7 = %c0 to %1 step %c4 iter_args(%arg8 = %arg6) -> (tensor<?x?xf32>) {
25        %6 = subtensor %t0[%arg3, %arg7][%c2, 4][1, 1] : tensor<?x?xf32> to tensor<?x4xf32>
26        %7 = subtensor %arg1[%arg7, %arg5][4, %c3][1, 1] : tensor<?x?xf32> to tensor<4x?xf32>
27        %8 = subtensor %arg8[%arg3, %arg5][%c2, %c3][1, 1] : tensor<?x?xf32> to tensor<?x?xf32>
28        %9 = linalg.matmul ins(%6, %7 : tensor<?x4xf32>, tensor<4x?xf32>) init(%8 : tensor<?x?xf32>) -> tensor<?x?xf32>
29        %10 = subtensor_insert %9 into %arg8[%arg3, %arg5] [%c2, %c3] [1, 1]  : tensor<?x?xf32> into tensor<?x?xf32>
30        scf.yield %10 : tensor<?x?xf32>
31      }
32      scf.yield %5 : tensor<?x?xf32>
33    }
34    scf.yield %4 : tensor<?x?xf32>
35  }
36  return %3 : tensor<?x?xf32>
37}
38
39// CHECK-LABEL: func @matmul_tensors(
40//  CHECK-SAME: %[[A:[0-9a-z]*]]: tensor<?x?xf32>
41//  CHECK-SAME: %[[B:[0-9a-z]*]]: tensor<?x?xf32>
42//  CHECK-SAME: %[[C:[0-9a-z]*]]: tensor<?x?xf32>
43//   CHECK-DAG: %[[C0:.*]] = constant 0 : index
44//   CHECK-DAG: %[[C1:.*]] = constant 1 : index
45//   CHECK-DAG: %[[dA1:.*]] = dim %[[A]], %[[C1]] : tensor<?x?xf32>
46//       CHECK: scf.for %[[I:[0-9a-z]*]]
47//       CHECK:     %[[stA:.*]] = subtensor %[[A]][%[[I]], 0] [2, %[[dA1]]] [1, 1]  : tensor<?x?xf32> to tensor<2x?xf32>
48//  CHECK-NEXT:   scf.for %[[J:[0-9a-z]*]]
49//  CHECK-NEXT:     scf.for %[[K:[0-9a-z]*]] {{.*}} iter_args(%[[RES:[0-9a-z]*]]
50//   CHECK-DAG:       %[[stB1:.*]] = subtensor %[[B]][%[[K]], %[[J]]] [4, 3] [1, 1]  : tensor<?x?xf32> to tensor<4x3xf32>
51//   CHECK-DAG:       %[[stF:.*]] = subtensor %[[RES]][%[[I]], %[[J]]] [2, 3] [1, 1]  : tensor<?x?xf32> to tensor<2x3xf32>
52//
53// subtensors of the producing matmul.
54//   CHECK-DAG:       %[[stB2:.*]] = subtensor %[[B]][0, %[[K]]] [%[[dA1]], 4] [1, 1]  : tensor<?x?xf32> to tensor<?x4xf32>
55//   CHECK-DAG:       %[[stC:.*]] = subtensor %[[C]][%[[I]], %[[K]]] [2, 4] [1, 1]  : tensor<?x?xf32> to tensor<2x4xf32>
56//       CHECK:       %[[stD:.*]] = linalg.matmul ins(%[[stA]], %[[stB2]] : tensor<2x?xf32>, tensor<?x4xf32>) init(%[[stC]] : tensor<2x4xf32>)  -> tensor<2x4xf32>
57//  CHECK-NEXT:       %[[stG:.*]] = linalg.matmul ins(%[[stD]], %[[stB1]] : tensor<2x4xf32>, tensor<4x3xf32>) init(%[[stF]] : tensor<2x3xf32>)  -> tensor<2x3xf32>
58//  CHECK-NEXT:       subtensor_insert %[[stG]] into %[[RES]][%[[I]], %[[J]]]
59