Enzyme crash when using OpenMP: PHI nodes not grouped at top of basic block!
- Dominant language
- LLVM
- Stars
- 1.7k
- Forks
- 188
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 26
Description
Consider this program `lse.cpp`:
```C++
#include
#include
#include
extern int enzyme_dup;
extern int enzyme_dupnoneed;
extern int enzyme_out;
extern int enzyme_const;
void __enzyme_autodiff(...) noexcept;
void primal(size_t n, const double* x, double* out) {
std::vector As(omp_get_max_threads());
#pragma omp parallel
{
double priv_A = x[0];
#pragma omp for
for (size_t i = 1; i < n; i++) {
priv_A = std::max(priv_A, x[i]);
}
As[omp_get_thread_num()] = priv_A;
}
double A = 0;
for (int i = 0; i < omp_get_max_threads(); i++) {
A = std::max(A, As[i]);
}
std::vector Ss(omp_get_max_threads());
#pragma omp parallel
{
double priv_s = 0;
#pragma omp for
for (size_t i = 0; i < n; i++) {
priv_s += exp(x[i] - A);
}
Ss[omp_get_thread_num()] = priv_s;
}
double s = 0;
for (int i = 0; i < omp_get_max_threads(); i++) {
s += Ss[i];
}
*out = log(s) + A;
}
int main() {
size_t n = 10;
double input[10];
double output[10];
double dummy, unit = 1;
__enzyme_autodiff(primal,
enzyme_const, n,
enzyme_dup, input, output,
enzyme_dupnoneed, &dummy, &unit);
}
```
I compile it as follows:
```
$ clang++ lse.cpp -fopenmp -fuse-ld=lld -flto -Wl,--load-pass-plugin=$ENZYME_LIB/LLDEnzyme-19.so
```
Which produces a rather verbose error of which I show only the first few lines below:
```
PHI nodes not grouped at top of basic block!
%77 = phi double [ %38, %48 ], [ %71, %73 ]
label %74
...
```
I am using `clang++` 19.1.7 and Enzyme 0.0.176, but the error also occurs with Enzyme 0.0.179.
Contributor guide
Assessment
This issue has not been assessed yet.