<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/122260>122260</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
OpenMP offloaded code crashes at compilation/runtime depending on optimization flags
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
JakobSchaeffeler
</td>
</tr>
</table>
<pre>
I'm trying to compile the stencil3d-omp benchmark of HeCBench: [https://github.com/zjin-lcf/HeCBench/blob/master/src/stencil3d-omp/main.cpp](https://github.com/zjin-lcf/HeCBench/blob/master/src/stencil3d-omp/main.cpp)
I'm using LLVM version 19.1.3 on a MI100 AMD GPU.
If I compile the code with -O3 everything works and the results match with the ones from SYCL and HIP:
`make CC=clang++ CFLAGS="-fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx908"`
If I compile the code without any optimization flags the compilation is successful, however at runtime i get the following error:
`AMDGPU fatal error 1: Memory access fault by GPU 8 (agent 0x55f222c19fb0) at virtual address 0x7f8c9c06a000. Reasons: Page not present or supervisor privilege
Aborted (core dumped)
`
Lastly, if I compile the code with O0, O1 or O2 I get a Segfault at compilation: [O0_compilation_output.txt](https://github.com/user-attachments/files/18361060/O0_compilation_output.txt)
The only difference I was able to find between the O0 and O3 version is that the O0 version launches the OpenMP kernels in generic mode and the O3 in generic-SPMD mode. Could this be the reason for the crash?
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0VEGT2jgT_TXi0gUly2DwwQcPlBO-Ggrqm83W7iklyy1bGVlySTIM-fVbMpCdbCWb0x7AoH7drX79nrn3qjWIBVk9kdVuxsfQWVf8j7_a-kV0HKVEjW5W2-Za7Alb9xDcVZkWggVh-0FphNAh-IBGKJ02c9sPUKMRXc_dK1gJH3H7FP-TtASyeupCGDxJS8IqwqpWhW6sF8L2hFVfvygz10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