0

I installed clang-11 from https://apt.llvm.org/ on Ubuntu 18.04 and I have OpenMP host device functionality working in my C++ test project, but omp_get_num_devices() returns 0, even though I have Nvidia GPU and working CUDA 11 toolkit. Do I have to build a special version of Clang from source in order to get OpenMP GPU offload working, as described here: https://hpc-wiki.info/hpc/Building_LLVM/Clang_with_OpenMP_Offloading_to_NVIDIA_GPUs ?

Paul Jurczak
  • 7,008
  • 3
  • 47
  • 72

2 Answers2

2

Yes, I believe you have to build your own version from the source. I wrote a simple script to build Clang/LLVM with GPU offloading support. Please check: https://gist.github.com/ouankou/27c1fc22aee9125190492ea126125249

The script takes three arguments: location, LLVM version, the CUDA compute capability number. For example, to build Clang/LLVM 11 on NVIDIA Tesla V100 (Volta):

./install_llvm.sh $HOME/llvm11 11 70

You may also add the variable settings at the end of script to .bashrc if necessary.

ouankou
  • 21
  • 5
  • I arrived to the same conclusion after a bit of searching. I will try to build it and report the results. My patch to documentation didn't go through, though. It would help to add a note *Clang has to be built from source to enable offloading support for given GPU* to https://releases.llvm.org/11.0.0/tools/clang/docs/OpenMPSupport.html – Paul Jurczak Nov 11 '20 at 13:25
1

The Debian/Ubuntue packages for LLVM do not come with OpenMP offload support for GPUs [0] (at least until LLVM 11) . Packaging this is a bit tricky but we are working on it. One of the tricky parts, for now, is that for reasonable performance it requires a two stage build and you need(ed) to specify what GPU architectures you are targeting. The latter requirement is partially gone in LLVM now as we look at the build machine configuration and make a reasonable guess but was still there in the LLVM 11 release (IIRC). We are working on eliminating the two stage requirement as well, among other things.

While pretty new and mostly empty, these things will eventually be described here: http://openmp.llvm.org/docs

Also, if you have questions or concerns, don't hesitate to send an email to openmp-dev@lists.llvm.org :)

Lastly, at first glance the script by @ouankou looks pretty good, except that I usually recommend the latest top-of-trunk over a release. It can be unstable but, TBH, for OpenMP offload support it is probably not any less stable than a release.

[0] CMake excerpt: https://paste.debian.net/1171752/ (thanks Sylvestre!)

  • Thank you for detailed response. The first problem with OpenMP offload, both in LLVM and GCC, is lack of clear statement in documentation about the need to build a custom version to enable this feature. I tried a pull request to LLVM documentation with a short note (*Clang has to be built from source to enable offloading support for given GPU*), but doing it through a simple edit on Github was automatically rejected. – Paul Jurczak Nov 11 '20 at 23:36
  • 1
    LLVM does not yet do pull requests.Patches need to go to the commits list or to https://reviews.llvm.org . Some more information is available here https://llvm.org/docs/Contributing.html#how-to-submit-a-patch . I did update the FAQ under http://openmp.llvm.org/docs/SupportAndFAQ.html to include a brief statement. I encourage you to submit patches to improve the documentation wherever you see fit! – Johannes Doerfert Nov 25 '20 at 18:14