I’m trying to call cuBlas from a Fortran program, but somehow the codes does not compile.
The error message is:
PGF90-S-0084-Illegal use of symbol cublasdcopy - attempt to use a SUBROUTINE as a FUNCTION (main.f90: 14)
What is wrong with this code?
Thank you for your help
The code is:
PROGRAM test
use cublas
implicit none
integer n,i,ierr
type(cublasHandle) :: h
real*8,device,allocatable :: x(:)
real*8,device,allocatable :: y(:)
real*8,device,allocatable :: z(:)
n=10e6
allocate(x(n))
allocate(y(n))
allocate(z(n))
h = cublasGetHandle()
ierr = cublasDcopy(h,10,x,1,y,1)
end PROGRAM test
cuBlas changed their interfaces a bit ago. When you use “cublas”, you’re using the v1 interface where “cublasdcopy” is a subroutine that does not include a handle as the first argument. Though if you use “cublasdcopy_v2” instead, then you’re using the v2 interface where it’s a function with a handle. Alternatively, you can use “cublas_v2” instead of “cublas”, in which case “cublasdcopy” will be using the v2 interface.
I have another question regarding mixing cublas and OpenACC.
Do I have to call cudaDeviceSynchronize() after I called a cublas function if
I have OpenACC kernels after the cuBLAS call? Do cuBLAS and OpenACC both use the same stream?
Mat, this isn’t necessarily true. For absolute safeness, you can run cublas and your openacc kernels on the same stream. If you use an openacc async number of 5, for instance, you can do this:
ierr = cublasSetStream(h, acc_get_cuda_stream(5))
If you use the default stream everywhere, you will be fine. Or add cudaDeviceSynchronize as you said.