[Fortran][C++] Question on cross-language function inlinement

Hi, after a discussion in the fortran-lang discourse group regarding function inlinement on GPUs I tried to see wether it would be possible to inline a C++ function within a Fortran program that will be executed on the GPU. In that link I show how I took the saxpy example and modified it to call a cpp implementation and compare the execution times.

I found that the execution was indeed much slower compared to the pure fortran implementation, but, as mentioned also there, when I read in the nvidia HPC manuals regarding inlinement I see no explicit limitation to exploit inlinement for a cross-language application. Is it possible to do? and if so, would it be possible to give some hints on how to manage doing so?

Thank you in advance.

This is because the C code isn’t getting vectorized due to the potential aliasing. Either add the “restrict” keyword or the flag “-Msafeptr” to assert to the compiler that there is no aliasing.

Is it possible to do?

Cross language calling is certainly fine, but cross-language inlining isn’t something we support.


Hi @MatColgrove , thanks for the clear answer!!

Out of curiosity I added the flag -Msafeptr but got the following error:

nvfortran-Error-Unknown switch: -Msafeptr

I’m using the following version: nvfortran 23.1-0 64-bit target on x86-64 Linux -tp skylake-avx512

nvfortran-Error-Unknown switch: -Msafeptr

Sorry, I should have been more clear. This is a C/C++ flag, so please add it to the compilation of the C++ file.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.