File: test-matmul-masked-vec.mlir

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.8-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,388 kB
  • sloc: cpp: 7,438,767; ansic: 1,393,871; asm: 1,012,926; python: 241,728; f90: 86,635; objc: 75,411; lisp: 42,144; pascal: 17,286; sh: 10,027; ml: 5,082; perl: 4,730; awk: 3,523; makefile: 3,349; javascript: 2,251; xml: 892; fortran: 672
file content (60 lines) | stat: -rw-r--r-- 2,453 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// RUN: mlir-opt %s -transform-interpreter -test-transform-dialect-erase-schedule -one-shot-bufferize="bufferize-function-boundaries" -buffer-deallocation-pipeline -lower-vector-mask --test-lower-to-llvm | \
// RUN: mlir-runner -e main -entry-point-result=void --shared-libs=%mlir_c_runner_utils,%mlir_runner_utils | \
// RUN: FileCheck %s

func.func private @printMemrefF32(%ptr : tensor<*xf32>)

func.func @main() {
  %c4 = arith.constant 4 : index
  %c8 = arith.constant 8 : index

  %A = arith.constant dense<[
          [ 1.1, 2.1 ],
          [ 1.2, 2.2 ],
          [ 1.3, 2.3 ],
          [ 1.4, 2.4 ],
          [ 1.5, 2.5 ],
          [ 1.6, 2.6 ],
          [ 1.7, 2.7 ],
          [ 1.8, 2.8 ]
      ]> : tensor<8x2xf32>
  %B = arith.constant dense<[
          [ 10.1, 11.1, 12.1, 13.1 ],
          [ 10.2, 11.2, 12.2, 13.2 ]
      ]> : tensor<2x4xf32>
  %C_dyn = bufferization.alloc_tensor(%c8, %c4) : tensor<?x?xf32>

  %A_dyn = tensor.cast %A : tensor<8x2xf32> to tensor<?x?xf32>
  %B_dyn = tensor.cast %B : tensor<2x4xf32> to tensor<?x?xf32>

  %c0_i32 = arith.constant  0 : i32
  %C_init = linalg.fill ins(%c0_i32 : i32) outs(%C_dyn : tensor<?x?xf32>) -> tensor<?x?xf32>

  %res = linalg.matmul ins(%A_dyn, %B_dyn: tensor<?x?xf32>, tensor<?x?xf32>)
            outs(%C_init: tensor<?x?xf32>) -> tensor<?x?xf32>
  %xf = tensor.cast %res : tensor<?x?xf32> to tensor<*xf32>

  // CHECK:      {{\[}}[32.53,   35.73,   38.93,   42.13],
  // CHECK-NEXT: [34.56,   37.96,   41.36,   44.76],
  // CHECK-NEXT: [36.59,   40.19,   43.79,   47.39],
  // CHECK-NEXT: [38.62,   42.42,   46.22,   50.02],
  // CHECK-NEXT: [0,   0,   0,   0],
  // CHECK-NEXT: [0,   0,   0,   0],
  // CHECK-NEXT: [0,   0,   0,   0],
  // CHECK-NEXT: [0,   0,   0,   0]]
  call @printMemrefF32(%xf) : (tensor<*xf32>) -> ()

  return
}

module attributes {transform.with_named_sequence} {
  transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {
    %0 = transform.structured.match ops{["linalg.matmul"]} in %arg1 : (!transform.any_op) -> !transform.any_op
    %func_op = transform.get_parent_op %0 : (!transform.any_op) -> !transform.op<"func.func">
    transform.structured.vectorize %0 vector_sizes [4, 4, 2] : !transform.any_op
    transform.apply_patterns to %func_op {
      transform.apply_patterns.vector.lower_multi_reduction lowering_strategy = "innerreduction"
    } : !transform.op<"func.func">
    transform.yield
  }
}