File: match_matmul_common.mlir

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (48 lines) | stat: -rw-r--r-- 3,437 bytes parent folder | download | duplicates (12)
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
// RUN: mlir-opt %s

module attributes { transform.with_named_sequence } {
  transform.named_sequence @_match_matmul_like(
      %entry: !transform.any_op {transform.readonly},
      %rank: !transform.param<i64> {transform.readonly})
      -> (!transform.any_op, !transform.any_op, !transform.param<i64>,
          !transform.type, !transform.type, !transform.type,
          !transform.param<i64>, !transform.param<i64>, !transform.param<i64>, !transform.param<i64>) {
    %c1 = transform.param.constant 1 : i64 -> !transform.param<i64>
    %c2 = transform.param.constant 2 : i64 -> !transform.param<i64>
    %capture:9 = transform.match.structured %entry : (!transform.any_op)
        -> (!transform.any_op, !transform.param<i64>, !transform.type, !transform.type, !transform.type,
            !transform.param<i64>, !transform.param<i64>, !transform.param<i64>, !transform.param<i64>) {
    ^bb0(%struct: !transform.any_op):
      %op_rank = transform.match.structured.rank %struct : (!transform.any_op) -> !transform.param<i64>
      transform.match.param.cmpi eq %rank, %op_rank : !transform.param<i64>
      %dims = transform.match.structured.dim %struct[all] : (!transform.any_op) -> !transform.param<i64>
      
      %n_inputs = transform.match.structured.num_inputs %struct : (!transform.any_op) -> !transform.param<i64>
      %n_inits = transform.match.structured.num_inits %struct : (!transform.any_op) -> !transform.param<i64>
      transform.match.param.cmpi eq %n_inputs, %c2 : !transform.param<i64>
      transform.match.param.cmpi eq %n_inits, %c1 : !transform.param<i64>
      
      %lhs = transform.match.structured.input %struct[0] : (!transform.any_op) -> !transform.any_value
      %rhs = transform.match.structured.input %struct[1] : (!transform.any_op) -> !transform.any_value
      %res = transform.match.structured.result %struct[0] : (!transform.any_op) -> !transform.any_value
      %lhs_type = transform.get_type elemental %lhs : (!transform.any_value) -> !transform.type
      %rhs_type = transform.get_type elemental %rhs : (!transform.any_value) -> !transform.type
      %res_type = transform.get_type elemental %res : (!transform.any_value) -> !transform.type

      %init = transform.match.structured.init %struct[0] : (!transform.any_op) -> !transform.any_op
      transform.match.operation_name %init ["linalg.fill"] : !transform.any_op

      transform.match.structured.body %struct { contraction = ["arith.mulf", "arith.addf"] } : !transform.any_op
      %dim_kinds:4 = transform.match.structured.classify_contraction_dims %struct
        : (!transform.any_op) -> (!transform.param<i64>, !transform.param<i64>, !transform.param<i64>, !transform.param<i64>)

      transform.match.structured.yield %init, %dims, %lhs_type, %rhs_type, %res_type, %dim_kinds#0, %dim_kinds#1, %dim_kinds#2, %dim_kinds#3
          : !transform.any_op, !transform.param<i64>, !transform.type, !transform.type, !transform.type,
            !transform.param<i64>, !transform.param<i64>, !transform.param<i64>, !transform.param<i64>
    }
    transform.yield %capture#0, %entry, %capture#1, %capture#2, %capture#3, %capture#4, 
                    %capture#5, %capture#6, %capture#7, %capture#8
        : !transform.any_op, !transform.any_op, !transform.param<i64>, !transform.type, !transform.type, !transform.type,
          !transform.param<i64>, !transform.param<i64>, !transform.param<i64>, !transform.param<i64>
  }
}