Fortran codes in CUDA

Hey Guys

I'm new here. And i have some doubts how i must proceed to make my fortran codes run with CUDA. I make codes in fortran90 and reading the manual i don't see any keyword or something like to use when i'm compiling the program.

Let us assume that is a code:

program test
implicit none

! Declaring variables

integer :: var1
real :: var 2
doubleprecision :: var3
character :: var4

! The code

assume this is a program

end program

save as test.f90, what must i do to convert my program to CUDA. Exist any keyword, or some library that must i add to the source. I’m completely newbie with this, i try to make some programs run with CUDA and none works. Thanks for all help.

PS: sorry for my english, isn’t good enough, iḿ a brazilian user.

I develop F90+CUDA programs, and here’s what I do…

In your F90 code, I’ll assume somewhere you have a function line like

[font=“Lucida Console”]call launchgpustuff(arguments)[/font]

Then in a *.cu file, you’ll put the declaration of that function with the appropriate name-mangling convention. For example, if using gfortran on linux, I’d define (note the underscore after the function name)

[font=“Lucida Console”]global void launchgpustuff_(arguments)
{
.
.
.
kernelfunction<<dimGrid,dimBlock>>(more arguments);
.
.
.
}[/font]

To compile this code, you first compile the fortran code using [font=“Lucida Console”]gfortran -c[/font], then compile the CUDA code using [font=“Lucida Console”]nvcc -c[/font]. Finally, link it all together using gfortran: [font=“Lucida Console”]gfortran -lstdc++ -L/usr/local/cuda/lib/ -lcudart *.o -o executable_name[/font]

This is what has worked for me. Unfortunately, I am unable to use the visual profiler. I think it may be a CUDA+F90 problem. So I’d be interested to know if you can get that to work for you.

Fortran is not supported by CUDA now. You can only write CUDA code in C/C++. However, you can write the CPU code in Fortran, and write GPU code in C/C++, then link them together using the technique described by faircdl.

I am using CUDA+90 the same way you are doing and the visual profiler works pretty well for me.

I’m curious about your setup. I have a RHEL 5.3 box with a GTX 295 and 2 Teslas. I’ve tried CUDA 2.1 and 2.2b to no avail. I’m not doing any fancy multi-GPU stuff for now. All I can see when I run the profiler are the memcopy operations. Any thoughts?

I have Cuda 2.0 and RHEL 5.1 installed with C1060 GPUs. Actually, I can see all the kernel calls but memcopies doesn’t appear in the profiler. May be there is a problem when profiling operations that may overlap. I dont think it is a fortran+Cuda issue.

Well, for some reason unknown to me, the profiler is working now. I’ll just keep my fingers crossed that everything remains happy. Thanks for your reply.

Thanks for all the help. But, I use programs who are code, completely in fortran, including the functions, which makes the use of C/C++ functions impossible. What I’m trying to do is running a fortran source natively in my GPU, but, this appears to be impossible. I thought about converting the hole program to C/C++, but I Know too little about C/C++ to do this, and the program isn’t mine, i just had access to the source, but the new modifications and all new things implemented in the program i don’t know how it works. But, thanks a lot, I’ll study C!

You should look into Flagon (just google it). It’s a fortran wrapper for most of CUDA. You could also look into the latest beta of Portland Group’s fortran compiler. It attempts to use some OpenMP-like flags to auto-parallelize parts of your code for the GPU.

The Flagon looks nice. I’ll think about it. Thanks again