CUDA with Fortran


I am new to using CUDA, and was wondering if it is possible to call c++ function which uses cuda from a fortran program? I am working to improve an already created fortran source code and don’t want to have to pay for the PGI CUDA compiler. Thanks!

Thanks everyone, I actually found a paper that was pretty helpful.

Yes, it’s possible. The method to call a C++ function from Fortran is not CUDA - specific. Once you call your C++ wrapper function, then you can run your CUDA activity from that wrapper function.

As txbob says, this interoperability question is orthogonal to the use of CUDA. It may be easier to call a function with C bindings rather than C++ bindings, so likely better to declare such functions as extern "C" in the CUDA code. On the Fortran side, check whether your compiler supports ISO_C_BINDING introduced with Fortran 2003, otherwise check the compiler documentation for a description of the vendor-specific way to invoke C functions.