Cusparse for solving the sparse linear equation Ax=b

Question:
I’d like to solve the sparse linear equation Ax=b (A is stored in ‘CSR’) by using the cuSparse library.
The official document is not detailed.I’d like to know how to achieve this (STEP BY STEP) in detail.For example,the functions and the use-order of functions.
And I see the official document …, it can only get the solution of a sparse triangular linear system ? How about the SPD(Symmetric positive definite) matrixs(not triangular matrixs)
Here I post my test code…The answer is not as expected ,I’m looking forward for some help…,thanks!

.......      
      istat=cusparseCreate(h)
      istat=cusparseCreateMatDescr(descr)
      istat=cusparseSetMatType(descr,CUSPARSE_MATRIX_TYPE_GENERAL)
      istat=cusparseSetMatIndexBase(descr,CUSPARSE_INDEX_BASE_ONE)
      istat=cusparseCreateSolveAnalysisInfo(info)
      ....
      istat=cusparseXcoo2csr(h,cooRowPtr_d,nnz,m,csrRowPtr_d,             &
       CUSPARSE_INDEX_BASE_ONE)
      istat=cusparseCcsrsv_analysis(h,cusparse_operation_non_transpose, &
      m,nnz,descr,csrVal_d,csrRowPtr_d,csrColInd_d,info)
!      istat=cusparseCcsrilu0(h,cusparse_operation_non_transpose,m,descr,&
!      csrVal_d,csrRowPtr_d,csrColInd_d,info)
      istat=cusparseCcsrsv_solve(h,cusparse_operation_non_transpose,m,  &
      alpha,descr,csrVal_d,csrRowPtr_d,csrColInd_d,info,x,y)
      istat=cusparseDestroy(h)
      istat=cusparseDestroyMatDescr(descr)
      istat=cusparseDestroySolveAnalysisInfo(info)

Hi M_yeah,

Have you looked at using the cuSolver library instead? https://docs.nvidia.com/cuda/cusolver/index.html#cusolver-intro

-Mat

emmmm, I use '‘fortran’ , does it have cuSolver library? I can’t find
the cuSolver library API in this website…
https://www.pgroup.com/resources/docs/19.4/x86/cuda-fortran-prog-guide/index.htm#cfpg-fort-mods-access-data

Yes, you can call cuSolver routines from CUDA Fortran.

We do provide a interface module for most of the DN routines (cusolverdn.mod). For the SP and RF routines, you may need to write an interface, but it’s fairly straight forward to do.

Do you have a particular routine in mind?

Maybe i need a simple example to show me exactly how to do …
Be grateful with your help~~

I’ve not used suSolver myself so wont be much help on using it. But there’s this post over on NVIDIA’s devtalk forum: https://devtalk.nvidia.com/default/topic/882492/gpu-accelerated-libraries/using-cusolverdn-in-fortran-code/
and this from Stackoverflow: https://stackoverflow.com/questions/44829771/proper-use-of-cudafortran-cusolver-functions

I can help with the interfaces if needed. Here’s an example from one of the interfaces in our cuSolverDN module:

module cusolverDn

use cusolver_common

TYPE cusolverDnHandle
  TYPE(C_PTR) :: handle
END TYPE

! cusolverDnDpotrs
interface
  integer(4) function cusolverDnDpotrs(handle, uplo, n, nrhs, A, lda, B, ldb, devinfo) bind(C, name='cusolverDnDpotrs')
    import cusolverDnHandle
    type(cusolverDnHandle), value :: handle
    integer(4), value :: uplo
    integer(4), value :: n, nrhs, lda, ldb
    real(8), device, dimension(lda,*) :: A
    real(8), device, dimension(ldb,*) :: B
    integer(4), device, intent(out) :: devinfo
  end function
end interface
....

-Mat

Is there a performance gain from using sparse cuSolver versus cuSparse’s solvers?

  • Ron

It’s my understanding that cuSolver uses cuSparse underneat for its cusolverSP API, so I would think that the performance difference between them shouldn’t be too great. If you later need support for dense matrices, you won’t need to include an additional library if you use cuSolver.