Integration of nvfotran inside a CMake


I am trying to introduce nvfortran as a compiler for my project.
I would like to set the flags following this model:

set (CMAKE_Fortran_FLAGS “-shared-intel -mcmodel=large -fpp -fimf-arch-consistency=true -fpe0 -init=zero -init=arrays -fp-model strict -nogen-interfaces”)
set (CMAKE_Fortran_FLAGS_RELEASE “-O1”)
set (CMAKE_Fortran_FLAGS_DEBUG “-O0 -g -traceback -Mdclchk -Ktrap=fp”)
set (Fortran_EXTRA_FLAGS “-Mbounds”)
endif ()

I would like to know with which command-lines I should replaces the ones that are present in the code above.


I’ll do my best, but I’m not too familiar with the Intel flags and in some cases there’s no direct mapping.

-shared-intel: Use of shared object is set via “-Bdynamic” but is the default, so this can be removed. Though to link statically against the nvhpc compiler runtime use “-static-nvidia”

-mcmodel=large: Same

-fpp: -Mpreprocess

-fimf-arch-consistency=true: No direct mapping for this, but by default we don’t relax precision unless the “-Mfprelaxed” is used.

-fpe0: -Ktrap=fp

-init=zero -init=arrays: Here’s our versions of these

-Minit-integer=<n>  Initialize local integer*4 and integer*8 variables and arrays to <n>
-Minit-local-zero   Initialize local {integer, real, logical} variables and arrays to 0
    true            initialize to .true.
    false           initialize to .false.
-Minit-msg          Issue a compiler message via -Minfo for initialized variables and arrays

The caveats being that they are fairly new, only available for local variables, and array initialization is only available for static arrays, not allocatables or automatics.

-fp-model strict: -Kieee

-nogen-interfaces: Default, we don’t generate implicit interfaces so you can remove this option.

Other items:

I’d recommend putting “-Mbounds” under the DEBUG flags.

Also several of these flags will deoptimize the code so what is gained in precision, will lose performance. By default, we’re generally more strict on precision (1 ULP) than Intel, so the flags that force strict floating point accuracy aren’t needed. Hence I’d recommend not using these flags unless your code is numerically sensitive.

For the RELEASE flags, you’ll generally want a higher level of optimization such as “-O3” or “-fast”.

Thanks for your response.

Following what you have said I have written the code portion this way:

set (CMAKE_Fortran_FLAGS “-static-nvidia -mcmodel=medium -Ktrap=fp -Kieee -Minit-integer= -Minit-local-zero -Minit-logical=true -Minit-real=zero”)
set (CMAKE_Fortran_FLAGS_RELEASE “-fast”)
set (CMAKE_Fortran_FLAGS_DEBUG “-O0 -g -traceback -Mdclchk -Ktrap=fp -Mbounds”)**
set (Fortran_EXTRA_FLAGS “-Mbounds”)
endif ()

With this version I have the following errors during the compilation:

/bin/sh: n: No such file or directory
nvfortran-Error-Unknown switch: -Minit-local-zero nvfortran-Error-Unknown switch: -Minit-logical=true
nvfortran-Error-Unknown switch: -Minit-real=zero`

I think that the first error is linked to the flag: -Minit-integer=

In your response you talked about the flags that force strict floating point accuracy, and I don’t know if the flags that lead to the compilation errors are concerned.

If I remove those flags I encounter no errors during the compulation.

These flags were added in our 22.5 release. Earlier versions would give this error.

Though, the flags are likely not needed so removing them should be fine.

I removed the flags and now I have the following error when I execute my project:

version `OACC_2.0' not found

It’s strange because I don’t have any OpenACC directives in my project.

I’m not familiar with what “OACC_2.0” is, but doing a web search it appears to be the GNU libgomp library.

Is your Cmake project testing for this library? If so, then you’ll want to remove this test given it’s not a library we use.

If by testing you mean that the GNU libgomp library is mentioned in the Cmake file then no it’s not testing.

Ok, then unfortunately I don’t know. Best as I can tell it may have something to do with a libgomp dependency, but exactly what, you’ll need to investigate.