metagraph-dev / mlir-graphblas

MLIR tools and dialect for GraphBLAS
https://mlir-graphblas.readthedocs.io/en/latest/
Apache License 2.0
15 stars 6 forks source link

Fuse graphblas.apply with graphblas.update #262

Open paul-tqh-nguyen opened 2 years ago

paul-tqh-nguyen commented 2 years ago
        negative_a = irb.arith.mulf(a, c_negative_1_f64)
        factor = irb.graphblas.apply(eye, "second", right=negative_a)
        irb.graphblas.update(L, factor, "plus")
        two_over_a = irb.arith.divf(c2_f64, a)
        factor = irb.graphblas.apply(factor, "times", right=two_over_a)

I don't think this case is handled yet. I think we should be able to fuse the 2 graphblas.apply ops and the graphblas.update op into a single op (either graphblas.apply_generic or some new op).

This is motivated by GraphWave.

paul-tqh-nguyen commented 2 years ago

@jim22k and I discussed this. It seems that graphblas.apply with an inplace attribute will solve all the use cases we've seen of this situation in GraphWave.

One other optimization worth considering is the cases where we have:

        negative_a = irb.arith.mulf(a, c_negative_1_f64)
        factor = irb.graphblas.apply(eye, "second", right=negative_a)
        irb.graphblas.update(L, factor, "plus")

A cursory look at GraphWave brought this motivation for the original plan to my attention:

        signal = eye
        # ...
        negative_signal = irb.graphblas.apply(signal, "ainv")
        irb.graphblas.update(negative_signal, twf_cur, "plus")

This could be optimized to:

        c_negative_1_f64 = irb.arith.constant(-1, "f64")
        irb.graphblas.update(c_negative_1_f64, twf_cur, "plus", mask=signal)

This is found in GraphWave and is the only instance I've found.

@jim22k, got any thoughts? I'm thinking since graphblas.apply with an inplace attribute solves the majority of cases, we should move this example to a new issue with lower priority.

jim22k commented 2 years ago

I agree with restricting this issue to graphblas.apply with inplace.

The other case you found with the scalar and a mask is actually part of graphblas.assign, which we haven't written yet. We should tackle assign sometime this quarter because it is useful.