Page MenuHomePhabricator

[mlir][Linalg] Add support to lower named ops to loops.
ClosedPublic

Authored by nicolasvasilache on Apr 29 2020, 3:03 PM.

Details

Summary

This revision adds support to allow named ops to lower to loops.
Linalg.batch_matmul successfully lowers to loops and to LLVM.

In the process, this test also activates linalg to affine loops.
However padded convolutions to not lower to affine.load atm so this revision overrides the type of underlying load / store operation.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptApr 29 2020, 3:03 PM
rriddle added inline comments.Apr 29 2020, 3:13 PM
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
1119

Can we use std::array here instead?

mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
125–154

nit: Please use /// for comments.

185

Depends on what you need, but you could use mlir::inlineRegion. You just need to provide an InlinerInterface.

nicolasvasilache edited the summary of this revision. (Show Details)Apr 29 2020, 3:41 PM

Update affine loops.

nicolasvasilache marked 3 inline comments as done.

Address review.

nicolasvasilache marked an inline comment as done.Apr 29 2020, 3:47 PM
nicolasvasilache added inline comments.
mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
185

Ack, keeping that for a global change in a separate revision.
Thanks!

nicolasvasilache marked an inline comment as done.Apr 29 2020, 3:47 PM

Looks good... some minor comments.

mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
357–358

A couple of typos here: access and StdIndexedValue

358

I might have missed this but a test case exercising this path is probably missing.

680

Nit: typo operands -> operand.

mlir/test/Dialect/Linalg/loops.mlir
3

Nit: I think you have a separate file affine.mlir for -convert-linalg-to-affine-loops?

mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp
1583

A comment here and perhaps above will help.

ftynse added inline comments.Apr 30 2020, 1:40 AM
mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
126

Does "1." actually emit stores?

133

Nit: // -> ///

mlir/test/Dialect/Linalg/loops.mlir
3

Why do you need to disable pass threading here?

5

I'm surprised this ever worked on non-unix system

890

The comment in the code says loads are emitted in the same order as operands, so why "DAG" ?

893

DAG here looks like it would allow breaking use-def chains...

nicolasvasilache marked 12 inline comments as done.

Address review comments.

mlir/test/Dialect/Linalg/loops.mlir
5

Hmm, I've picked this up from here IIRC

ftynse accepted this revision.Apr 30 2020, 9:30 AM
This revision is now accepted and ready to land.Apr 30 2020, 9:30 AM
mravishankar accepted this revision.Apr 30 2020, 9:32 AM

Overall looks fine to me. Thanks

mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
127

This is not necessary for this CL, but you only need to emit loads for output views if there is a use of the corresponding arguments. Something I have been wanting to address for a while now.

458–460

Ack :)

nicolasvasilache marked 2 inline comments as done.Apr 30 2020, 10:46 AM
This revision was automatically updated to reflect the committed changes.