This is an archive of the discontinued LLVM Phabricator instance.

[mlir][vector] Support vector.extractelement distribution of 1D vectors
ClosedPublic

Authored by springerm on Nov 3 2022, 6:48 AM.

Details

Summary

Ops such as %1 = vector.extractelement %0[%pos : index] : vector<96xf32>.

In case of an extract from a 1D vector, the source vector is distributed. The lane into which the requested position falls, extracts the element and shuffles it to all other lanes.

Diff Detail

Event Timeline

springerm created this revision.Nov 3 2022, 6:48 AM
Herald added a project: Restricted Project. · View Herald Transcript
springerm requested review of this revision.Nov 3 2022, 6:48 AM
Herald added a project: Restricted Project. · View Herald Transcript
ThomasRaoux added inline comments.Nov 3 2022, 8:03 AM
mlir/lib/Dialect/Vector/Transforms/VectorDistribute.cpp
973–989

I would remove the if/else, since the code guarded by if is just an extract it is better to do it for all the lanes even if it is useful only for laneIdx.

993

warpSize should always be constant, I would pass int64_t here instead of a Value.

springerm updated this revision to Diff 472973.Nov 3 2022, 10:03 AM
springerm marked 2 inline comments as done.

address comments

ThomasRaoux added inline comments.Nov 3 2022, 11:04 AM
mlir/test/Dialect/Vector/vector-warp-distribute.mlir
697

I would have expected the distributed index to be pos%warpSize? and the extract idx to be pos/warpSize?

Here let's say %pos = 54, we get extract_element of 18 which is out of bound?

springerm updated this revision to Diff 473233.Nov 4 2022, 7:26 AM

address comments

springerm marked an inline comment as done.Nov 4 2022, 7:26 AM
springerm added inline comments.
mlir/test/Dialect/Vector/vector-warp-distribute.mlir
697

ah yes of course

ThomasRaoux added inline comments.Nov 4 2022, 10:00 AM
mlir/test/Dialect/Vector/vector-warp-distribute.mlir
697

isn't the problem still there? would expect the maps to be s0 floordiv 32 and s0 mod 32?

springerm marked an inline comment as done.Nov 8 2022, 7:43 AM
springerm added inline comments.
mlir/test/Dialect/Vector/vector-warp-distribute.mlir
697

I think this is correct now. vector<96xf32> gets distributed, so that each lane receives a vector<3xf32>. With pos = 54:

The lane that should extract: pos / 3 = 54 / 3 = 18
The position at which it should extract: pos % 3 = 0

Note, in case of pos % 32 = 54 % 32 = 22, we produce an out-of-bounds index for the extract from a vector<3xf32>.

ThomasRaoux accepted this revision.Nov 9 2022, 12:20 PM
ThomasRaoux added inline comments.
mlir/test/Dialect/Vector/vector-warp-distribute.mlir
697

you're right.

This revision is now accepted and ready to land.Nov 9 2022, 12:20 PM