1
$\begingroup$

I try to use sparse matrix operations in GPU in Python and now try to use PyCUDA with theano. But I can't find how to do sparse matrix and vector multiplication. I only got an example showing how to solve $A\cdot x=b$ using CG from the library document. Is there any document or example detailing how to do some basic sparse matrix operations?

By the way, is there another python library that can do sparse matrix operations in GPU?

$\endgroup$

2 Answers 2

2
$\begingroup$

I think the most used libraries for sparse matrix operations using CUDA is cuSPARSE, which already comes included in the CUDA toolkit and supports all common sparse matrix formats. There is a Python wrapper for it here.

Overall, the Python/CUDA ecosystem still seems weirdly fractured, with no obvious choice existing for many common tasks. That said, most of my Python/CUDA experience comes from writing custom kernels using PyCUDA, which worked well.

$\endgroup$
1
$\begingroup$

This example from the PyCUDA demonstrates how to do sparse matrix vector multiplication.

$\endgroup$
3
  • $\begingroup$ Isn't this an example for solving a sparse linear system with CG? I don't see any explicit matrix-vector products. $\endgroup$
    – cfh
    May 23, 2015 at 14:46
  • 1
    $\begingroup$ Yes, but CG is built on (sparse) matrix-vector multiplication. The relevant lines are 30-31, where the sparse matvec operator spmv is defined for a matrix $A$ given in scipy.sparse.crs format. If you look at the cg source (line 123), you see that $b=Ax$ is then computed via b=spmv(x). $\endgroup$ May 23, 2015 at 15:17
  • $\begingroup$ It would be good to put that into the answer since it's definitely not easy to spot in the code (and in fact spmv is never explicitly invoked in that source file, only passed to CG). $\endgroup$
    – cfh
    May 23, 2015 at 22:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.