Repository navigation
[Integrate] Make IREE compatible with the new memref.assume_alignment semantic change. - #20913
Conversation
Signed-off-by: hanhanW <[email protected]>
Signed-off-by: hanhanW <[email protected]>
Signed-off-by: hanhanW <[email protected]>
Signed-off-by: hanhanW <[email protected]>
Signed-off-by: hanhanW <[email protected]>
Signed-off-by: hanhanW <[email protected]>
|
Note: there are some dump Input: func.func @foo(%0: memref<10xf32>) {
memref.assume_alignment %0, 32 : memref<10xf32>
return
}Output from module {
func.func @foo(%arg0: memref<10xf32>) {
%assume_align = memref.assume_alignment %arg0, 32 : memref<10xf32>
return
}
} |
Signed-off-by: hanhanW <[email protected]>
Signed-off-by: hanhanW <[email protected]>
Signed-off-by: hanhanW <[email protected]>
Signed-off-by: hanhanW <[email protected]>
Signed-off-by: hanhanW <[email protected]>
Signed-off-by: hanhanW <[email protected]>
Signed-off-by: hanhanW <[email protected]>
|
Yeah, an assume_alignment that isn't used anywhere (that example that doesn't capture the SSA value) will get dead-code-eliminated, IIRC |
| patterns.add<RemoveAssumeAlignOp>(context); | ||
| populateCleanMemRefAssumeAlignmentPatterns(patterns); | ||
| context->getOrLoadDialect<IREE::Util::UtilDialect>() | ||
| ->getCanonicalizationPatterns(patterns); |
There was a problem hiding this comment.
Why do we need this if we just end up folding them subsequently anyway?
There was a problem hiding this comment.
Good question!
This is needed because the Linalg/LinalgExt to loops passes can generate memref.dim ops for ub when there is a dynamic shape. The standard pipeline runs the FoldDimOp pattern to fold memref.dim op away in canonicalization pass when the source is IREE HAL bindings. (Because they implement ShapeAwareOpInterface interface.)
However, it is not happening when the source of memref.dim is memref.assume_alignment, which does not implement the interface. This is why I need to implement the pattern that makes it query the dim size from the source instead; kick in the specific canonicalization patterns in the pre-processing.
To make this type of casting work with ShapeAwareOpInterface, I think we'll need to make the interface methods return std::optional<*> instead. Then they can have an indirect query and the world would be easier. I can file an issue for this and start a quick discussion with Ben there, if you think it is helpful.
(I think the memref.assume_alignment semantic change introduces way more issues than I expected; it does not play well with the folding/hoisting/etc transformations. This is why this big switch is hard. IMO, it is better if upstream can keep the both semantic, like create a new op for the new semantic and deprecate the old one later. My guess is that we may be one of few users that has such broad e2e coverage.)
There was a problem hiding this comment.
I was wrong on this. I implemented the folder in 94d2e31, and I think it is needed for recovering all the memref.assume_alignment status. Currently, few of dispatches disable the support.
I'll revisit this part after I fix all the assuem_alignment issues.
Signed-off-by: hanhanW <[email protected]>
… semantic change. (#20913) This drops a revert: iree-org/llvm-project@435bb50 To make IREE compatible with the new `memref.assuem_assignment` semantics, the revision moves the op creation from OneShotBufferization to post bufferization passes. It is mainly for reducing the burdens of bufferization analysis. Otherwise, it'd easily generate redundant copies between the original memref and the result of AssumeAlignment op. Furthermore, there are several missing support when AssumeAlignment op is present in SSA chain. - The `FlattenMemRefSubspanPass` needs to be improved to take the op into account. - We are missing a pattern that propagates the `memref.dim` ops for `memref.dim(memref.assume_alignment)` cases. It reduces the deps from AssumeAlignment op, so we don't need to add more patterns for it. - The chained memref.assume_alignment ops are not folded away. This can be done as a canonicalization pattern. The revision adds a workaround for early-bufferization dispatch, and it will be removed once we implement the pattern. - Need to teach SPIRVVectorizeLoadStore pass to take AssumeAlignment ops into account. - Need to teach VMVX ResolveBufferDescriptors pass to take AssumeAlignment ops into account. The new pattern is copied from the other one, and a refactoring can be done in the future. For now, we mainly want to drop the revert, and we can easily refactor the code out. So it is a TODO for now. - It triggers failures in hoisting vector transfer ops when AssumeAlignment ops are present. We don't know the root cause yet, and it is too complicated and hard to fix it within the revision. Because the implementation is in upstream. See #20912 for reproducer. Closes #20908 --------- Signed-off-by: hanhanW <[email protected]>
This drops a revert: iree-org/llvm-project@435bb50
To make IREE compatible with the new
memref.assuem_assignmentsemantics, the revision moves the op creation from OneShotBufferization to post bufferization passes. It is mainly for reducing the burdens of bufferization analysis. Otherwise, it'd easily generate redundant copies between the original memref and the result of AssumeAlignment op.Furthermore, there are several missing support when AssumeAlignment op is present in SSA chain.
FlattenMemRefSubspanPassneeds to be improved to take the op into account.memref.dimops formemref.dim(memref.assume_alignment)cases. It reduces the deps from AssumeAlignment op, so we don't need to add more patterns for it.Closes #20908