Hi,
I’m getting segmentation fault from calling “cublasDgetrfBatched” and “cublasDgetriBatched”. Then I wrote a small code to repeat this error. Would you please take a look?
Thanks.
– Jing
----------------------------------- code start from here ------------------------------
module LU
interface cuda_getrf
subroutine cuda_dgetrf(n, Aarray, lda, ipvt, info, batchCount) bind(C,name=‘cublasDgetrfBatched’)
use cudafor
use iso_c_binding
integer, value :: n
type(c_devptr), device :: Aarray()
integer, value :: lda
integer, device :: ipvt()
integer, device :: info()
integer, value :: batchCount
end subroutine cuda_dgetrf
end interface
interface cuda_getri
subroutine cuda_dgetri(n, Aarray, lda, ipvt, Carray, ldc, info, batchCount) bind(C,name=‘cublasDgetriBatched’)
use cudafor
use iso_c_binding
integer, value:: n
type(c_devptr), device :: Aarray()
integer, value :: lda
integer, device :: ipvt()
type(c_devptr), device :: Carray()
integer, value :: ldc
integer, device :: info(*)
integer, value :: batchCount
end subroutine cuda_dgetri
end interface
end module LU
PROGRAM solvelinear
use cudafor
use LU
implicit none
REAL(8), dimension(3,3) :: A,Ainv,M,LU
INTEGER,dimension(3) :: ipiv
INTEGER :: i
integer, parameter :: batchCount=1, ndim=3
integer, device :: ipiv_d(ndim)
integer, device :: info1_d(batchCount), info2_d(batchCount)
real(8), device :: t_d(ndim,ndim)
real(8), device :: ti_d(ndim,ndim)
type(c_devptr) :: devPtrA(batchCount), devPtrC(batchCount)
type(c_devptr), device :: devPtrA_d(batchCount), devPtrC_d(batchCount)
INTEGER istat, status
A = reshape((/1,-1,3,3,1,1,1,1,1,1/),(/3,3/))
t_d(1:ndim,1:ndim) = A
ti_d(1:ndim,1:ndim) = 0.
devPtrA(batchCount) = c_devloc(t_d(1,1))
devPtrC(batchCount) = c_devloc(ti_d(1,1))
devPtrA_d = devPtrA
devPtrC_d = devPtrC
call cuda_dgetrf(ndim,devPtrA_d,ndim,ipiv_d,info1_d,batchCount)
call cuda_dgetri(ndim,devPtrA_d,ndim,ipiv_d,devPtrC_d,ndim,info2_d,batchCount)
Ainv(1:ndim,1:ndim)=ti_d(1:ndim,1:ndim)
!-- computation of A^-1 * A to check the inverse
M = matmul(Ainv,A)
do i=1,3
print*,M(i,:)
end do
END PROGRAM solvelinear
!.. CORRECT OUTPUT
!.. 1. 0. 0.
!.. 0. 1. 0.
!.. 0. 0. 1.
------------------------------ code end here -------------------------