This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][Ploops] Add custom builders from ParallelOp and ReduceOp.
ClosedPublic

Authored by pifon2a on Feb 17 2020, 5:34 AM.

Diff Detail

Event Timeline

pifon2a created this revision.Feb 17 2020, 5:34 AM
herhut requested changes to this revision.Feb 17 2020, 8:07 AM

Thanks for adding the builders!

mlir/include/mlir/Dialect/LoopOps/LoopOps.td
240

Why is this called initValue? It is the value to be reduced.

mlir/lib/Dialect/LoopOps/LoopOps.cpp
239

Can you express the above builder by calling this builder? Or have the resultTypes have an empty default?

This revision now requires changes to proceed.Feb 17 2020, 8:07 AM
rriddle added inline comments.Feb 17 2020, 9:54 AM
mlir/lib/Dialect/LoopOps/LoopOps.cpp
248

Please cache the end value of this loop.

377

Nit: SmallVector -> ArrayRef?

mehdi_amini added inline comments.Feb 17 2020, 8:47 PM
mlir/include/mlir/Dialect/LoopOps/LoopOps.td
188

Isn't a loop always supposed to capture as operands the same types as the returned values? If so then why do we have a builder with resultTypes? I'd expect these to be inferred from the captured operands?

It is a problem with the current reduce, which does not model this, but that's a bug to fix right? And so adding a builder around the incorrect design does not seem right to me.

pifon2a updated this revision to Diff 245328.Feb 18 2020, 11:04 PM
pifon2a marked 4 inline comments as done.

Addressed most comments.

pifon2a marked an inline comment as done.Feb 18 2020, 11:05 PM
pifon2a added inline comments.
mlir/include/mlir/Dialect/LoopOps/LoopOps.td
240

Then the documentation is quite confusing:

mlir
      %zero = constant 0.0 : f32
      loop.reduce(%zero) {
        ^bb0(%lhs : f32, %rhs: f32):
          %res = addf %lhs, %rhs : f32
          loop.reduce.return %res : f32
      } : f32

Looking at %zero I would assume that it is the initial value of the accumulator. I'll fix it.

pifon2a updated this revision to Diff 245342.Feb 19 2020, 12:42 AM
pifon2a marked an inline comment as done.

Doc mod

pifon2a marked an inline comment as done.Feb 19 2020, 12:51 AM
pifon2a added inline comments.
mlir/include/mlir/Dialect/LoopOps/LoopOps.td
188

Ploops don't really capture any operands from which we can infer result types. The result types correspond to the ReduceOps in the body of the ploop.

herhut accepted this revision.Feb 19 2020, 1:13 AM
herhut added inline comments.
mlir/include/mlir/Dialect/LoopOps/LoopOps.td
188

We have not added neutral values that can be used as initial values to parallel loops, yet, and I am not sure whether they should be mandatory. Having neutral values unlocks some additional reduction schemes but they are not always necessary. If we make them optional, we will need to provide return types to support that.
If we make them mandatory, we can adapt the builders and their use sites.

This revision is now accepted and ready to land.Feb 19 2020, 1:13 AM
This revision was automatically updated to reflect the committed changes.
mehdi_amini added inline comments.Feb 19 2020, 8:32 AM
mlir/include/mlir/Dialect/LoopOps/LoopOps.td
188

I thought we discussed this and it would be added?
There is no guarantee that a loop would be executed once: as such it should take an input value for all returned to support this.

mlir/lib/Dialect/LoopOps/LoopOps.cpp
239

I don't think this code path is tested?

370

I don't think this code path is tested?

Ping on ntv@ comments and my question?

@mehdi_amini @nicolasvasilache I am working on a PR that passes initial values to loop.parallel. After that PR this new builder won't be needed.