tensor-compiler / taco

The Tensor Algebra Compiler (taco) computes sparse tensor expressions on CPUs and GPUs
http://tensor-compiler.org
Other
1.25k stars 188 forks source link

How to convert tensor formats #516

Open LeiWang1999 opened 2 years ago

LeiWang1999 commented 2 years ago

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?

rohany commented 2 years ago

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.