Author: Austen C. Duffy, Florida State University
Cuda functions can be called directly from fortran programs by using a kernel wrapper as long as some simple rules are followed.
1. Data Types: Make sure you use equivalent data types, these basically follow from fortran --> C conventions. Make sure to specify fortran integers and reals, note that integer*2 is a short int in C, I have had alot of problems trying to use these so I would suggest using integer*4's instead.
integer*4 --> int
real*4 --> float
real*8 --> double
2. Function Names: Fortran functions are appended with _ so you need to account for this in your cuda function call, e.g. calling function 'kernel_wrapper( )' in fortran will be changed to 'kernel_wrapper_( )' in the pre-processing stage, and so your cuda function should be called 'kernel_wrapper_( )' instead. This does not apply to the cuda kernels since they will not be called in the fortran code.
3. Arrays: Fortran and C use a different storage structure, essentially the opposite of each other, i.e. Fortran array(i,j,k) is equivalent to C array[k][j][i], except the Fortran arrays are stored in linear memory and so will be passed as 1-D arrays to CUDA.
Fortran array A(i,j,k) -> CUDA array A((k-1)*NX*NY+(j-1)*NY+i)