Skip to content

[OpenMP] Compilation error at O0 for OpenMP GPU offloading with NVIDIA GPU and LLVM 20 #132654

Open
@ouankou

Description

@ouankou

Given the following OpenMP C code, at O0 there is a compilation error. O1-3 works fine. The issue occurs in LLVM 20 but not the main branch (LLVM 21).

#include <stdio.h>

void foo() {
  int sum = 10000;
#pragma omp target teams distribute parallel for map(tofrom: sum) num_teams(256) num_threads(1024) reduction(+ : sum)
  for (int i = 1; i <= 100; i++)
    sum += i;

  printf("sum = %d\n", sum);
}

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

  foo();

  return 0;
}
$ clang -v
clang version 20.1.2 (https://github.com/llvm/llvm-project 3f957cc67cff4e337f56fa2dbfdb037d3a997baf)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/ouankou/Projects/llvm-20/llvm_install/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12
Candidate multilib: .;@m64
Selected multilib: .;@m64
Found CUDA installation: /opt/nvidia/hpc_sdk/Linux_x86_64/24.3/cuda/12.3, version 12.3

$ clang -fopenmp -fopenmp-targets=nvptx64 -O0 test.c
nvlink error   : Undefined reference to 'IsSPMDMode' in '/tmp/a.out.nvptx64.sm_86-a57cc1-8872c3.cubin'
nvlink error   : Undefined reference to '_ZN4ompx5state9TeamStateE' in '/tmp/a.out.nvptx64.sm_86-a57cc1-8872c3.cubin'
nvlink error   : Undefined reference to '_ZN4ompx5state12ThreadStatesE' in '/tmp/a.out.nvptx64.sm_86-a57cc1-8872c3.cubin'
/home/ouankou/Projects/llvm-20/llvm_install/bin/clang-nvlink-wrapper: error: 'nvlink' failed
clang: error: nvlink command failed with exit code 1 (use -v to see invocation)
/home/ouankou/Projects/llvm-20/llvm_install/bin/clang-linker-wrapper: error: 'clang' failed
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The setup is LLVM 20 built from source, NVIDIA HPC SDK 24.3 (CUDA 12.3), NVIDIA RTX A3000 Laptop GPU (sm86). The full error log is attached. Please let me know if any other information is needed. Thanks!

error.log

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions