calling CUDA from fortran

I am trying to see if I can port a Fortran subroutine to CUDA and call it from Fortran itself. Is this possible?

Obviously I will have to allocate the device pointers and execute memcopy(device) and memcopy(host) each time the function is called.

I am using Intel Compiler 11 (ifort) to compile the Fortran code. My approach is to have the Fortran compiled object files linked with CUDA(nvcc) so that I compare the CUDA kernel vs the Fortran subroutine. Any pointers/references?

You could write wrappers for each function. The blas library has good examples,. Alternatively you could try PGI. Same principle as CUDA C , but more complicated. Check here also and this

Thanks for the update.

I downloaded the CUDA-Fortran sample from the Nvidia page

Works well with gfortran, g77 and ifort !!!

Based on the Fortran Cuda example, I wrote a dummy CUDA kernel and I called it using extern “C” inside the Fortran code and added the foll:

$(F77) -o $(OBJS) -llapack -lblas $(CUDAINC) $(CUDALIB) -lcudart

But this gives me the following error:

/usr/bin/ld: cannot find -lcudart

collect2: ld returned 1 exit status

However, my LD_LIBRARY_PATH has /usr/local/cuda/lib64/

I am using gfortran (gcc-4.4.0) and CUDA 4.0 Any suggestions?

You need to pass the location of cudart (-L./usr/local/cuda/lib64).
LD_LIBRARY_PATH is not used by the linker.

Thanks !!!

I was using CUDALIB = /usr/local/cuda/lib64

Now I use

$(F77) -o $(OBJS) -L/usr/local/cuda/lib64/ -lcudart -llapack -lblas

and just see a warning:

/usr/bin/ld: warning:, needed by /usr/lib/…/lib64/, may conflict with

I apologize to be bad mouth, but really using FORTRAN with CUDA is quite tedious. I use FORTRAN for my CPU codes, but I found it easier to use CUDA C for nvidia. I had only a short course in C 12 years ago.