taco icon indicating copy to clipboard operation
taco copied to clipboard

How to convert tensor formats

Open LeiWang1999 opened this issue 2 years ago • 1 comments

I‘m new to taco, any existing methods to convert tensor formats ?

Suppose that I have a tensor W with the shape (256, 512) and 60% sparsity. To define a dense-dense martix in taco, I think the code should be something like :

Format denseFormat({Dense, Dense});
Tensor<double> W("W", {256, 512}, denseFormat);

Then use utils to fill the matrix with 60% sparsity, There's going to be 60% zeros in this matrix, and I look forward to use some other specified formats, like BCSR to store this martix, any methods can do that? for example, is there something like :

Format bcsr({Dense,Sparse,Dense,Dense});
W_bcsr = W.convertFormat(bcsr)

Because to manually create a bcsr format tensor which represents the 60% sparsity tensor W is Incomprehensible, I need to create a tensor with code like (with bcsr block size (16,1)):

Format bcsr({Dense,Sparse,Dense, Dense});
Tensor<double> W("W", {1,4916,16,1}, denseFormat);

or maybe I have some improper understanding about taco?

LeiWang1999 avatar Mar 24 '22 06:03 LeiWang1999

Conversions between formats are expressed in TACO by assignments between tensors of the desired source and destination formats. Unfortunately, there aren't utilities right now in TACO to directly express the tiling that you want when converting a dense -> BCSR, so you would have to explicitly iterate over the values in WDense and insert each value into WBCSR and then call pack.

rohany avatar Mar 28 '22 17:03 rohany