CUDA Fortran programs - for beginners

We have searched a lot in the web but simple step by step guide on how to compile and run a simple fortran-cuda program is not present.
Apart from the Portland Group (PGI) manual nothing is found. :pirate:

We would greatly appreciate if some one can provide details on

(1) What compiler to download and install for CUDA Fortran
(2) Example CUDA Fortran program(s)
(3) how to compile them
(4) how to run them.

With Regards

You’ll need to use PGI compiler, as this is the only compiler available supporting CUDA Fortran; you can find it for download here, and after creating an account at PGI site you should be able to generate 15-day trial license (PGI compiler is not freely available, moreover it’s a bit on the pricey side - see here, but still IMO it is well worth its money).

After installing the compiler, you should be able to find two sample programs under the installation tree; only one is “real” code (SGEMM routine), but it should be enough for you to get a feeling on CUDA Fortran programming. You build the code in command line, practically just like you build your C CUDA code with nvcc, but only you’re using PGI compiler instead of nvcc. There exist several compiler switches that are CUDA related, but you could learn about these from the compiler user guide (also available in the installation tree), and everything else that you’d need to get started with CUDA Fortran you could learn from CUDA Fortran user guide, that is available here (the guide is rather short and readable, but knowledge of C CUDA is assumed). Finally, you run the compiled program just like any other executable on your machine: you type in the executable name in the command line, and that’s it.

On a side note: my own overall impression so far is that CUDA Fortran is very nice in case one programmed in Fortran before - CUDA runtime functions integrated within native Fortran syntax, so host code is much nicer than in C, and also writing device functions seems as natural as writing any other kind of Fortran code.

If you have access to a modern Fortran compiler - one that supports Fortran2003 - then there is a module “iso_c_binding” to help do what you want to do, maybe. Search the web for examples of its use.


Thank you very much ‘sagrailo’ :woot:

We will start the CUDA-Fortran adventure with your valuable inputs