Hello,
I’m having difficulties using cublas in a Fortran/OpenACC code to solve a system of linear equations via LU factorization.
Here is the code:
program lu_cublas
use cublas_v2
use openacc
use iso_c_binding
implicit none
integer(c_int), parameter :: n=2, batchSize=1, lda=n, ldb=n, nrhs=batchSize
real(kind=8) :: A(n,n,batchSize), B(n,batchSize)
type(cublasHandle) :: handle
integer(c_int) :: i, k, istat, iInfo
integer(c_int) :: Pvt(n,batchSize), Info(batchSize)
type(c_devptr) :: devptrA(batchSize), devptrB(batchSize)
A = reshape((/6,3,4,3/), [n,n,batchSize])
B = reshape((/10,6/), [n,batchSize])
print "(/,'Input:')"
do k = 1, batchSize
print "(2x,'Matrix: ')"
do i=1, n
print *, A(i,:,k)
enddo
enddo
!$acc enter data copyin(A,B) create(Pvt,Info)
!$acc host_data use_device(A,B)
do k = 1, batchSize
devptrA(k) = c_devloc(A(1,1,k))
devptrB(k) = c_devloc(B(1,k))
end do
!$acc end host_data
!$acc enter data copyin (devptrA, devptrB)
istat = cublasCreate(handle)
if (istat /= CUBLAS_STATUS_SUCCESS) &
write(*,*) 'cublasCreate failed'
istat = cublasSetStream(handle, acc_get_cuda_stream(acc_async_sync))
if (istat /= CUBLAS_STATUS_SUCCESS) &
write(*,*) 'cublasSetStream failed'
!$acc host_data use_device(Pvt, Info, devptrA, devptrB)
istat= cublasDgetrfBatched(handle, n, devptrA, lda, Pvt, Info, batchSize)
if (istat /= CUBLAS_STATUS_SUCCESS) &
write(*,*) 'cublasDgetrfBatched failed: ', istat
istat = cublasDgetrsBatched(handle, CUBLAS_OP_N, n, lda, devptrA, nrhs, Pvt, devptrB, ldb, iInfo, batchSize)
if (istat /= CUBLAS_STATUS_SUCCESS) then
write(*,*) 'cublasDgetrsBatched failed: ', istat
write(*,*) 'The faulty parameter is : ', abs(iInfo)
end if
!$acc end host_data
!$acc exit data copyout(A,B,Pvt) delete(devptrA, devptrB)
istat = cublasDestroy(handle)
if (istat /= CUBLAS_STATUS_SUCCESS) &
write(*,*) 'cublasDestroy failed'
print "(/, 'LU Factorization:')"
do k = 1, batchSize
print "(2x,'Matrix: ')"
do i = 1, n
print *, A(i,:,k)
enddo
print "(2x,'Pivot: ')"
print *, Pvt(:,k)
print "(2x,'X: ')"
print *, B(:,k)
enddo
end program lu_cublas
The call to cublasDgetrfBatched executes successfully, while the execution of cublasDgetrsBatched fails with error code 7 and the value of info parameter -5.
I’m using SDK 26.3 and cuda 12.8.0.
Here are the compilation options:
nvfortran -O0 -g -Minform=warn -Mdetail -acc=gpu,verystrict -gpu=cc70 -cudalib=cublas lu_cublas.f90
Thank you in advance for your help.