With the sparse work ramping up, I am making some support I have been implementing more broadly available.

Because MLIR is not a general-purpose programming language, it can be tedious to set up test inputs in benchmarks and integration tests. For sparse matrices in particular, reading an external file is much more preferable than programmatically encoding all nonzeros of test matrices.

To simplify benchmarking and testing sparse computations, I have written a very small runtime support library to read sparse matrices in the Matrix Market Exchange Format, since this has become a popular format to share and distribute sparse matrices. With this runtime support library, filling a sparse storage scheme is as simple as running the following MLIR code. The part on the dots consist of inserting the nonzeros of the test matrix into the sparse storage scheme used by the benchmark or integration test.

```
call @openMatrix(â€śmatrix.mtxâ€ť, %m, %n, %nnz)
: (!llvm.ptr<i8>, memref<index>,
memref<index>, memref<index>) -> ()
///
// .... get ready for a m x n matrix A with nnz nonzeros ....
//
%u = load %nnz[] : memref<index>
scf.for %k = %c0 to %u step %c1 {
call @readMatrixItem(%i, %j, %d)
: (memref<index>, memref<index>, memref<f64>) -> ()
//
// .... process nonzero A[%i,%j] = %d ....
//
}
call @closeMatrix() : () -> ()
```

I will send out the CL with this library and a sample integration shortly. Note that this library is * not* part of core MLIR. It is merely a convenience library to simplify sparse matrix setup in tests and benchmarking.