Repository navigation
Rework LinalgBufferize pass. - #5539
Conversation
|
Might be better to just treat this as a new pass. Its significantly different from the old pass (cause the old version was just too brittle and almost at end-of-life. |
ThomasRaoux
left a comment
There was a problem hiding this comment.
Added few more nits. This doesn't support SCF ops right? Does that mean it won't work with our current flow? Is the idea to rely on tiled_loop op?
There is nothing to do for |
ThomasRaoux
left a comment
There was a problem hiding this comment.
Looks good to me. Do the comment line 15 to 25 still apply? Those seem out of date (github doesn't let me comment on it since it wasn't modified...)
The bufferization pass on the linalg on tensors path was an arbitrary set of methods put in place to connect linalg on tensors to the post tile+distribute codegeneration on CPU and GPU. This PR cleans up the logic to better handle the tensor -> memref conversion. In particular 1) Adds an analysis step to figure out which tensors can be mapped to the same memref object. This also provides information of what tensors are eventually mapped to the output of the dispatch region. In such cases, the output is used to compute the values in place reducing the need for copies and intermediate allocations. 2) Use this analysis step to convert operations from tensors to memrefs. 3) Use the `readonly`, `readwrite` and `writeonly` attributes to avoid copies when possible. All of this uses logic similar to the Tied operands/results approach that the bufferization in the sandbox uses. Indeed this pass might eventually subsumed by a bufferization pass in the sandbox and to be upstreamed. Till that happens, this rewrite gives something that is similar in spirit.
552ab17 to
7213fc1
Compare
asaadaldien
left a comment
There was a problem hiding this comment.
LGTM! Lets run the benchmarks this to make sure no extra alloc + copies are inserted.
I checked the bufferization manually to see there no allocs and unnecessary copies. Plus these seem on par https://buildkite.com/iree/iree-android-benchmark/builds/2341 |
antiagainst
left a comment
There was a problem hiding this comment.
Cool! Nice refactoring, Mahesh! Much better.
I just have a few nits.
The bufferization pass on the linalg on tensors path was an arbitrary
set of methods put in place to connect linalg on tensors to the post
tile+distribute codegeneration on CPU and GPU. This PR cleans up the
logic to better handle the tensor -> memref conversion.
In particular
the same memref object. This also provides information of what
tensors are eventually mapped to the output of the dispatch
region. In such cases, the output is used to compute the values in
place reducing the need for copies and intermediate allocations.
readonly,readwriteandwriteonlyattributes to avoidcopies when possible.
All of this uses logic similar to the Tied operands/results approach
that the bufferization in the sandbox uses. Indeed this pass might
eventually subsumed by a bufferization pass in the sandbox and to be
upstreamed. Till that happens, this rewrite gives something that
is similar in spirit.
Fixes #4734
Fixes #5013