[all-commits] [llvm/llvm-project] 10056c: [mlir][SCF] `scf.parallel`: Make reductions part o...

Matthias Springer via All-commits all-commits at lists.llvm.org
Tue Dec 19 18:06:40 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 10056c821a56a19cef732129e4e0c5883ae1ee49
      https://github.com/llvm/llvm-project/commit/10056c821a56a19cef732129e4e0c5883ae1ee49
  Author: Matthias Springer <me at m-sp.org>
  Date:   2023-12-20 (Wed, 20 Dec 2023)

  Changed paths:
    M mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
    M mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp
    M mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp
    M mlir/lib/Conversion/SCFToOpenMP/SCFToOpenMP.cpp
    M mlir/lib/Dialect/Async/Transforms/AsyncParallelFor.cpp
    M mlir/lib/Dialect/SCF/IR/SCF.cpp
    M mlir/lib/Dialect/SCF/Transforms/ParallelLoopTiling.cpp
    M mlir/lib/Dialect/SparseTensor/Transforms/SparseGPUCodegen.cpp
    M mlir/lib/Dialect/SparseTensor/Transforms/Utils/LoopEmitter.cpp
    M mlir/test/Conversion/AffineToStandard/lower-affine.mlir
    M mlir/test/Conversion/SCFToControlFlow/convert-to-cfg.mlir
    M mlir/test/Conversion/SCFToGPU/parallel_loop.mlir
    M mlir/test/Conversion/SCFToOpenMP/reductions.mlir
    M mlir/test/Conversion/SCFToSPIRV/unsupported.mlir
    M mlir/test/Dialect/Linalg/parallel-loops.mlir
    M mlir/test/Dialect/Linalg/transform-op-match.mlir
    M mlir/test/Dialect/SCF/buffer-deallocation.mlir
    M mlir/test/Dialect/SCF/canonicalize.mlir
    M mlir/test/Dialect/SCF/invalid.mlir
    M mlir/test/Dialect/SCF/ops.mlir
    M mlir/test/Dialect/SCF/parallel-loop-fusion.mlir
    M mlir/test/Dialect/SparseTensor/sparse_parallel_reduce.mlir
    M mlir/test/Transforms/invalid-parallel-loop-collapsing.mlir
    M mlir/test/Transforms/loop-invariant-code-motion.mlir
    M mlir/test/Transforms/parallel-loop-collapsing.mlir
    M mlir/test/Transforms/single-parallel-loop-collapsing.mlir

  Log Message:
  -----------
  [mlir][SCF] `scf.parallel`: Make reductions part of the terminator (#75314)

This commit makes reductions part of the terminator. Instead of
`scf.yield`, `scf.reduce` now terminates the body of `scf.parallel` ops.
`scf.reduce` may contain an arbitrary number of reductions, with one
region per reduction.

Example:
```mlir
%init = arith.constant 0.0 : f32
%r:2 = scf.parallel (%iv) = (%lb) to (%ub) step (%step) init (%init, %init)
    -> f32, f32 {
  %elem_to_reduce1 = load %buffer1[%iv] : memref<100xf32>
  %elem_to_reduce2 = load %buffer2[%iv] : memref<100xf32>
  scf.reduce(%elem_to_reduce1, %elem_to_reduce2 : f32, f32) {
    ^bb0(%lhs : f32, %rhs: f32):
      %res = arith.addf %lhs, %rhs : f32
      scf.reduce.return %res : f32
  }, {
    ^bb0(%lhs : f32, %rhs: f32):
      %res = arith.mulf %lhs, %rhs : f32
      scf.reduce.return %res : f32
  }
}
```

`scf.reduce` operations can no longer be interleaved with other ops in
the body of `scf.parallel`. This simplifies the op and makes it possible
to assign the `RecursiveMemoryEffects` trait to `scf.reduce`. (This was
not possible before because the op was not a terminator, causing the op
to be DCE'd.)




More information about the All-commits mailing list