Issue 150092
Summary [flang][openmp] link error when openmp target program uses omp_lib and offloads to NVIDIA
Labels flang
Assignees
Reporter kevinsala
    Consider an OpenMP program, written in Fortran and including the `omp_lib` module, that uses the target construct for GPU offloading:
 
```f90 
program openmp_example                                                          
 use omp_lib 
  implicit none 
 
  !$omp target 
  !$omp end target 
end program openmp_example 
``` 
 
When compiling the program using flang, and offloading to NVIDIA GPU, the linking fails due to multiple undefined symbols in the device side. These symbols correspond to the parameters declared by `omp_lib`:

```sh
$ flang -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda --offload-arch=sm_90 example.f90
nvlink error   : Undefined reference to '_QMomp_lib_kindsECkmp_affinity_mask_kind' in '/var/tmp/example-88455c-nvptx64-nvidia-cuda-sm_90-7e47d6-eed870.cubin'
nvlink error   : Undefined reference to '_QMomp_lib_kindsECkmp_cancel_kind' in '/var/tmp/example-88455c-nvptx64-nvidia-cuda-sm_90-7e47d6-eed870.cubin'
nvlink error   : Undefined reference to '_QMomp_libECkmp_cancel_loop' in '/var/tmp/example-88455c-nvptx64-nvidia-cuda-sm_90-7e47d6-eed870.cubin'
nvlink error   : Undefined reference to '_QMomp_libECkmp_cancel_parallel' in '/var/tmp/example-88455c-nvptx64-nvidia-cuda-sm_90-7e47d6-eed870.cubin'
nvlink error   : Undefined reference to '_QMomp_libECkmp_cancel_sections' in '/var/tmp/example-88455c-nvptx64-nvidia-cuda-sm_90-7e47d6-eed870.cubin'
nvlink error   : Undefined reference to '_QMomp_libECkmp_cancel_taskgroup' in '/var/tmp/example-88455c-nvptx64-nvidia-cuda-sm_90-7e47d6-eed870.cubin'
nvlink error   : Undefined reference to '_QMomp_lib_kindsECkmp_double_kind' in '/var/tmp/example-88455c-nvptx64-nvidia-cuda-sm_90-7e47d6-eed870.cubin'
nvlink error   : Undefined reference to '_QMomp_libECkmp_lock_hint_adaptive' in '/var/tmp/example-88455c-nvptx64-nvidia-cuda-sm_90-7e47d6-eed870.cubin'
[...] 
nvlink error   : Undefined reference to '_QMomp_lib_kindsEComp_sync_hint_kind' in '/var/tmp/example-88455c-nvptx64-nvidia-cuda-sm_90-7e47d6-eed870.cubin'
nvlink error   : Undefined reference to '_QMomp_libEComp_sync_hint_none' in '/var/tmp/example-88455c-nvptx64-nvidia-cuda-sm_90-7e47d6-eed870.cubin'
nvlink error   : Undefined reference to '_QMomp_libEComp_sync_hint_nonspeculative' in '/var/tmp/example-88455c-nvptx64-nvidia-cuda-sm_90-7e47d6-eed870.cubin'
nvlink error   : Undefined reference to '_QMomp_libEComp_sync_hint_speculative' in '/var/tmp/example-88455c-nvptx64-nvidia-cuda-sm_90-7e47d6-eed870.cubin'
nvlink error   : Undefined reference to '_QMomp_libEComp_sync_hint_uncontended' in '/var/tmp/example-88455c-nvptx64-nvidia-cuda-sm_90-7e47d6-eed870.cubin'
nvlink error   : Undefined reference to '_QMomp_libEComp_thread_mem_alloc' in '/var/tmp/example-88455c-nvptx64-nvidia-cuda-sm_90-7e47d6-eed870.cubin'
nvlink error   : Undefined reference to '_QMomp_libECopenmp_version' in '/var/tmp/example-88455c-nvptx64-nvidia-cuda-sm_90-7e47d6-eed870.cubin'
/home/inst/bin/clang-nvlink-wrapper: error: 'nvlink' failed                     
clang: error: nvlink command failed with exit code 1 (use -v to see invocation) 
/home/inst/bin/clang-linker-wrapper: error: 'clang' failed 
flang-21: error: linker command failed with exit code 1 (use -v to see invocation)
``` 
 
If I save the temporary files with `-save-temps`, these symbols start appearing in `example-openmp-nvptx64-nvidia-cuda-sm_90-fir.mlir`:
 
``` 
%131 = fir.address_of(@_QMomp_libEComp_control_tool_end) : !fir.ref<i32>        
 %132:2 = hlfir.declare %131 {fortran_attrs = #fir.var_attrs<parameter>, uniq_name = "_QMomp_libEComp_control_tool_end"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
 
[...] 
 
fir.global @_QMomp_libEComp_control_tool_end constant : i32                     
``` 
 
Apparently, in AMD systems, these symbols are also present in that same intermediate file, but the linking error does not occur.

The environment is the following:
- Intel(R) Xeon(R) Platinum 8480+
- NVIDIA H100
- CUDA 11.8.0
- LLVM bc2cc8b56e2444339ffa58e83a457d15ae18241d
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to