Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OpenMP] Offloading returns incorrect value when compiled from a different file #55943

Open
jhuber6 opened this issue Jun 8, 2022 · 1 comment
Assignees
Labels

Comments

@jhuber6
Copy link
Contributor

jhuber6 commented Jun 8, 2022

The following offloading program returns an incorrect value when run on my V100.

/// impl.c
#pragma omp begin declare target
int x = 1;

int function() {
#pragma omp parallel for
  for (int i = 0; i < 128; ++i) {
    x = 0;
  }
  return 0;
}
#pragma omp end declare target
// kernel.c
int function();

int main() {
  int x = 0;
#pragma omp target map(from : x)
  x = function();
  
  return x;
}

When compiled together we get incorrect results using regular compilation.

3n4:iguazu ~/llvm/llvm-project/build> clang impl.c kernel.c -fopenmp -fopenmp-targets=nvptx64 -O3
3n4:iguazu ~/llvm/llvm-project/build> ./a.out; echo $?
33

However, using LTO or manually linking the static library this seems fine.

3n4:iguazu ~/llvm/llvm-project/build> clang impl.c kernel.c -fopenmp -fopenmp-targets=nvptx64 -O3 -foffload-lto
3n4:iguazu ~/llvm/llvm-project/build> ./a.out; echo $?
0

This is most likely caused by a variable that is not shred correctly in the bitcode version of the runtime. We can try to identify this variable or move forward making LTO default / always using the static library.

@jhuber6 jhuber6 added the openmp label Jun 8, 2022
@jhuber6 jhuber6 self-assigned this Jun 8, 2022
@llvmbot
Copy link
Member

llvmbot commented Jun 8, 2022

@llvm/issue-subscribers-openmp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants