6
6
//
7
7
// ===----------------------------------------------------------------------===//
8
8
//
9
- // This header file defines utilities for lowering and accessing sparse tensor
10
- // types.
9
+ // This header file defines utilities for the sparse memory layout.
11
10
//
12
11
// ===----------------------------------------------------------------------===//
13
12
@@ -23,13 +22,15 @@ namespace mlir {
23
22
namespace sparse_tensor {
24
23
25
24
// ===----------------------------------------------------------------------===//
26
- // SparseTensorDescriptor and helpers, manage the sparse tensor memory layout
27
- // scheme.
25
+ // SparseTensorDescriptor and helpers that manage the sparse tensor memory
26
+ // layout scheme during "direct code generation" (i.e. when sparsification
27
+ // generates the buffers as part of actual IR, in constrast with the library
28
+ // approach where data structures are hidden behind opaque pointers).
28
29
//
29
- // Sparse tensor storage scheme for rank-dimensional tensor is organized
30
- // as a single compound type with the following fields. Note that every
31
- // memref with ? size actually behaves as a "vector", i.e. the stored
32
- // size is the capacity and the used size resides in the memSizes array .
30
+ // The sparse tensor storage scheme for a rank-dimensional tensor is organized
31
+ // as a single compound type with the following fields. Note that every memref
32
+ // with ? size actually behaves as a "vector", i.e. the stored size is the
33
+ // capacity and the used size resides in the storage_specifier struct .
33
34
//
34
35
// struct {
35
36
// ; per-dimension d:
@@ -40,15 +41,37 @@ namespace sparse_tensor {
40
41
// memref<? x idx> indices-d ; indices for sparse dim d
41
42
// ; if singleton:
42
43
// memref<? x idx> indices-d ; indices for singleton dim d
44
+ //
43
45
// memref<? x eltType> values ; values
44
46
//
45
- // ; sparse tensor metadata
46
- // struct {
47
+ // struct sparse_tensor.storage_specifier {
47
48
// array<rank x int> dimSizes ; sizes for each dimension
48
49
// array<n x int> memSizes; ; sizes for each data memref
49
50
// }
50
51
// };
51
52
//
53
+ // In addition, for a "trailing COO region", defined as a compressed
54
+ // dimension followed by one ore more singleton dimensions, the default
55
+ // SOA storage that is inherent to the TACO format is optimized into an
56
+ // AOS storage where all indices of a stored element appear consecutively.
57
+ // In such cases, a special operation (sparse_tensor.indices_buffer) must
58
+ // be used to access the AOS index array. In the code below, the method
59
+ // `getCOOStart` is used to find the start of the "trailing COO region".
60
+ //
61
+ // Examples.
62
+ //
63
+ // #CSR storage of 2-dim matrix yields
64
+ // memref<?xindex> ; pointers-1
65
+ // memref<?xindex> ; indices-1
66
+ // memref<?xf64> ; values
67
+ // struct<(array<2 x i64>, array<3 x i64>)>) ; dim0, dim1, 3xsizes
68
+ //
69
+ // #COO storage of 2-dim matrix yields
70
+ // memref<?xindex>, ; pointers-0, essentially [0,sz]
71
+ // memref<?xindex> ; AOS index storage
72
+ // memref<?xf64> ; values
73
+ // struct<(array<2 x i64>, array<3 x i64>)>) ; dim0, dim1, 3xsizes
74
+ //
52
75
// ===----------------------------------------------------------------------===//
53
76
54
77
enum class SparseTensorFieldKind : uint32_t {
@@ -198,11 +221,11 @@ class SparseTensorSpecifier {
198
221
TypedValue<StorageSpecifierType> specifier;
199
222
};
200
223
201
- // / A helper class around an array of values that corresponding to a sparse
202
- // / tensor, provides a set of meaningful APIs to query and update a particular
203
- // / field in a consistent way.
204
- // / Users should not make assumption on how a sparse tensor is laid out but
205
- // / instead relies on this class to access the right value for the right field.
224
+ // / A helper class around an array of values that corresponds to a sparse
225
+ // / tensor. This class provides a set of meaningful APIs to query and update
226
+ // / a particular field in a consistent way. Users should not make assumptions
227
+ // / on how a sparse tensor is laid out but instead rely on this class to access
228
+ // / the right value for the right field.
206
229
template <typename ValueArrayRef>
207
230
class SparseTensorDescriptorImpl {
208
231
protected:
0 commit comments