Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenMP dependency not found with Nvidia HPC SDK #8058

Open
nordmoen opened this issue Dec 3, 2020 · 11 comments
Open

OpenMP dependency not found with Nvidia HPC SDK #8058

nordmoen opened this issue Dec 3, 2020 · 11 comments

Comments

@nordmoen
Copy link

nordmoen commented Dec 3, 2020

Describe the bug
When using openmp = dependency('openmp') with Nvidia HPC SDK and Meson 0.56.0 OpenMP is not detected.

To Reproduce
Have openmp = dependency('openmp') and run CC=nvc meson setup builddir

Expected behavior
Expected OpenMP to be detected since it is supported by Nvidia HPC SDK according to their documentation.

I expect the issue to be that Nvidia (previously PGI) still does not define _OPENMP. In the code there is a special handling of pgi and that should probably be extended to nvidia_hpc. As per the link above the new Nvidia HPC SDK compilers should support version 4.5 (except for the offloading capabilities).

system parameters

  • Meson 0.56.0
  • Nvidia HPC SDK 20.7 and 20.9
@dcbaker
Copy link
Member

dcbaker commented Jan 7, 2021

@scivision I think you're the only one with access to the Nvidia compilers.

@nordmoen
Copy link
Author

nordmoen commented Jan 7, 2021

The Nvidia HPC SDK should be accessible to everyone as long as you accept Nvidia's EULA.

@scivision
Copy link
Member

I don't have the Nvidia compiler anymore

@dcbaker
Copy link
Member

dcbaker commented Jan 8, 2021

I think then we're at "patches welcome". I'd be happy to review something though.

@nordmoen
Copy link
Author

It seems like my initial assessment was wrong, the Nvidia HPC SDK does indeed support the _OPENMP macro, however, meson was unable to detect this due to incompatible flags used with nvc when preprocessing to detect _OPENMP. One solution is to add nvc flags to PGICompiler or create a new Nvidia HPC SDK mixin with the required flags.

The following preprocessor flags (the order is important) will result in nvc handling the _OPENMP macro and printing the expected result.

def get_preprocess_only_args(self) -> T.List[str]:
    return ['-Mcpp', '-E']

@nordmoen
Copy link
Author

@dcbaker Could you or anyone else comment on the above proposed changes?

@dcbaker
Copy link
Member

dcbaker commented Jan 25, 2021

Does that still work with the PGI compiler, if it does just flipping it makes sense, otherwise some kind of inheritance based override make sense.

@nordmoen
Copy link
Author

Does that still work with the PGI compiler, if it does just flipping it makes sense, otherwise some kind of inheritance based override make sense.

Yes, I tested with both PGI/19.9 and PGI/20.4 and they both output the expected OpenMP support when compiled with pgcc -Mcpp -E -mp (note that using pgcc -E -Mcpp -mp results in no output at all)

@nordmoen
Copy link
Author

One challenge I find when testing a custom get_preprocess_only_args is that the command used to compile is not strictly nvc -Mcpp -E ..., but rather nvc -Mcpp -E -Mcpp ... which seems to be down to how compilers.py:compile() is building the command. Before compile() is called the extra_args parameter is built up to contain the flags we are after (in the correct order), but on line compilers.py:757 the command is extended with the arguments for the desired mode (preprocessor in our case) before the extra_args list is added. The result being that the preprocessor flags are attempted added twice to the command. If I comment out line compilers.py:757 the compile works as expected (however, I don't know what else this may lead to down the road).

Could anyone advice on what is the correct course so that the flags appear in the correct order?

@e-kwsm
Copy link
Contributor

e-kwsm commented Jan 19, 2022

Let’s consider https://github.com/dftd4/dftd4, which requires OpenMP, as an example.

Meson fails to detect OpenMP with nvc and nvfortran:

$ CC=nvc FC=nvfortran meson setup --default-library static NVIDIA

Fortran compiler for the host machine: nvfortran (nvidia_hpc 22.1-0)
Fortran linker for the host machine: nvfortran pgi 22.1-0
Host machine cpu family: x86_64
Host machine cpu: x86_64
C compiler for the host machine: nvc (nvidia_hpc 22.1-0)
C linker for the host machine: nvc pgi 22.1-0
Run-time dependency OpenMP found: NO (tried system)

config/meson.build:42:2: ERROR: Dependency "openmp" not found, tried system

Then what happens if pgcc and pgfortran are used instead, which are symlinks to nvc/nvfortran? Meson works as expected:

$ CC=pgcc FC=pgfortran meson setup --default-library static PGI

Fortran compiler for the host machine: pgfortran (pgi 22.1-0)
Fortran linker for the host machine: pgfortran pgi 22.1-0
Host machine cpu family: x86_64
Host machine cpu: x86_64
C compiler for the host machine: pgcc (pgi 22.1-0)
C linker for the host machine: pgcc pgi 22.1-0
Run-time dependency OpenMP found: YES 3.1

So a workaround is to use old PGI names, but pgi staffs should be replaced with nvidia_hpcas @nordmoen pointed out.


  • nvc 22.1-0
  • meson 0.61.1

@RudiFeiman
Copy link

I met a similar problem.
Describe the bug
I'm trying buid a c++ project with nvidia HPC compiler with openmp . This project compiled with meson.
When I using default compiler (gcc c++) with openmp, it's OK.
But nvidia hpc compiler is failed.

To Reproduce
meson.build file:

project('nvidiaHPCtest', 'cpp')
ompdep = dependency('openmp')
executable('demo', 'main.cpp', dependencies : ompdep)

main.cpp file:

#include <iostream>
#include <omp.h>

int main(int argc, char **argv) {

#if defined(_OPENMP)
  std::cout << "openmp is defined\n";
#endif

  #pragma omp parallel
  {
    std::cout << _OPENMP <<"Hello there.\n";
  }
  
  return 0;
}

Expected behavior
gcc meson compile command:

1. meson setup builddir  
2. cd builddir
3. ninja

nvidia hpc compile command:
1. CC=/mnt/f/work/nvhpc/Linux_x86_64/23.5/compilers/bin/nvc CXX=/mnt/f/work/nvhpc/Linux_x86_64/23.5/compilers/bin/nvc++ meson setup builddir

It will failed with ERROR: Dependency “openmp” not found, tried system.

note: my nvidia hpc compiler installed in /mnt/f/work/nvhpc/Linux_x86_64/23.5/compilers/bin

system parameters

  • This is a Windows wsl2 Ubuntu subsystem compile
  • Ubuntu 22.04
  • Python 3.10.6
  • meson 0.61.2
  • ninja 1.10.1

I have also post this issue on nvidia forums for some comments with nvidia hpc compiler.
https://forums.developer.nvidia.com/t/nvhpc-22-2-error-use-of-undefined-value-l-lb26-8163/205286/19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants