taco icon indicating copy to clipboard operation
taco copied to clipboard

Reshape functionality

Open qnzhou opened this issue 8 years ago • 8 comments

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?

qnzhou avatar Mar 19 '18 16:03 qnzhou

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?

fredrikbk avatar Mar 20 '18 14:03 fredrikbk

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

qnzhou avatar Mar 20 '18 16:03 qnzhou

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.

fredrikbk avatar Mar 20 '18 17:03 fredrikbk

@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

ofmla avatar Jul 05 '18 18:07 ofmla

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.

qnzhou avatar Jul 05 '18 18:07 qnzhou

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?

fredrikbk avatar Jul 06 '18 07:07 fredrikbk

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?

ofmla avatar Jul 06 '18 12:07 ofmla

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!

Kraks avatar Nov 21 '24 13:11 Kraks