This is an archive of the discontinued LLVM Phabricator instance.

[mlir][sparse] avoid creating temporary unordered COO buffer when reshape sparse tensor.
ClosedPublic

Authored by Peiming on Mar 29 2023, 6:01 PM.

Diff Detail

Event Timeline

Peiming created this revision.Mar 29 2023, 6:01 PM
Herald added a project: Restricted Project. · View Herald Transcript
Peiming requested review of this revision.Mar 29 2023, 6:01 PM
aartbik added inline comments.Mar 29 2023, 6:05 PM
mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
387–388

These comment doc needs some updating

397

debug info?

wrengr added inline comments.Mar 29 2023, 6:06 PM
mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
391

I'm pretty sure that should be dstTp

Peiming updated this revision to Diff 509525.Mar 29 2023, 6:06 PM

remove debugging code.

Peiming marked 3 inline comments as done.Mar 29 2023, 6:07 PM
Peiming updated this revision to Diff 509526.Mar 29 2023, 6:11 PM

update comments.

Peiming updated this revision to Diff 509527.Mar 29 2023, 6:12 PM

update comments

wrengr added inline comments.Mar 29 2023, 6:12 PM
mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
390–391

I think it'd be cleaner to use SparseTensorType from the beginning, instead of having both RankedTensorType and SparseTensorType variants floating around. That's very easily doable by changing the first few lines of this method to:

const auto srcTp = getSparseTensorType(srcTensor);
const auto dstTp = getSparseTensorType(op.getResult());
if (!srcTp.hasEncoding() || !dstTp.hasEncoding())
  return failure();

Since RankedTensorType supports all the helper methods of SparseTensorEncodingAttr, you shouldn't need the srcEnc/dstEnc variables anymore (can just use srcTp/dstTp instead). But if there are places where you need them, you can always:

const auto srcEnc = srcTp.getEncoding();
const auto dstEnc = dstTp.getEndocing();
aartbik accepted this revision.Mar 29 2023, 6:19 PM
This revision is now accepted and ready to land.Mar 29 2023, 6:19 PM
wrengr accepted this revision.Mar 29 2023, 6:21 PM

(Assuming my previous comment is implemented)

Peiming updated this revision to Diff 509529.Mar 29 2023, 6:23 PM

address comments.

Peiming marked an inline comment as done.Mar 29 2023, 6:23 PM
This revision was landed with ongoing or failed builds.Mar 29 2023, 6:30 PM
This revision was automatically updated to reflect the committed changes.