nvlink reported undefined reference when building OpenMP offloading program

Hi,

I was trying to build an OpenMP offloading program. nvlink always reported following error:

nvlink error : Undefined reference to ‘_Z25GetLogicalThreadIdInBlockb’ in ‘/tmp/main-02fcf5.cubin’
nvlink error : Undefined reference to ‘_Z13checkSPMDModeP5ident’ in ‘/tmp/main-02fcf5.cubin’
nvlink error : Undefined reference to ‘_Z14GetOmpThreadIdib’ in ‘/tmp/main-02fcf5.cubin’
nvlink error : Undefined reference to ‘_Z22setExecutionParameters13ExecutionMode11RuntimeMode’ in ‘/tmp/main-02fcf5.cubin’
nvlink error : Undefined reference to ‘_Z18GetThreadIdInBlockv’ in ‘/tmp/main-02fcf5.cubin’
nvlink error : Undefined reference to ‘_Z24GetNumberOfWorkersInTeamv’ in ‘/tmp/main-02fcf5.cubin’
nvlink error : Undefined reference to ‘_Z16IncParallelLevelbj’ in ‘/tmp/main-02fcf5.cubin’
nvlink error : Undefined reference to ‘_Z16DecParallelLevelbj’ in '/tmp/main-02fcf5.cubin’

I was using clang which was built with trunk via following CMake command:

cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=“X86;NVPTX” -DLLVM_ENABLE_PROJECTS=“clang;openmp” -DCLANG_OPENMP_NVPTX_DEFAULT_ARCH=sm_75 -DLIBOMPTARGET_NVPTX_COMPUTE_CAPABILITIES=75 -DCMAKE_INSTALL_PREFIX=$HOME/.local …/llvm
make -j $(nproc)

OpenMP library was built via following CMake command:

cmake -DCMAKE_C_COMPILER=$HOME/.local/bin/clang -DCMAKE_CXX_COMPILER=$HOME/.local/bin/clang++ -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$HOME/.local -DLIBOMPTARGET_NVPTX_COMPUTE_CAPABILITIES=75 …
make -j $(nproc)

And finally the compilation command is:

clang -fopenmp -fopenmp-targets=nvptx64 main.c

Did I miss something? The program is very simple:

int main() {
int i = 0;

#pragma omp target nowait
{
i++;
int k = 0;
++k;
}

int j = 0;
#pragma omp target nowait
{
++j;
}

return 0;
}

I have CUDA 10.1 on the system.

Regards,
Shilei

You can set like “clang;openmp” to build them at once.

I think Jon (CCed) is aware and working on it:
  https://reviews.llvm.org/rG764c8420e4b8fc11a9fa94d00f4ee617aa754cb2