How to transpose a sparse matrix in cuSparse?

会有一股神秘感。 提交于 2021-02-11 14:49:08

问题


I am trying to compute A^TA using cuSparse. A is a large but sparse matrix. The proper function to use based on the documentation is cusparseDcsrgemm2. However, this is one of the few cuSparse operations that doesn't support an optional built-in transpose for the input matrix. There's a line in the documentation that said

Only the NN version is supported. For other modes, the user has to transpose A or B explicitly.

The problem is I couldn't find a function in cuSparse that can perform a transpose. I know I can transpose in CPU and copy it to the GPU but that will slow down the application. Am I missing something? What is the right way to use cuSparse to compute A^TA?


回答1:


For matrices that are in CSR (or CSC) format:

The CSR sparse representation of a matrix has identical format/memory layout as the CSC sparse representation of its transpose.

Therefore, if we use the cusparse provided function to convert a CSR format matrix into a CSC format, that resultant CSC-format matrix is actually the same as the CSR representation of the transpose of the original matrix. Therefore this CSR-to-CSC conversion routine could be used to find the transpose of a CSR format sparse matrix. (It can similarly be used to find the transpose of a CSC format sparse matrix.)



来源:https://stackoverflow.com/questions/57368010/how-to-transpose-a-sparse-matrix-in-cusparse

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!