[clang] [HIP] Define `_OPENMP` on the device for mixed OpenMP CPU compilations (PR #176791)
Joseph Huber via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 25 11:32:45 PST 2026
jhuber6 wrote:
> Could you please provide a minimal reproducer to explain the issue. Based on the limited description, it sounds like user tries to compile codes with hip source code with OpenMP threading and the hip part was reactive to `__OPENMP__`. It is complicated to ask hip mode supporting full OpenMP logics (not just predefined macro but also API header files, directives). CUDA / HIP offloading should not supports OpenMP at all.
>
> My recommendation will be asking users to spin off the hip code as separate functions in cpp file without openmp, the old cpp file then doesn't need to be compiled in hip mode.
The test file is the reproducer:
```
#include <omp.h>
const char ompver_str[] = {'I', 'N', 'F', 'O', ':', 'O', 'p', 'e', 'n', 'M', 'P', '-',
'd', 'a', 't', 'e', '[',
('0' + ((_OPENMP / 100000) % 10)),
('0' + ((_OPENMP / 10000) % 10)),
('0' + ((_OPENMP / 1000) % 10)),
('0' + ((_OPENMP / 100) % 10)),
('0' + ((_OPENMP / 10) % 10)),
('0' + ((_OPENMP / 1) % 10)),
']', '\0'};
int main(void) {
return 0;
}
```
This is what CMake uses to test OpenMP. As you can see there are no checks for whether or not it's defined because it assumes if you pass `-fopenmp` it will be defines (As per the standard.) We could probably work around this as the user with `-Xarch_device -D_OPENMP=0` or something.
https://github.com/llvm/llvm-project/pull/176791
More information about the cfe-commits
mailing list