Open paul-tqh-nguyen opened 3 years ago
@jim22k and I came up with a plan to address this. I'll describe our proposed approach below.
We'll want to change the standard passes we use.
--graphblas-structuralize
. This pass will make our code more optimization-friendly. It'll add graphblas.convert_layout
ops where necessary (but won't in cases where the given types are handled properly in --graphblas-lower
). This will add the simplest set of graphblas.convert_layout
ops to get the thing working (the next optimization pass will fix any slow ops sequences introduced). --graphblas-optimize
. This will do additional optimizations besides those already present in --graphblas-optimize
, e.g.
graphblas.convert_layout
+ graphblas.apply
+ graphblas.convert_layout
=> graphblas.apply
+ graphblas.convert_layout
graphblas.apply
? Including graphblas.apply
?graphblas.convert_layout
+ graphblas.convert_layout
=> graphblas.convert_layout
graphblas.transpose
+ graphblas.transpose
=> graphblas.transpose
a_CSC @ b_CSR
normally requires 2 graphblas.convert_layout
ops, can do (b_CSR @ a_CSC).transpose
with at most 1 graphblas.convert_layout
op.--graphblas-lower
pass that will handle a very specific set of cases, e.g. code with a_CSC @ b_CSR
that is not lowered with the previous two passes will be untouched by this pass.
Implementation details (and misc. answers to misc. questions we had during our discussion):
CSC @ CSR
. However, this does not necessarily mean the rewrite patterns in --graphblas-lower
will lower them. We've been previously writing the rewrite patterns by overriding the matchAndRewrite
method. We should instead override the match
method and the rewrite
method independently (see here). The match
methods will be more strict and will limit the cases handled by each rewrite pattern used in each pass. CC @eriknw
After reading Dan Gohman's article on canonicalization (as recommended by MLIR), it turns out that there's no agreed upon strict clear line that differentiates optimization/transformation from canonicalization.
Since MLIR's canonicalization functionality is implemented as a pass, there's currently no impactful difference for us right now to implement any of the passes I've described above via canonicalization. Thus, I'm choosing to avoid using canonicalization at this time. If we decide to do so in the future, it'll be a trivial refactoring since canonicalization is implemented via rewrite patterns.
Currently, in our lowering passes, we add
graphblas.convert_layout
ops when we're given a CSC matrix when the "real" lowering expects a CSR matrix.It might be cleaner to use canonicalization passes passes to do this sort of thing.
It might also be a good idea to add tensor casts to convert fixed shaped tensors to tensors using
?
in the shape. This would help with https://github.com/metagraph-dev/mlir-graphblas/issues/129.For
graphblas.comment
ops, it's unclear whether or not these should be handled during lowering or canonicalization.