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] Device declarations are not used when applied to extern variables #63355

Closed
jhuber6 opened this issue Jun 16, 2023 · 2 comments
Closed
Assignees
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" openmp

Comments

@jhuber6
Copy link
Contributor

jhuber6 commented Jun 16, 2023

OpenMP uses the #pragma omp declare target directive to control which variables are present on the device. Currently this cannot be used to mark any variable on the device unless it is applied to the first time that variable is seen. This can be seen in this godbolt example https://godbolt.org/z/aT9171xn6. In the first case, because the #pragma omp declare target to(x) clause is applied to an extern declaration of the variable x, OpenMP does not place it on the device. This can be seen due to the visibility begin extern and x being passed in as an argument to the GPU. However, if we instead apply it to the extern variable before the actual declaration, it will work fine.

This is currently preventing us from providing adequately wrapped headers when implementing system utilities on the GPU. I.e. we cannot do the following so there is no way to indicate that stderr is on the GPU without including everything from the host's stdio.h on the GPU as well.

#include_next<stdio.h>

extern FILE *stderr;
#pragma omp declare target to(stderr)
@jhuber6 jhuber6 added clang Clang issues not falling into any other category openmp labels Jun 16, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Jun 16, 2023

@llvm/issue-subscribers-openmp

@jhuber6 jhuber6 assigned jhuber6 and unassigned alexey-bataev Jun 23, 2023
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed clang Clang issues not falling into any other category labels Jun 27, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Jun 27, 2023

@llvm/issue-subscribers-clang-frontend

Chenyang-L pushed a commit to intel/llvm that referenced this issue Jul 11, 2023
This patch changes the handling of OpenMP to add the device attributes
to the canonical definitions when we encounter a non-canonical
definition. Previously, the following code would not work because it
would find the non-canonical definition first which would then not be
used anywhere else.

```
int x;
extern int x;
```

This patch now adds the attribute to both of them. This allows us to
perform the following operation if, for example, there were an
implementation of `stderr` on the device.

```
#include <stdio.h>

// List of libc symbols supported on the device.
extern FILE *stderr;
```

Unfortunately I cannot think of an equivalent solution to HIP / CUDA
device declarations as those are done with simple attributes. Attributes
themselves cannot be used to affect a definition once its canonical
definition has already been seen. Some help on that front would be
appreciated.

Fixes llvm/llvm-project#63355

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D153369
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" openmp
Projects
None yet
Development

No branches or pull requests

4 participants