I can’t point you to checked in MLIR set up code at this moment (but you can always study the runtime support library that implements the “one size fits all” solution), but I can give some pointers in the hope that is helpful to write your own MLIR set up code. Suppose you want to initialize a 3-d sparse tensor with the following contents, in extended FROSTT format.
# extended FROSTT format
3 7
3 3 4
1 1 1 1.0
1 1 4 2.0
1 2 1 3.0
1 2 2 4.0
3 1 2 5.0
3 2 3 6.0
3 2 4 7.0
In this case, the sparse compiler generates code that will need up to 3 x memref<?xindex>
for positions and 3 x memref<?xindex>
for indices (each, one per dimension) and one memref<?xf64>
for the actual numerical values.
When annotated as [ “D”, “D”, “S” ], you will have to set up only the last positions and indices array, and the values, as follows.
positions[2] = [ 0 2 4 4 4 4 4 5 7 7 ]
indices[2] = [ 0 3 0 1 1 2 3]
values = [1.000000 2.000000 3.000000 4.000000 5.000000 6.000000 7.000000 ]
The annotation [ “S”, “S”, “S” ] needs a positions and indices array for every dimension, as follows.
positions[0] = [ 0 2 ]
indices[0] = [ 0 2 ]
positions[1] = [ 0 2 4 ]
indices[1] = [ 0 1 0 1 ]
positions[2] = [ 0 2 4 5 7 ]
indices[2] = [ 0 3 0 1 1 2 3 ]
values = [1.000000 2.000000 3.000000 4.000000 5.000000 6.000000 7.000000 ]
Lastly, something as unusual as [ “S”, “D”, “D” ] would need the following set up of the array contents.
positions[0] = [ 0 2 ]
indices[0] = [ 0 2 ]
values = [ 1.000000 0.000000 0.000000 2.000000 3.000000 4.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 5.000000 0.000000 0.000000 0.000000 0.000000
6.000000 7.000000 0.000000 0.000000 0.000000 0.000000 ]
Please let me know if this provides you with sufficient background to implement a set up method for these buffers.