tensor-compiler / taco

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

Reshape functionality #144

Open qnzhou opened 6 years ago

qnzhou commented 6 years ago

Hi there,

I am new to taco, but it has been amazingly easy to use so far. I am wondering if there is support for Kronecker product of matrices. e.g.

image

While the following is possible:

C(i,j,k,l) = A(i,j) * B(k,l)

But the output needs to be a matrix instead of a 4th order tensor because it will be fed into a sparse solver. Is there any way of reshaping or flattening a tensor?

fredrikbk commented 6 years ago

Hi @qnzhou! I'm thrilled you're finding taco easy to use!

This is a cool problem that's come up in different variants in QCD and in optimizing expressions. You need to combine coordinates in some tensor dimension indexings, something like C(i x j, k x l) = A(i,j) * B(k,l). Building this into the code generator is in our roadmap, but tricky and will take some time.

An alternative solution we can have for you much quicker, is to provide a reshape routine. This has a performance cost since we have to move data, but perhaps that is acceptable. The first implementation could perhaps be implemented in C++ as follows:

  1. Turn C into coordinates
  2. Combine coordinates
  3. Pack coordinates into C_matrix

Would this work for you? That is, what are your performance requirements?

qnzhou commented 6 years ago

Thanks Fredrik! The reshape approach works. I am not too worried about the performance at the moment.

fredrikbk commented 6 years ago

Great, we'll figure out how to get it done as well as a timeline on our side then. We have meetings today so we should know more by tomorrow.

ofmla commented 6 years ago

@qnzhou I'm experiencing the same problem with a Sparse matrix-vector multiplication with the matrix in BCSR format (4th order tensor). The output is a matrix instead of a vector. Is there a possibility of sharing your piece of code to perform this task? so I can just look it up and modify and put into my code. Thanks

qnzhou commented 6 years ago

I don't have any code to perform this task that works with taco, but I think it is on the todo list of the development team.

fredrikbk commented 6 years ago

Hi, I've been working on a new lowering framework that will include coordinate combining, so it's definitely on our list.

The eta for this is August. @ofmla do you need the BCSR multiplication to go directly to a vector, or is a temporary data copy step acceptable to you?

ofmla commented 6 years ago

The result mapped into a vector would be ideal but I can work on a matrix. Could I do a copy to a vector after just by using a loop and playing with indices right?

Kraks commented 1 week ago

Hi, it has been a while since the opening of this issue. I wonder what is the status of supporting kronecker product or the reshape routine in taco? Thanks!