-
Notifications
You must be signed in to change notification settings - Fork 29
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
[BUG] Loop carried dependences should be SSA values not memory operations #123
Comments
I agree that generating iteration variables may be helpful for some compiler passes. However, it is somehow not an easy job to determine whether a variable is a reduction variable from the frontend, so we currently do not support this feature. The I haven't figured out a good way to resolve this issue. Probably some sophisticated frontend analysis pass may help generate this kind of reduction loops. |
I think I found a solution to this problem: https://github.com/cornell-zhang/amc-dialect/pull/64 |
This looks cool! Could you provide an example of the original MLIR code and the code after this pass? @andrewb1999 |
Yeah so this is the code before the pass:
and this is the code after the pass:
you can see the load and store on sum have been removed and replaced with iter_args and an affine.yield. The sum memref should then be able to be removed entirely using store-load forwarding. |
Describe the bug
Neither writing kernels with primitives like
matmul()
or usingallo.grid()
make use ofaffine.for
's ability to contain iteration arguments. For us, this is important for pipelining. Here is an example of the MLIR produced bytest_reduce()
(shown further down).To Reproduce
The linalg dialect compounds the issue, because it lowers linalg to affine loops without an accumulator:
But even with an explicit accumulator in a single memref cell, I can't get it to be raised to SSA values:
Buggy output
I was not hopeful that the existing MLIR passes would help with this issue, but I tried anyways by running
mlir-opt --convert-linalg-to-affine-loops --affine-scalrep --lower-affine --convert-scf-to-cf --mem2reg
It is only expected to work on unstructured control flow, but I could not get it to work for that.
Expected behavior
Here is an example of how we do matmul in affine that uses iteration arguments to assist the pipelining pass:
Perhaps there are the right patterns/passes in MLIR to accomplish what we want, but I haven't found them yet. Maybe we will have to write our own pass for this or lower the AST differently.
The text was updated successfully, but these errors were encountered: