-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[mlir][bufferization] Return BufferLikeType in BufferizableOpInterface #144867
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,7 +222,7 @@ AliasingValueList AllocTensorOp::getAliasingValues(OpOperand &opOperand, | |
return {}; | ||
} | ||
|
||
FailureOr<BaseMemRefType> | ||
FailureOr<BufferLikeType> | ||
AllocTensorOp::getBufferType(Value value, const BufferizationOptions &options, | ||
const BufferizationState &state, | ||
SmallVector<Value> &invocationStack) { | ||
|
@@ -245,7 +245,8 @@ AllocTensorOp::getBufferType(Value value, const BufferizationOptions &options, | |
return getOperation()->emitError("could not infer memory space"); | ||
} | ||
|
||
return getMemRefTypeWithStaticIdentityLayout(getType(), memorySpace); | ||
return cast<BufferLikeType>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: unfortunately, i didn't seem to manage to avoid this even with an addition of an implicit ctor (tried locally but didn't add it in this patch): |
||
getMemRefTypeWithStaticIdentityLayout(getType(), memorySpace)); | ||
} | ||
|
||
LogicalResult AllocTensorOp::verify() { | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
getMemorySpace()
is the main problem here why I couldn't dropbufferization::detail::asMemRefType()
(and thus work with BufferLikeType objects directly).@matthias-springer is it reasonable to assume all buffers have an associated memory space? I guess I could follow this up by another patch that extends the BufferLikeType and streamlines multiple places around the code-base.
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.
How would that help?
The memory space is optional, it could be
Attribute()
.That being said, the
bufferize
implementation ofarith.select
is hard-coded to memref types: it insertsmemref.cast
operations. Therefore, I'd say it's reasonable to also hard-code thegetBufferType
implementation to memref types.If you'd like to extend this (so that
arith.select
can work with custom buffer types), you'd have to add interface methods toBufferLikeType
to query if two buffer-like types are cast compatible.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.
I don't plan on extending
arith.select
(as of now at least) but it seems that it's going to be much less churn due to "cast to memref" / "cast to buffer-like" across multiple places if there's a memory space tied to buffer-like (which also could be optional and thus returnnullptr
).here, for instance, as I get
falseType
andtrueType
already as buffer-like by the API, I wouldn't need to cast them first to memrefs (to check memory space compatibility) and then cast "back" to buffer-like.