This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add primitive transform pattern to rewrite linalg.copy into vector.broadcast form
AbandonedPublic

Authored by tetuante on Feb 26 2020, 3:11 PM.

Details

Summary

This diff adds a transformation patter to rewrite linalg.copy as
broadcasting a vector into a vector.
It uses the same preconditioning as matmul (memory is contiguous).

Diff Detail

Event Timeline

tetuante created this revision.Feb 26 2020, 3:11 PM
tetuante retitled this revision from [mlir] Add primitive transform pattern to rewrite linalg.fill into vector.broadcast form to [mlir] Add primitive transform pattern to rewrite linalg.copy into vector.broadcast form.Feb 26 2020, 3:12 PM
tetuante added a reviewer: jsetoain.

There should be a *-commits list in the subscribers.

asaadaldien added inline comments.Feb 26 2020, 5:52 PM
mlir/lib/Dialect/Linalg/Transforms/LinalgTransforms.cpp
215

nit: s/fill/copy

nicolasvasilache requested changes to this revision.Feb 27 2020, 12:16 PM
nicolasvasilache added inline comments.
mlir/lib/Dialect/Linalg/Transforms/LinalgTransforms.cpp
215

typo: fill -> copy

219

I think there are a few issues with this scheme:

  1. this ignores the permutations on the copy so it will generate wrong code
  2. linalg.copy itself is meant to copy between a memref with static behavior and a memref with "less static" behavior. In practice we should have logic for masking etc and there is some trickiness involved.
  3. auto resVec = vector_broadcast(dstVec, srcVec); does not seem right

I would recommend instead evolving this revisions into a rewrite of linalg.copy into the proper vector.transfer_read and vector.transfer_write with proper permutations.
Note that the condition here is that only the source or target is fully static (not both, unlike linalg.fill and matmul).
Then in a separate revision we can start implementing rewrite and canonicalization patterns for transfers + splat and other things into the proper load / store + masks.

We may have to introduce first order masked loads too and delagate sone of the logic to LLVM, not too sure at this point.

This revision now requires changes to proceed.Feb 27 2020, 12:16 PM
tetuante abandoned this revision.Mar 9 2020, 4:25 AM

Abandoning this revision to evolve it into a rewrite of linalg.copy into the proper vector.transfer_read and vector.transfer_write with proper permutations.