File: foreach-thread-canonicalization.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 (36 lines) | stat: -rw-r--r-- 1,827 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
// RUN: mlir-opt %s -scf-for-loop-canonicalization | FileCheck %s

func.func @reduce() {
  // CHECK: %[[C64:.*]] = arith.constant 64 : index
  %c2 = arith.constant 2 : index
  %cst_0 = arith.constant -0.000000e+00 : f32
  %0 = memref.alloc() : memref<128x384xf32>
  linalg.fill ins(%cst_0 : f32) outs(%0 : memref<128x384xf32>)
  %2 = memref.alloc() : memref<128xf32>
  linalg.fill ins(%cst_0 : f32) outs(%2 : memref<128xf32>)
  scf.forall (%arg0) in (%c2) {
    %7 = affine.min affine_map<(d0) -> (d0 * -64 + 128, 64)>(%arg0)
    %8 = affine.max affine_map<(d0) -> (0, d0)>(%7)
    %9 = affine.apply affine_map<(d0) -> (d0 * 64)>(%arg0)
    %10 = affine.min affine_map<(d0, d1) -> (d1 * -64 + 128, d0)>(%8, %arg0)

    // CHECK: memref.subview %{{.*}}[%{{.*}}, 0] [%[[C64]], 384] [1, 1] : memref<128x384xf32> to memref<?x384xf32, {{.*}}>
    // CHECK: memref.subview %{{.*}}[%{{.*}}] [%[[C64]]] [1] : memref<128xf32> to memref<?xf32, {{.*}}>
    %11 = memref.subview %0[%9, 0] [%10, 384] [1, 1] :
      memref<128x384xf32> to memref<?x384xf32, affine_map<(d0, d1)[s0] -> (d0 * 384 + s0 + d1)>>
    %12 = memref.subview %2[%9] [%10] [1] :
      memref<128xf32> to memref<?xf32, affine_map<(d0)[s0] -> (d0 + s0)>>

    // CHECK: linalg.generic {{.*}} ins(%{{.*}} : memref<?x384xf32, {{.*}}>) outs(%{{.*}} : memref<?xf32, {{.*}}>)
    linalg.generic {indexing_maps = [affine_map<(d0, d1) -> (d0, d1)>,
                                      affine_map<(d0, d1) -> (d0)>],
                     iterator_types = ["parallel", "reduction"]}
      ins(%11 : memref<?x384xf32, affine_map<(d0, d1)[s0] -> (d0 * 384 + s0 + d1)>>)
      outs(%12 : memref<?xf32, affine_map<(d0)[s0] -> (d0 + s0)>>) {
        ^bb0(%arg1: f32, %arg2: f32):
          %14 = arith.addf %arg1, %arg2 : f32
          linalg.yield %14 : f32
      }
  }
  return
}