This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Linalg] Split reduction transform op
ClosedPublic

Authored by nicolasvasilache on Jun 20 2022, 2:15 AM.

Details

Summary

This revision separates the LinalgSplitReduction pattern, whose application is based on attributes,
from its implementation.
A transform dialect op extension is added to control the application of the transformation at a finer granularity.

Diff Detail

Event Timeline

nicolasvasilache requested review of this revision.Jun 20 2022, 2:15 AM

Add CHECKs to test

ftynse accepted this revision.Jun 20 2022, 3:16 AM
ftynse added inline comments.
mlir/include/mlir/Dialect/Linalg/TransformOps/LinalgTransformOps.td
161

I'd expand a bit on what the transformation does.

mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
404

Nit: can't one just omit the name?

410

Payload ops shouldn't be null, if they are, this sounds like a bug. Note that .front() will fail on the empty list, not return null.

412

Can't we just make it apply to each operand via the TransformEachOpTrait?

412

Otherwise, please add a test for this user-visible error message.

423

Nit: I'd rather do getSplitLinalgOp().cast<OpResult>()

mlir/lib/Dialect/Linalg/Transforms/SplitReduction.cpp
68

Nit: expand auto

110

Not for this diff: it would be nice to have this reported through DiagnosedSilenceableFailure. I don't know if we can connect the rewriter to that.

This revision is now accepted and ready to land.Jun 20 2022, 3:16 AM

Implementation that does not require ExpandShapeOp.

nicolasvasilache retitled this revision from [mlir][Linalg] Split reduction transform op to [WIP][mlir][Linalg] Split reduction transform op.Jun 20 2022, 8:35 AM
nicolasvasilache planned changes to this revision.Jun 20 2022, 8:40 AM
nicolasvasilache added a subscriber: ThomasRaoux.

It turns out that the transformation had a few issues, in particular related to dynamic dimensions and somewhat hardcoded assumptions.
I spent some time writing a version that does not require ExpandShapeOp and that instead rewrites the dimension with a "convolution" flavor.
This has certain advantages over the ExpandShapeOp version for some of the work I am doing but may be generally undesirable for @ThomasRaoux 's use cases.

Let's see what Thomas thinks of this version.

nicolasvasilache edited the summary of this revision. (Show Details)Jun 20 2022, 8:42 AM

Add more comments to the test.

This revision is now accepted and ready to land.Jun 20 2022, 8:42 AM
nicolasvasilache marked 7 inline comments as done.

Address review.

mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
412

Extended TransformEachOpTrait to work with multi-result.

mlir/lib/Dialect/Linalg/Transforms/SplitReduction.cpp
110

Ack

nicolasvasilache retitled this revision from [WIP][mlir][Linalg] Split reduction transform op to [mlir][Linalg] Split reduction transform op.Jun 21 2022, 4:06 AM
nicolasvasilache edited the summary of this revision. (Show Details)

It turns out that the transformation had a few issues, in particular related to dynamic dimensions and somewhat hardcoded assumptions.
I spent some time writing a version that does not require ExpandShapeOp and that instead rewrites the dimension with a "convolution" flavor.
This has certain advantages over the ExpandShapeOp version for some of the work I am doing but may be generally undesirable for @ThomasRaoux 's use cases.

Let's see what Thomas thinks of this version.

Reverted back to an NFC PR from the point of view of the transformation itself.
I'll send the proposed "SplitReduction without ExpanShapeOp" separately.

ftynse added inline comments.Jun 21 2022, 4:14 AM
mlir/include/mlir/Dialect/Transform/IR/TransformInterfaces.h
763–764

Something is broken with this signature

792

This looks fishy

809–811

I'd do something like SmallVector<SmallVector<Operation *>, 1> here to avoid over-allocating on stack in the common case of there being only one result.

818–838

const &, we don't want to copy here

831

Ditto

nicolasvasilache edited the summary of this revision. (Show Details)

Add test

Avoid spurious deletions.

nicolasvasilache marked an inline comment as done.Jun 21 2022, 4:51 AM
nicolasvasilache marked 5 inline comments as done.

Fix build

I see a bunch of spurious stderr: 'fatal: Unable to create '/var/lib/buildkite-agent/builds/llvm-project-fork/.git/index.lock': File exists. in the build bots.
Tests pass locally, landing as is.

This revision was landed with ongoing or failed builds.Jun 21 2022, 5:12 AM
This revision was automatically updated to reflect the committed changes.