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

Add graphblas.print op #183

Closed paul-tqh-nguyen closed 2 years ago

paul-tqh-nguyen commented 3 years ago

NOTE: This PR doesn't include tests for the behavior of graphblas.print. I'm leaving that as future work since it's non-trivial.


Example:


from mlir_graphblas import MlirJitEngine
from mlir_graphblas.tests.jit_engine_test_utils import GRAPHBLAS_PASSES

engine = MlirJitEngine()

mlir_text = '''

module {

    func @main() -> () {
        %c99 = constant 99 : index
        %0 = constant 1.3 : f32
        %1 = constant 34 : i8
        graphblas.print %0, %0, %0, %0 { strings = ["first line : "] } : f32, f32, f32, f32
        graphblas.print %c99 { strings = ["second line : ", " string_a", " string_b", " string_c"] } : index
        graphblas.print %0, %1 { strings = ["third line : ", " |\\"| "] } : f32, i8
        return
    }

}

'''

engine.add(mlir_text, GRAPHBLAS_PASSES)

engine.main()

Execution:

(mlirgraphblas) pnguyen@CONDA-0584:/Users/pnguyen/code/mlir-graphblas$ python3 test.py
first line : 1.31.31.31.3
second line : 99 string_a string_b string_c
third line : 1.3 |"| 34
(mlirgraphblas) pnguyen@CONDA-0584:/Users/pnguyen/code/mlir-graphblas$ 

Another Example:


from mlir_graphblas import MlirJitEngine
from mlir_graphblas.mlir_builder import MLIRFunctionBuilder
from mlir_graphblas.tests.jit_engine_test_utils import GRAPHBLAS_PASSES

engine = MlirJitEngine()

ir_builder = MLIRFunctionBuilder(
    "print_func",
    input_types=['f32', 'i8', 'i64', 'index'],
    return_types=[],
)
(val_f32, val_i8, val_i64, val_index) = ir_builder.inputs
ir_builder.graphblas.print("first line : ", val_f32, val_i8, val_i64, val_index)
ir_builder.graphblas.print("second line : ", val_i64, " string_a", " string_b", " string_c")
ir_builder.graphblas.print("third line : ", val_i8, '|"|', val_index)
ir_builder.return_vars()
print_func = ir_builder.compile(engine=engine, passes=GRAPHBLAS_PASSES)

assert None is print_func(1.2, 3, 4, 5)

Execution:

(mlirgraphblas) pnguyen@CONDA-0584:/Users/pnguyen/code/mlir-graphblas$ python3 test.py
first line : 1.2345
second line : 4 string_a string_b string_c
third line : 3|"|5
(mlirgraphblas) pnguyen@CONDA-0584:/Users/pnguyen/code/mlir-graphblas$ 
coveralls commented 2 years ago

Pull Request Test Coverage Report for Build 1259376766


Changes Missing Coverage Covered Lines Changed/Added Lines %
mlir_graphblas/mlir_builder.py 9 10 90.0%
mlir_graphblas/ops.py 5 18 27.78%
<!-- Total: 14 28 50.0% -->
Totals Coverage Status
Change from base Build 1258737825: -0.3%
Covered Lines: 2830
Relevant Lines: 3385

💛 - Coveralls