2020-03-30 06:35:38 +08:00
|
|
|
// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline='func(parallel-loop-collapsing{collapsed-indices-0=0,1}, canonicalize)' | FileCheck %s
|
[MLIR] Add parallel loop collapsing.
This allows conversion of a ParallelLoop from N induction variables to
some nuber of induction variables less than N.
The first intended use of this is for the GPUDialect to convert
ParallelLoops to iterate over 3 dimensions so they can be launched as
GPU Kernels.
To implement this:
- Normalize each iteration space of the ParallelLoop
- Use the same induction variable in a new ParallelLoop for multiple
original iterations.
- Split the new induction variable back into the original set of values
inside the body of the ParallelLoop.
Subscribers: mgorny, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, Joonsoo, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D76363
2020-03-11 21:38:10 +08:00
|
|
|
|
|
|
|
func @collapse_to_single() {
|
|
|
|
%c0 = constant 3 : index
|
|
|
|
%c1 = constant 7 : index
|
|
|
|
%c2 = constant 11 : index
|
|
|
|
%c3 = constant 29 : index
|
|
|
|
%c4 = constant 3 : index
|
|
|
|
%c5 = constant 4 : index
|
2020-05-13 18:12:30 +08:00
|
|
|
scf.parallel (%i0, %i1) = (%c0, %c1) to (%c2, %c3) step (%c4, %c5) {
|
[MLIR] Add parallel loop collapsing.
This allows conversion of a ParallelLoop from N induction variables to
some nuber of induction variables less than N.
The first intended use of this is for the GPUDialect to convert
ParallelLoops to iterate over 3 dimensions so they can be launched as
GPU Kernels.
To implement this:
- Normalize each iteration space of the ParallelLoop
- Use the same induction variable in a new ParallelLoop for multiple
original iterations.
- Split the new induction variable back into the original set of values
inside the body of the ParallelLoop.
Subscribers: mgorny, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, Joonsoo, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D76363
2020-03-11 21:38:10 +08:00
|
|
|
%result = "magic.op"(%i0, %i1): (index, index) -> index
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-03-30 19:26:46 +08:00
|
|
|
// CHECK-LABEL: func @collapse_to_single() {
|
|
|
|
// CHECK: [[C7:%.*]] = constant 7 : index
|
|
|
|
// CHECK: [[C4:%.*]] = constant 4 : index
|
|
|
|
// CHECK: [[C18:%.*]] = constant 18 : index
|
|
|
|
// CHECK: [[C3:%.*]] = constant 3 : index
|
|
|
|
// CHECK: [[C6:%.*]] = constant 6 : index
|
|
|
|
// CHECK: [[C0:%.*]] = constant 0 : index
|
|
|
|
// CHECK: [[C1:%.*]] = constant 1 : index
|
2020-05-13 18:12:30 +08:00
|
|
|
// CHECK: scf.parallel ([[NEW_I:%.*]]) = ([[C0]]) to ([[C18]]) step ([[C1]]) {
|
2020-03-30 19:26:46 +08:00
|
|
|
// CHECK: [[I0_COUNT:%.*]] = remi_signed [[NEW_I]], [[C3]] : index
|
|
|
|
// CHECK: [[I1_COUNT:%.*]] = divi_signed [[NEW_I]], [[C6]] : index
|
|
|
|
// CHECK: [[VAL_10:%.*]] = muli [[I1_COUNT]], [[C4]] : index
|
|
|
|
// CHECK: [[I1:%.*]] = addi [[VAL_10]], [[C7]] : index
|
|
|
|
// CHECK: [[VAL_12:%.*]] = muli [[I0_COUNT]], [[C3]] : index
|
|
|
|
// CHECK: [[I0:%.*]] = addi [[VAL_12]], [[C3]] : index
|
|
|
|
// CHECK: "magic.op"([[I0]], [[I1]]) : (index, index) -> index
|
2020-05-13 18:12:30 +08:00
|
|
|
// CHECK: scf.yield
|
2020-03-30 19:26:46 +08:00
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: return
|