This is an archive of the discontinued LLVM Phabricator instance.

[mlir][taco] Use sparse_tensor.out to write sparse tensors to files.
ClosedPublic

Authored by bixia on Feb 3 2022, 4:54 PM.

Details

Summary

Add a Python method, output_sparse_tensor, to use sparse_tensor.out to write
a sparse tensor value to a file.

Modify the method that evaluates a tensor expression to return a pointer of the
MLIR sparse tensor for the result to delay the extraction of the coordinates and
non-zero values.

Implement the Tensor to_file method to evaluate the tensor assignment and write
the result to a file.

Add unit tests. Modify test golden files to reflect the change that TNS outputs
now have a comment line and two meta data lines.

Diff Detail

Event Timeline

bixia created this revision.Feb 3 2022, 4:54 PM
bixia requested review of this revision.Feb 3 2022, 4:54 PM
aartbik added inline comments.Feb 3 2022, 5:15 PM
mlir/test/Integration/Dialect/SparseTensor/taco/test_MTTKRP.py
49–51

Why don't we simply use

filecmp.cmp()

as in test_SpMM.py?

and test for the exact contents of the golden file vs computed file.
We don't have any accuracy issues, it should be sorted the same way always,
and that we verify the metadata for correctness too.

mlir/test/Integration/Dialect/SparseTensor/taco/test_SpMM.py
36

same

37

this seems the opposite of what I think is better

why not add the

; extended FROSTT format

to the golden file and we are done?

mlir/test/Integration/Dialect/SparseTensor/taco/test_SpMV.py
49–50

same

mlir/test/Integration/Dialect/SparseTensor/taco/tools/mlir_pytaco.py
853–864

can we avoid the codeup for unpacked()?
perhaps simply by packing?

860

is this lexicographically sorted?

bixia updated this revision to Diff 406106.Feb 4 2022, 2:26 PM

Add testing_utils for comparing results.

mlir/test/Integration/Dialect/SparseTensor/taco/test_MTTKRP.py
49–51

Per offline chat, I am adding a testing_utils for comparing result.

mlir/test/Integration/Dialect/SparseTensor/taco/test_SpMM.py
36

Addressing this with testing_utils.

37

Addressing this with testing_utils.

mlir/test/Integration/Dialect/SparseTensor/taco/test_SpMV.py
49–50

Similar to the above.

mlir/test/Integration/Dialect/SparseTensor/taco/tools/mlir_pytaco.py
853–864

Per offline chat, I add a TODO here and will fix this in the next PR.

860

The coordinates produced for a dense tensor are in lexicographically ordered. However, the values added by user through the Tensor.Insert method are not ordered.
Per offline conversation, I add a TODO here and will fix this in the next PR along with fixing the definition of "dense tensors".

aartbik accepted this revision.Feb 7 2022, 6:00 PM
aartbik added inline comments.
mlir/test/Integration/Dialect/SparseTensor/taco/tools/mlir_pytaco.py
860

OK, next revision sounds good.

mlir/test/Integration/Dialect/SparseTensor/taco/tools/testing_utils.py
11

I like this! All logic in once place, so we can later decide to test more/less/different!

22

note that technically there could be more than one comment line
of course, this is a very controlled environment, so okay for now

33

do we really need the float = 0.01 rtol? Can it be less?
That seems a pretty big difference, right?

This revision is now accepted and ready to land.Feb 7 2022, 6:00 PM
bixia added inline comments.Feb 8 2022, 8:41 AM
mlir/test/Integration/Dialect/SparseTensor/taco/tools/testing_utils.py
33

right, changed to 0.0001

bixia updated this revision to Diff 406858.Feb 8 2022, 8:42 AM

Change rtol from 0.001 to 0.00001.

This revision was landed with ongoing or failed builds.Feb 8 2022, 8:47 AM
This revision was automatically updated to reflect the committed changes.