This is an archive of the discontinued LLVM Phabricator instance.

[mlir] support conversion of parallel reduction loops to std
ClosedPublic

Authored by ftynse on Mar 4 2020, 2:46 AM.

Details

Summary

Recently introduced support for converting sequential reduction loops to
CFG of basic blocks in the Standard dialect makes it possible to perform
a staged conversion of parallel reduction loops into a similar CFG by
using sequential loops as an intermediate step. This is already the case
for parallel loops without reduction, so extend the pattern to support
an additional use case.

Diff Detail

Event Timeline

ftynse created this revision.Mar 4 2020, 2:46 AM
pifon2a accepted this revision.Mar 4 2020, 6:24 AM

Thank you for doing that!

mlir/lib/Conversion/LoopToStandard/ConvertLoopToStandard.cpp
284

will this work?

SmallVector<Value, 4> iterArgs = llvm::to_vector(parallelOp.initVals());
309

nit:

if (first) {
  // Store the results of the outermost loop that will be used to replace
  // the results of the parallel loop when it is fully rewritten.
  loopResults.assign(forOp.result_begin(), forOp.result_end());
  first = false;
  continue;
} 
// A loop is constructed with an empty "yield" terminator by default.
// Replace it with another "yield" that forwards the results of the nested
// loop to the parent loop. We need to explicitly make sure the new
// terminator is the last operation in the block because further transfoms
// rely on this.
rewriter.setInsertionPointToEnd(rewriter.getInsertionBlock());
rewriter.replaceOpWithNewOp<YieldOp>(
    rewriter.getInsertionBlock()->getTerminator(), forOp.getResults());
This revision is now accepted and ready to land.Mar 4 2020, 6:24 AM
ftynse marked 3 inline comments as done.Mar 4 2020, 7:36 AM
ftynse added inline comments.
mlir/lib/Conversion/LoopToStandard/ConvertLoopToStandard.cpp
284

Yes, thanks!

309

I raised the first = false, but kept the else branch because the setInsertionPoint is necessary in both cases.

This revision was automatically updated to reflect the committed changes.
ftynse marked an inline comment as done.
rriddle added inline comments.Mar 4 2020, 9:52 AM
mlir/lib/Dialect/LoopOps/LoopOps.cpp
67

You should be able to do do: result.addTypes(iterArgs.getTypes())