This is an archive of the discontinued LLVM Phabricator instance.

[mlir][sparse] Simplifying closure
ClosedPublic

Authored by wrengr on May 19 2022, 2:05 PM.

Details

Summary

By closing over the rank itself rather than this, we save a method call on each iteration. A minor optimization, but one that adds up.

Depends On D126016

Diff Detail

Event Timeline

wrengr created this revision.May 19 2022, 2:05 PM
wrengr requested review of this revision.May 19 2022, 2:05 PM
aartbik accepted this revision.May 19 2022, 3:09 PM

Oh, nice, I wonder if that makes reading the very large tensors slightly faster again!

mlir/lib/ExecutionEngine/SparseTensorUtils.cpp
176

const even?

This revision is now accepted and ready to land.May 19 2022, 3:09 PM
This revision was automatically updated to reflect the committed changes.
wrengr marked an inline comment as done.May 19 2022, 4:50 PM
wrengr added inline comments.
mlir/lib/ExecutionEngine/SparseTensorUtils.cpp
176

Adding const wouldn't change anything here, since we're closing over rank by value (and the values stored in a closure are always const).

Things would be different if rank were a pointer (like this) or if we closed over it by reference ([&rank](...){...}), since in both cases the closure would end up storing something like T* const ptr. So if we wanted to prohibit mutation we'd need the extra const on the thing being closed over, so that the closure instead stores T const* const ptr.