This is an archive of the discontinued LLVM Phabricator instance.

[mlir][sparse] avoid using mutable descriptor when unnecessary (NFC)
ClosedPublic

Authored by Peiming on Jan 17 2023, 11:25 AM.

Details

Summary

Use SparseTensorDescriptor whenever not calling setters, to avoid needing to create a temporal buffer for simple query purposes.

Diff Detail

Event Timeline

Peiming created this revision.Jan 17 2023, 11:25 AM
Herald added a project: Restricted Project. · View Herald Transcript
Peiming requested review of this revision.Jan 17 2023, 11:25 AM
Peiming edited the summary of this revision. (Show Details)Jan 17 2023, 11:33 AM
Peiming updated this revision to Diff 489903.Jan 17 2023, 11:49 AM
Peiming edited the summary of this revision. (Show Details)

clean up

Peiming added inline comments.Jan 17 2023, 11:50 AM
mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp
107

I removed the optional as it never returns std::nullopt.

Peiming edited the summary of this revision. (Show Details)Jan 17 2023, 11:56 AM
Peiming edited the summary of this revision. (Show Details)Jan 17 2023, 12:09 PM
wrengr accepted this revision.Jan 17 2023, 12:26 PM

The CL description seems a bit misleading/backwards to me —since it places focus on *using* MutSparseTensorDescriptor, rather than focusing on not using it. So would be better to rephrase it to something like:

"""Use SparseTensorDescriptor whenever not calling setters, to avoid needing to create a temporal buffer for simple query purposes."""

(Though I'm thinking you mean "temporary" here rather than "temporal".)

mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorStorageLayout.h
205

I'm curious why the change here? To you anticipate needing to define ValueArrayRef to something other than ValueRange or SmallVectorImpl<Value>& ? If there's a valid reason to expect other uses, then I'm all for generalization; but if there'll only ever be those two instantiations, then it'd be better to stick with the bool templating since it explicitly ensures the invariant that those are the only two options.

(If you revert to using the bool parameter, I think you should keep the new documentation on the subclasses. Since that documentation is remains valid and helpful under both ways of structuring the code.)

259

The compiler should be smart enough to fix it, but using the helper function here means doing a redundant assertion.

This revision is now accepted and ready to land.Jan 17 2023, 12:26 PM
bixia accepted this revision.Jan 17 2023, 12:26 PM
Peiming edited the summary of this revision. (Show Details)Jan 17 2023, 12:28 PM
Peiming added inline comments.Jan 17 2023, 12:39 PM
mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorStorageLayout.h
205

I think changing it to ValueArrayRef makes it easier for readers to understand what is actually used for storage the array.

One reason I used bool at the first place is that I used to implement both mutable/immutable descriptor in this class and using enable_if to only allows setters for mutable descriptor. But the situation is changed, and this class now only holds getters, so I feel like that it make less sense to create a SparseTensorDescriptorImp<true> when it actually provides no setters.

259

Yeah, but should be okay? I would like to reuse the code here (maybe we will, though unlikely, switch to some class that does not provide operator[]).

Peiming added inline comments.Jan 17 2023, 12:40 PM
mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorStorageLayout.h
205

I think changing it to ValueArrayRef makes it easier for readers to understand what is actually used for storage the array.

*for storing the array*