-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mlir][tensor] Bufferize tensor.reshape with non-identity layouts #65654
Conversation
Bufferization of tensor.reshape generates a memref.reshape operation. memref.reshape requires the source memref to have an identity layout. The bufferization process may result in the source memref having a non-identity layout, resulting in a verification failure. This change causes the bufferization interface for tensor.reshape to copy the source memref to a new buffer when the source has a non-identity layout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the documentation, memref.reshape
seems to expect an identity layout for both inputs. Do we need to take care of the case with the non-identity map?
https://mlir.llvm.org/docs/Dialects/MemRef/#memrefreshape-memrefreshapeop
The source and destination types are compatible if both have the same element type, same number of elements, address space and identity layout map.
Hi @Lewuathe, are you asking whether the restrictions on At the moment, bufferization can create |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sabauma Sorry, my comment was not clear enough.
According to the documentation, the memref.reshape
expects both source and destination type to have identity layout map. I thought memref.reshape
does not get non-identity map input technically, which means we might not need to take care of the case where memref.reshape
has non-identity input in the bufferization pass too.
But as the test you have wrote indicated, we can pass the non-identity layout tensor to memref.reshape
by using tensor.extract_slice
. So my assumption might be wrong.
In that case, can we improve the documentation to say we can pass non-identity layout memref to memref.reshape
op?
@Lewuathe The change I made in the bufferization interface for Without the change to the bufferization interface, the bufferization process will produce IR that fails verification. From my perspective, the issue I'm trying to address is that bufferization produces an invalid
I don't think we want to do that. I suspect the lowerings depend on this identity map requirement. I think the fact that bufferization will try to create It may be possible to enhance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the intention of the change. It has made things much clearer to me. This change just guards the case where the input does not have an identity layout.
It may be possible to enhance memref.reshape to handle non-identity layout maps, but that is probably a more invasive change.
Yes, I agree. Even if it's the bug of the upstream to generate the invalid memref type with non-identity map, it would be a big fix.
Hi @Lewuathe, if there are no other comments, do you mind merging this PR. I do not have write access. |
@sabauma Okay, I'll merge this commit. Thanks for the contribution! |
…vm#65654) Bufferization of tensor.reshape generates a memref.reshape operation. memref.reshape requires the source memref to have an identity layout. The bufferization process may result in the source memref having a non-identity layout, resulting in a verification failure. This change causes the bufferization interface for tensor.reshape to copy the source memref to a new buffer when the source has a non-identity layout.
Bufferization of tensor.reshape generates a memref.reshape operation. memref.reshape requires the source memref to have an identity layout. The bufferization process may result in the source memref having a non-identity layout, resulting in a verification failure.
This change causes the bufferization interface for tensor.reshape to copy the source memref to a new buffer when the source has a non-identity layout.