This is an archive of the discontinued LLVM Phabricator instance.

[mlir][tensor] Implement TilingInterface for unpack op
ClosedPublic

Authored by hanchung on Dec 5 2022, 12:59 PM.

Details

Summary

The main issue of tiling unpack op is about incomplete tile. Since all
the dimensions are orthogonal, discussing 1-d unpack case is enough. The
core idea is to make the input slice have complete tiles. In this case,
a larger unpacked tile will be created. We'll need an extract_slice op
to shift and truncate the output.

Take Nn_to_N as an example. Say that N=32, n=8, and tiling_size=15. The
coordinates of second tile (i.e., result[15..31]) are [(1, 7), (2, 0,),
(2, 1) ... (3, 6), (3, 7)]. The first row and the last row are
incomplete in terms of inputs. It's impossible to represent an unpack op
using the coordinates. Because the input has higher rank and the math
computation of coordinate is using mod and ceilDiv. That's very tricky.

To represent the unpack op, we have to complete the rows. I.e., the
input coordinates would start with (1, 0); end with (3, 7). In this
context, the tiled unpack produces a (3 * n) elements because there are
3 rows in total. Follow by a tensor.extract_slice op, we can get the
actual result.

If the tiling sizes are multiple of inner tile sizes, it is a perfect
tiling case. In this context, the larger input and output is not needed.

Diff Detail

Event Timeline

hanchung created this revision.Dec 5 2022, 12:59 PM
hanchung requested review of this revision.Dec 5 2022, 12:59 PM
Herald added a project: Restricted Project. · View Herald Transcript
hanchung updated this revision to Diff 480272.Dec 5 2022, 4:05 PM

rebase and update lit tests

hanchung updated this revision to Diff 481386.Dec 8 2022, 11:45 AM

rebase + fix bazel build

chelini added inline comments.Dec 9 2022, 1:39 AM
mlir/lib/Dialect/Tensor/IR/TensorTilingInterfaceImpl.cpp
234

Can you please document this method?

292
347
348
349

what is head?

367

Can you please document why we are doing this?

hanchung updated this revision to Diff 482632.Dec 13 2022, 2:41 PM
hanchung marked 5 inline comments as done.

address comments and rebase

mlir/lib/Dialect/Tensor/IR/TensorTilingInterfaceImpl.cpp
234

I added more documents in getTiledImplemetation and route the "needed information" to it. Please take a look, thanks!

chelini accepted this revision.Dec 16 2022, 7:49 AM

To me looks good, approved. But I prefer someone more hands-on with the tiling interface to have a look too (@mravishankar).

This revision is now accepted and ready to land.Dec 16 2022, 7:49 AM

To me looks good, approved. But I prefer someone more hands-on with the tiling interface to have a look too (@mravishankar).

They are very similar to the version in IREE, and they are all reviewed by Mahesh. So I think it's fine to land the commit.

This revision was landed with ongoing or failed builds.Dec 16 2022, 1:07 PM
This revision was automatically updated to reflect the committed changes.