This is an archive of the discontinued LLVM Phabricator instance.

[mlir][sparse] Add readCOOElement for reading a sparse tensor element from files.
ClosedPublic

Authored by bixia on Oct 11 2022, 5:00 PM.

Details

Summary

Use the routine for openSparseTensorCOO and getSparseTensorReaderNext.

Diff Detail

Event Timeline

bixia created this revision.Oct 11 2022, 5:00 PM
Herald added a project: Restricted Project. · View Herald Transcript
bixia requested review of this revision.Oct 11 2022, 5:00 PM
bixia updated this revision to Diff 466981.Oct 11 2022, 5:11 PM

Rebase.

aartbik accepted this revision.Oct 12 2022, 10:45 AM
This revision is now accepted and ready to land.Oct 12 2022, 10:45 AM
wrengr requested changes to this revision.Oct 12 2022, 12:20 PM
wrengr added inline comments.
mlir/include/mlir/ExecutionEngine/SparseTensor/File.h
222–233

I think it's better to make this a method of the class rather than a standalone function, since that gives it a more uniform calling syntax in addition to helping avoid breaking encapsulation (since we'd like to avoid having readLine be public).

In my suggested edit I've also reordered the arguments to match the prevailing style (we pass the size of arrays/buffers before the pointer for arrays/buffers). And since we have the getRank method already, I've added an assertion to ensure that the caller-provided rank agrees.

In my suggested edit I've also lifted the conditional on perm out of the loop. Though really it'd be better to lift it further out in order to avoid checking every time the method is called. That can be easily achieved by passing the permutation to the SparseTensorReader ctor and saving it in the object (and constructing the identity permutation if there is no caller-provided one).

This revision now requires changes to proceed.Oct 12 2022, 12:20 PM

Following up after the issues addressed by D135811:

Do note that the proposed SparseTensorReader::readCOOElement method can still return the raw V value, since this is a C++ library. It's only the macros that call the method which need to worry about wrapping that V into a memref

bixia updated this revision to Diff 467296.Oct 12 2022, 4:25 PM

Move the routine to inside the sparse tensor reader.

bixia marked an inline comment as done.Oct 12 2022, 4:25 PM
bixia added inline comments.
mlir/include/mlir/ExecutionEngine/SparseTensor/File.h
222–233

Move the routine to the sparse tensor reader.

bixia updated this revision to Diff 467297.Oct 12 2022, 4:29 PM
bixia marked an inline comment as done.

Fix build error.

bixia updated this revision to Diff 467488.Oct 13 2022, 8:26 AM

Rebase.

bixia updated this revision to Diff 467582.Oct 13 2022, 1:10 PM

Fix format.

bixia updated this revision to Diff 467929.Oct 14 2022, 2:41 PM

Remove perm parameter from the routine.

bixia added inline comments.Oct 14 2022, 2:43 PM
mlir/include/mlir/ExecutionEngine/SparseTensor/File.h
222–233

Reordered rand and indices from the parameter list.
Remove perm from the parameter list.

bixia updated this revision to Diff 467956.Oct 14 2022, 4:12 PM

Fix format.

bixia added inline comments.Oct 14 2022, 4:15 PM
mlir/include/mlir/ExecutionEngine/SparseTensor/File.h
222–233

The COO file doesn't have a notation for dim permutation, only the SparseTensor encode has the notation for dim permutation. So it doesn't look right to have _mlir_ciface_getSparseTensorReaderNext handle dim perm. With the current change, we only handle dim perm for inserting the read elements to a SparseTensor.

bixia updated this revision to Diff 467962.Oct 14 2022, 4:42 PM

Use the code @wrengr suggested.

wrengr accepted this revision.Oct 14 2022, 4:47 PM
This revision is now accepted and ready to land.Oct 14 2022, 4:47 PM