CUDA Fortran: how to use CUDA Fortran in Fortran90 projects

Hi,

I am currently improving one large Fortran90 project using CUDA Fortran. The problem is that I want to redesign some modules using CUDA Fortran, but the new modules which are compiled by the pgf90 cannot be used in original fortran90 codes directly.
It seems like that gfortran can only use its own module files.

This may be a common problem, I think. Is there any good approach to solve this?

Thanks~
chengxuntao@gmail.com

Hi Chinacxt,

F90 modules are not compatible across Fortran compilers. You will need to compile your entire Fortran project using PGI or redesign your project so that mixing modules in not necessary.

  • Mat

HI, mkcolg

Thanks for your reply.
Is it possible to compile the .cuf into .o and then linke this .o together with other f90 .o files? This method works in ‘Calling CUDA C in Fortran’. I am trying this but many error messages show up during linking.

Hi Chinacxt,

If you compile all your F90 files with PGI, then yes CUDA Fortran and F90 objects are compatible. However, F90 features such as allocatable arrays and modules are not compatible across compiler vendors so you would not be able to compile the F90 objects with gfortran or ifort.

However what you can do is write an interface layer that does not use these F90 features (basically F77) and can act as a bridge between the two objects. Granted, it’s easier to just compile with PGI, but if you’re looking to write a library that can be used with any compiler, then this is what you’d need to do.

This method works in ‘Calling CUDA C in Fortran’. I am trying this but many error messages show up during linking.

I’m not clear on the question. What are you trying to do and what error messages are you getting?

  • Mat

Thank you.
I’ve decided to compile all codes using pgfortran. But a new problem shows up.
A lot of this kind of error messages show up when I am using pgfortran to compile some .f90 codes. Some subroutines cannot reference to others due to the “underscore” appended, I think.

"m_common_struct.F90:(.data+0x12c): undefined reference to `fox_utils_'
m_common_struct.F90:(.data+0x154): undefined reference to `fox_m_utils_mtprng_'
m_common_struct.F90:(.data+0x15c): undefined reference to `fox_m_utils_uuid_'
m_common_struct.F90:(.data+0x164): undefined reference to `fox_m_fsys_array_str_'
m_common_struct.F90:(.data+0x184): undefined reference to `fox_m_utils_uri_'
"

Pgfrotran appends underscores to all global names when compiling, right? Since I use it to compile all codes, there should be no dis-match about underscores. So, I don’t understand why this happens.
Would you please explain to me the ‘underscore’ mechanism?

Pgfrotran appends underscores to all global names when compiling, right? Would you please explain to me the ‘underscore’ mechanism?

Correct, we add an underscore at the end of symbol names in order to help with C name space conflicts. Other Fortran compilers will also add one or two underscores.

Since I use it to compile all codes, there should be no dis-match about underscores. So, I don’t understand why this happens.

It could be that they are C symbols and hence don’t get the underscore already added, or that the object that contains the definitions for these symbols wasn’t added to the link.

You need to determine the source where these symbols are defined, how this source is compiled, and then how the symbols are being decorated (i.e. ‘nm foo.o | grep fsys_array_str’), and if the object is being added to the link.

  • Mat

Thanks very much for your comprehensive advice.
I found out that I miss some linking options. I have now fixed it and it runs well now.
Thanks very much~