Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Sparse Matrix Multiplication across different sparse formats #315

Open
boyrealmadred opened this issue Sep 23, 2020 · 2 comments

Comments

@boyrealmadred
Copy link

Hi.
I am having an issue to correctly executing the multiplication of two sparse matrices and storing the result in a sparse format. Here is a simple code that I have been using to multiply for that reason. I tried different sparse formats for the three matrices, the only case that produces the correct result is when both dimensions are dense or when both matrices are CSR. In the later case, the results is still stored in a dense format. For all other cases, the program produce wrong results for SpMM. Is multiplication of two sparse matrices and storing it in a sparse format is still not supported yet ? or I am missing doing something wrong ? Thank you.

int main(int argc, char* argv[]) {

/* Sparse Matrix Multiplication */

Format dense ({Dense,Dense});
Format csr({Dense,Sparse});
Format coo({Sparse,Singleton});
Format csc ({Dense,Sparse},{1,0});

int row = 5 ;

//dense version
//Tensor A("A", {row,row}, dense);
//Tensor B("B", {row,row}, dense);
//Tensor C("c", {row,row}, dense);

//csr version
Tensor A("A", {row,row}, csr);
Tensor B("B", {row,row}, csr);
Tensor C("c", {row,row}, csr);

//coo version
//Tensor A("A", {row,row}, coo);
//Tensor B("B", {row,row}, coo);
//Tensor C("c", {row,row}, coo);

//csc version
//Tensor A("A", {row,row}, csc);
//Tensor B("B", {row,row}, csc);
//Tensor C("c", {row,row}, csc);

B(0,0) = 1.0 ;
B(1,0) = 2.0 ;
B(2,0) = 3.0 ; B(2,1) = 4.0 ;
B(3,2) = 5.0 ;

C(0,0) = 1.0 ;
C(1,0) = 2.0 ;
C(2,0) = 3.0 ; C(2,1) = 4.0 ;
C(3,2) = 5.0 ;

B.pack();
C.pack();

IndexVar i, j, k;
//A(i,j) = B(i,k) * C(k,j); //version_1

IndexExpr mul = B(i,k) * C(k,j); //version 2
IndexStmt matmul = (A(i,j) = sum(k,mul));

A.compile();
A.assemble();
A.compute();

write("out1.tns", A);

}

@Infinoid
Copy link
Contributor

Yeah, there is an issue with sparse outputs at the moment.

There is some ongoing work to support workspaces, which will improve the memory handling of sparse outputs. Until then, sparse outputs sometimes generate invalid output. See issues #184, #297.

For now, your program seems to work correctly in all cases, as long as A is dense.

@Infinoid
Copy link
Contributor

Infinoid commented Oct 8, 2020

Thanks for the example program, by the way. I created a test case based on it, see #325.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants