This is an archive of the discontinued LLVM Phabricator instance.

[mlir][sparse] packs sparse tensor sizes using llvm.struct instead of memref
AbandonedPublic

Authored by Peiming on Dec 6 2022, 3:55 PM.

Details

Summary

The sparse compiler used to stored the dimension sizes with a MemRef<rank x index>. This patch change the memory scheme by storing the dimension size using llvm.struct<array<rank x int>>.

There are multiple reasons behind the change

  1. MemRef, in addition to pointers, stores extra information for strides and offsets, which are redundant for our case.
  2. MemRef requires deallocation to avoid memory leak, which brings us extra challenges to implement sparse tensor slice in the future as sparse tensor slices will likely to hold a different MemRef for dimension sizes, which is required to be freed after the slices is no longer needed.

Note that this scheme is also closer to how MemRef stores its dimension sizes.

Future work:
Move the memSizes MemRef into the same llvm.struct together with dimSizes, it is currently blocked by sparse_tensor.push_back operation, which only takes a MemRef memSizes as inputs.

Diff Detail

Event Timeline

Peiming created this revision.Dec 6 2022, 3:55 PM
Herald added a project: Restricted Project. · View Herald Transcript
Peiming requested review of this revision.Dec 6 2022, 3:55 PM
wrengr added inline comments.Dec 6 2022, 4:04 PM
mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorBuilder.cpp
2

The name of the file should be right-aligned.

mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorBuilder.h
2

The name of the file should be left-aligned, and the end of the comment line should include -*- C++ -*- (as per the style guide).

Peiming edited the summary of this revision. (Show Details)Dec 6 2022, 4:12 PM
Peiming edited the summary of this revision. (Show Details)
Peiming updated this revision to Diff 480676.Dec 6 2022, 4:17 PM

fix style.

Peiming marked 2 inline comments as done.Dec 6 2022, 4:17 PM
Peiming added inline comments.Dec 7 2022, 5:21 PM
mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorPasses.cpp
191

Is there any way that I can get the same bitwidth for index type as used by lowerToLLVM passes?

Peiming abandoned this revision.Dec 13 2022, 3:16 PM

Will use sparse_tensor::StorageSpecifier for the same purpose