Skip to content

Commit

Permalink
[BACKEND] Fix the bug in software loop pipeline (#2737)
Browse files Browse the repository at this point in the history
### Issue
The software loop pipeline used the wrong predication for each stage in
pre-epilogue.
### Fix
1. Using the array to keep reference to each predication value when
created.
2. Refer the correct predication value for the ops in each stage which
is just like the ops iterated before pipelining.

No change to the stage scheduling sequence. There should no impacting on
the performance.
  • Loading branch information
chengjunlu authored Dec 1, 2023
1 parent 5f20301 commit 470da87
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/Dialect/TritonGPU/Transforms/Pipeliner/PipelineExpander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ void LoopPipelinerInternal::emitPrologue(RewriterBase &rewriter) {
}
auto yield = cast<scf::YieldOp>(forOp.getBody()->getTerminator());
Location loc = forOp.getLoc();
SmallVector<Value, 5> predicates(maxStage);
for (int64_t i = 0; i < maxStage; i++) {
Value predicate;
if (dynamicLoop) {
Type t = ub.getType();
// pred = ub > lb + (i * step)
Expand All @@ -234,8 +234,8 @@ void LoopPipelinerInternal::emitPrologue(RewriterBase &rewriter) {
loc, step,
rewriter.create<arith::ConstantOp>(
loc, rewriter.getIntegerAttr(t, i))));
predicate = rewriter.create<arith::CmpIOp>(loc, arith::CmpIPredicate::slt,
iv, ub);
predicates[i] = rewriter.create<arith::CmpIOp>(
loc, arith::CmpIPredicate::slt, iv, ub);
}

// special handling for induction variable as the increment is implicit.
Expand All @@ -259,8 +259,9 @@ void LoopPipelinerInternal::emitPrologue(RewriterBase &rewriter) {
newOperand->set(replacement);
}
});
if (predicate) {
newOp = predicateFn(rewriter, newOp, predicate);
int predicateIdx = i - stages[op];
if (predicates[predicateIdx]) {
newOp = predicateFn(rewriter, newOp, predicates[predicateIdx]);
assert(newOp && "failed to predicate op.");
}
if (annotateFn)
Expand Down

0 comments on commit 470da87

Please sign in to comment.