I talked to Brent who maintains the CUDA library Interface modules. Basically, when he did cuSolverDN, cuSolverSP was still in Beta so he didn’t want to add it until it was complete. Though you’re the second person we’ve had wanting to use it, so he’ll look at adding an interface module in the near future.
I’ve updated your example so that it will now compile and link, but the code seg faults during execution. I might need Brent to help me on this one. Though, I’m out of time for the day, but will look again tomorrow. Here’s what I have so far:
Module Cusolver_common
use iso_c_binding
type CusolverSpHandle
type(c_ptr) :: handle
end type
enum, bind(c)
enumerator :: CUSOLVER_STATUS_SUCCESS = 0
enumerator :: CUSOLVER_STATUS_NOT_INITIALIZED = 1
enumerator :: CUSOLVER_STATUS_ALLOC_FAILED = 2
enumerator :: CUSOLVER_STATUS_INVALID_VALUE = 3
enumerator :: CUSOLVER_STATUS_ARCH_MISMATCH = 4
enumerator :: CUSOLVER_STATUS_MAPPING_ERROR = 5
enumerator :: CUSOLVER_STATUS_EXECUTION_FAILED = 6
enumerator :: CUSOLVER_STATUS_INTERNAL_ERROR = 7
enumerator :: CUSOLVER_STATUS_MATRIX_TYPE_NOT_SUPPORTED = 8
enumerator :: CUSOLVER_STATUS_NOT_SUPPORTED = 9
enumerator :: CUSOLVER_STATUS_ZERO_PIVOT = 10
enumerator :: CUSOLVER_STATUS_INVALID_LICENSE = 11
enumerator :: CUSOLVER_STATUS_IRS_PARAMS_NOT_INITIALIZED= 12
enumerator :: CUSOLVER_STATUS_IRS_PARAMS_INVALID = 13
enumerator :: CUSOLVER_STATUS_IRS_PARAMS_INVALID_PREC = 14
enumerator :: CUSOLVER_STATUS_IRS_PARAMS_INVALID_REFINE = 15
enumerator :: CUSOLVER_STATUS_IRS_PARAMS_INVALID_MAXITER= 16
enumerator :: CUSOLVER_STATUS_IRS_INTERNAL_ERROR = 20
enumerator :: CUSOLVER_STATUS_IRS_NOT_SUPPORTED = 21
enumerator :: CUSOLVER_STATUS_IRS_OUT_OF_RANGE = 22
enumerator :: CUSOLVER_STATUS_IRS_NRHS_NOT_SUPPORTED_FOR_REFINE_GMRES=23
enumerator :: CUSOLVER_STATUS_IRS_INFOS_NOT_INITIALIZED = 25
enumerator :: CUSOLVER_STATUS_IRS_INFOS_NOT_DESTROYED = 26
enumerator :: CUSOLVER_STATUS_IRS_MATRIX_SINGULAR = 30
enumerator :: CUSOLVER_STATUS_INVALID_WORKSPACE = 31
end enum
end module Cusolver_common
Module Cusolver_m
Use Cudafor
Use Cusparse
Interface CusolverSpDcsrsv
integer(c_int) function CusolverSpDcsrsv(Handle, N, NNZA, DescrA, CsrValA, CsrRowPtrA, CsrColIndA, B, TOL, &
Reorder, X, Singularity) Bind(C, Name='cusolverSpDcsrlsvluHost')
Use Iso_C_Binding
Use Cusparse
use Cusolver_common
Type(CusolverSpHandle) :: Handle
Integer(C_Int), value :: N, NNZA, Reorder
integer(C_int) :: Singularity
Type(CusparseMatDescr) :: DescrA
Real(C_Double), Device :: CsrValA(NNZA), B(N), X(N)
Integer(C_Int), Device :: CsrRowPtrA(N+1), CsrColIndA(NNZA)
Real(C_Double), value :: TOL
End function
End Interface
Interface CusolverSpCreate
integer(c_int) function CusolverSpCreate(Handle) Bind(C, Name='cusolverSpCreate')
Use Iso_C_Binding
use Cusolver_common
Type(CusolverSpHandle) :: Handle
End function
End Interface
Interface CusolverSpDestroy
integer(c_int) function CusolverSpDestroy(Handle) Bind(C, Name='cusolverSpDestroy')
Use Iso_C_Binding
use Cusolver_common
Type(CusolverSpHandle) :: Handle
End function
End Interface
End Module
Program Sparse_Solver_GPU
Use Cudafor
Use Cusparse
use Cusolver_common
Use Cusolver_m
Implicit None
Type(CusolverSpHandle) :: Handle
Type(CusparseMatDescr) :: DescrA
Integer :: Istat,Reorder,Singularity
Double Precision :: TOL
Integer, Device :: CSR_Row_Index_GPU(5)
Integer, Device :: CSR_Matrix_Column_GPU(9)
Double Precision, Device :: CSR_Matrix_Value_GPU(9)
Double Precision, Device :: Right_Vector_GPU(4)
Double Precision, Device :: Computed_Value_GPU(4)
Integer :: CSR_Row_Index(5)
Integer :: CSR_Matrix_Column(9)
Double Precision :: CSR_Matrix_Value(9)
Double Precision :: Right_Vector(4)
Double Precision :: Computed_Value(4)
Double Precision :: Alpha
Print *,'Start LU Decomposing With Cusolver In GPU Platform'
Alpha=1.0D0
CSR_Row_Index =(/1,4,5,8,10/)
CSR_Matrix_Column=(/1,3,4,2,1,3,4,2,4/)
CSR_Matrix_Value =(/1.0D0,2.0D0,3.0D0,4.0D0,5.0D0,6.0D0,7.0D0,8.0D0,9.0D0/)
Right_Vector =(/19.0D0,8.0D0,51.0D0,52.0D0/)
Computed_Value =0.0D0
CSR_Row_Index_GPU =CSR_Row_Index
CSR_Matrix_Column_GPU=CSR_Matrix_Column
CSR_Matrix_Value_GPU =CSR_Matrix_Value
Right_Vector_GPU =Right_Vector
Computed_Value_GPU =Computed_Value
Istat=CusolverSpCreate(Handle)
If (Istat /= CUSOLVER_STATUS_SUCCESS) Print *, 'CusolverSpCreate Error: ', Istat
Istat=CusparseCreateMatDescr(DescrA)
Istat=CusparseSetMatType(DescrA,CUSPARSE_MATRIX_TYPE_GENERAL)
Istat=CusparseSetMatIndexBase(DescrA,CUSPARSE_INDEX_BASE_ONE)
!.... ==================================================================================================================================
Istat=CusolverSpDcsrsv(Handle, 4, 9, DescrA, CSR_Matrix_Value_GPU, CSR_Row_Index_GPU, CSR_Matrix_Column_GPU, &
Right_Vector_GPU, TOL, Reorder, Computed_Value_GPU, Singularity)
!.... ==================================================================================================================================
Computed_Value=Computed_Value_GPU ! U▒▒GPU▒▒▒▒CPU
Print *,Computed_Value
!.... Destroy and Deallocate
Istat=CusolverSpDestroy(Handle)
Stop
End Program