vkirangoud / cusp-library

Automatically exported from code.google.com/p/cusp-library
Apache License 2.0
0 stars 0 forks source link

Multiple calls to 'multiply' from a fortran program loading the matrix just once #85

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hello guys,

I'm currently using the multiply operation implemented in CUSP (to perform a 
spMV) from a fortran routine that needs to call it many times and I don't want 
to transfer the matrix from the CPU to the GPU every time. This is my situation:
I have a fortran code that needs to perform a matrix vector product. In order 
to do it, it calls a c++ code that currently creates the matrix in CSR format 
(allocate memory in the host and in the device), creates the vectors in the 
device and call the multiply function  

//Call spMV Cusp solver
    cusp::multiply(D,xd,yd);

This is currently giving the expected results.

My problem is that every time the fortran code calls this c++ function, the 
matrix is being created and transferred to the GPU. The fortran code may call 
this routine thousands of times and hence for large matrices, the transfer 
takes too long (and it is not necessary because the matrix never changes). It 
would be great to transfer the matrix only the first time to the device. 
However it seems that I would need to pass the pointer given by 

cusp::coo_matrix<int,float,cusp::device_memory> D = A;

to my fortran code. What kind of pointer this would be? How can I do this? Is 
there other way to do it?

Any suggestion would be very valuable.

Thank you

Carlos

Original issue reported on code.google.com by fade...@gmail.com on 17 Feb 2012 at 5:38

GoogleCodeExporter commented 9 years ago
Hi Carlos,

You can use array and matrix "views" [1] to avoid the copy.  Just create a 
plain function that accepts the device pointers and wrap them up in a 
csr_matrix_view to perform the multiply.  Something like

  void my_multiply(int num_rows, int num_cols, int num_nonzeros,
                   int * row_offsets, int * column_indices, double * values,
                   double * x, double * y)
  {
    // construct csr_matrix_view and call cusp::multiply
  }

BTW, we generally prefer people to ask questions on the cusp-users mailing list 
[2] since more people read that than this issue tracker.

[1] http://code.google.com/p/cusp-library/source/browse/#hg%2Fexamples%2FViews
[2] http://groups.google.com/group/cusp-users

Original comment by wnbell on 18 Feb 2012 at 6:01