GraphBLAS Passes and graphblas-opt¶
The mlir-graphblas package includes an drop-in replacement for mlir-opt
called graphblas-opt which includes the custom graphblas dialect along
with all the other dialects that ship with MLIR.
This document is not intended to be a complete tutorial on graphblas-opt and acts more
as a reference manual for the passes exclusively available for graphblas-opt. For tutorials
on these passes specific to graphblas-opt, see our GraphBLAS Dialect Tutorials.
There are five passes specific to graphblas-opt with two intended usages:
Standard Lowering
--graphblas-structuralize: Lowers higher-levelgraphblasops into lower-level genericgraphblasops--graphblas-dwim: Addsconvert-layoutcalls to inputs to match the expected shape and type of genericgraphblasops--graphblas-optimize: Fuses lower-level genericgraphblasops together to eliminate temporary tensors and redundant loops.--graphblas-lower: Convertgraphblasops to thescf,std, andmemrefdialects.
Linalg Lowering
--graphblas-structuralize: Lowers higher-levelgraphblasops into lower-level genericgraphblasops--graphblas-optimize: Fuses lower-level genericgraphblasops together to eliminate temporary tensors and redundant loops.--graphblas-linalg-lower: Convertgraphblasops to thelinalgdialects, specifically tolinalg.genericcalls. These will be further lowered by thesparse_tensordialect.
--graphblas-structuralize Pass¶
The structuralization pass performs eight generic transformations:
Transform
graphblas.matrix_multiplyops into equivalentgraphblas.matrix_multiply_genericops.Transform
graphblas.applyops into equivalentgraphblas.apply_genericops.Transform
graphblas.selectops into equivalentgraphblas.select_genericops.Transform
graphblas.unionops into equivalentgraphblas.union_genericops.Transform
graphblas.intersectops into equivalentgraphblas.intersect_genericops.Transform
graphblas.updateops into equivalentgraphblas.update_genericops.Transform
graphblas.reduce_to_vectorops into equivalentgraphblas.reduce_to_vector_genericops.Transform
graphblas.reduce_to_scalarops into equivalentgraphblas.reduce_to_scalar_genericops.
--graphblas-dwim Pass¶
The DWIM (Do-What-I-Mean) pass automatically converts the layout of input matrices to conform to the requirements each pass. DWIM transformations are included for:
graphblas.transposegraphblas.reduce_to_vectorgraphblas.matrix_multiplygraphblas.matrix_multiply_reduce_to_scalar
--graphblas-optimize Pass¶
The optimization pass performs two transformations:
Combine
graphblas.matrix_multiplyfollowed bygraphblas.applyinto a singlegraphblas.matrix_multiplywith an additional scalar transformation of the output elements as they are written to memory.Combine
graphblas.matrix_multiplyfollowed bygraphblas.matrix_reduce_to_scalarinto a newgraphblas.matrix_multiply_reduce_to_scalarop that does the sparse multiply and accumulate in a single pass (rather than two passes forgraphblas.matrix_multiply).
--graphblas-lower Pass¶
The lowering pass is intended to allow the graphblas ops to be executed on
a CPU target. Although the lowering assumes the same C++ structure as is used in
the existing sparse tensor related passes in MLIR, --graphblas-lower does
not use the linalg dialect, as there is not yet support for sparse output.
The graphblas lowering pass requires a small runtime based on the MLIR
sparse runtime, but with some additional functions that allow for the
allocation, resizing, and deallocation of the sparse tensor data structure.
In general, this pass uses scf ops to handle traversing the sparse data
structure, with scf.parallel used when possible to indicate loops where the
loop body iterations are independent of each other, or are performing a
well-defined reduction.
--graphblas-linalg-lower Pass¶
The linalg lowering will eventually be a full replacement for the standard lowering pass,
once improvements are made to the sparse_tensor handling of linalg.generic.
One benefit of linalg lowering is a much smaller and simpler lowering output to maintain. Another is the ability to handle more types of inputs, eliminating the need for the DWIM pass.