llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.92k stars 11.52k forks source link

Incorrect linking of device code #41740

Open ye-luo opened 5 years ago

ye-luo commented 5 years ago
Bugzilla Link 42395
Version unspecified
OS Linux
CC @alexey-bataev,@jdoerfert

Extended Description

I got the following error at runtime.

Target CUDA RTL --> Load data from image 0x00000000006ce450 Target CUDA RTL --> CUDA module successfully loaded! Target CUDA RTL --> Loading '__omp_offloading_805_19e264f__ZN11qmcplusplus17einspline_spo_ompIdE10evaluate_vERKNS_11ParticleSetEi_l218' (Failed) Libomptarget --> Unable to generate entries table for device id 0. Libomptarget --> Failed to init globals on device 0 Libomptarget --> Failed to get device 0 ready

The issue is related to static linking. Target offload regions are compiled and archived as static libraries. Then *.a are then linked together to create an executable. Such an executable ran well in the past but no more. If I link manually all the object files. The executable can run correctly.

The build and run recipe https://github.com/QMCPACK/miniqmc/tree/OMP_offload mkdir build_clang_offload; cd build_clang_offload cmake -DCMAKE_CXX_COMPILER="clang++" -DQMC_MPI=0 -DENABLE_OFFLOAD=1 .. make -j24 miniqmc ./bin/miniqmc

alexey-bataev commented 5 years ago

This case used to work even static linking is not supported. Since it is no more working and there are other static linking issues. llvm/llvm-project#38051 I can only use Clang on kernels. Even a miniapp doesn't work.

This critical limitation significantly impact the usability of OpenMP offload in clang. Hopefully the community is aware of it and prioritize a solution. My previous bug report is almost one year old. Many thanks.

I have nothing to add. I understand that many users need this feature. We did not forget about this feature, we actively work trying to support it. But this is not easy and may need some time to provide a reliable and universal solution. The main problem here is to design the feature so that it could work for as many platforms as possible. It requires some specific design in the compiler and many people from different companies work on this feature trying to provide a solution that works for all of them.

ye-luo commented 5 years ago

This case used to work even static linking is not supported. Since it is no more working and there are other static linking issues. llvm/llvm-project#38051 I can only use Clang on kernels. Even a miniapp doesn't work.

This critical limitation significantly impact the usability of OpenMP offload in clang. Hopefully the community is aware of it and prioritize a solution. My previous bug report is almost one year old. Many thanks.

alexey-bataev commented 5 years ago

Linking against libraries with the device code is not supported yet.