This is an archive of the discontinued LLVM Phabricator instance.

[mlir][sparse] generalize invariant expression handling in sparse compiler
ClosedPublic

Authored by aartbik on Nov 23 2020, 11:14 AM.

Details

Summary

Generalizes invariant handling to anything defined outside the Linalg op
(parameters and SSA computations). Fixes bug that was using parameter number
as tensor number.

Diff Detail

Event Timeline

aartbik created this revision.Nov 23 2020, 11:14 AM
aartbik requested review of this revision.Nov 23 2020, 11:14 AM
aartbik edited the summary of this revision. (Show Details)Nov 23 2020, 2:54 PM
penpornk accepted this revision.Nov 24 2020, 1:36 PM

Thank you for the CL! The generated MLIR code looks good to me.

mlir/lib/Dialect/Linalg/Transforms/Sparsification.cpp
66

A bit curious if union would be worth it. But then we'll have to have a nested union in a struct because kind is always there (and then bundle e0 and e1 together as one choice). So I think it's not worth the effort.

This revision is now accepted and ready to land.Nov 24 2020, 1:36 PM
aartbik added inline comments.Nov 24 2020, 1:39 PM
mlir/lib/Dialect/Linalg/Transforms/Sparsification.cpp
66

Coming from a classical C approach to compiler writing, that is always my instinct too! Once the dust settles we can always revisit our data structures and optimize, but I actually may use the "val" field elsewhere too (when implementing loop hoisting during sparse codegen, where we need a place to store the SSA value). So I think we will use this fields even for the others, making a struct better.

mehdi_amini added inline comments.Dec 1 2020, 11:45 AM
mlir/lib/Dialect/Linalg/Transforms/Sparsification.cpp
66

Can you add assertions for all the invariants in the constructor?

I'd be worried about growing this struct beyond what it models right now: if the invariants have to get more complex it'll be worth revisiting this and model this as a class with better encapsulation.

aartbik marked an inline comment as done.Dec 2 2020, 9:22 AM
aartbik added inline comments.
mlir/lib/Dialect/Linalg/Transforms/Sparsification.cpp
66

Thanks Medhi. I just noticed this post-commit feedback.

I will add assertions in the next CL. Also, I suspect this struct (and Merger class) may at some point migrate into their own utility file. It depends a bit on how many more "features" are required on the path to full bufferization :-)