<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - OpenMP Cuda Offloading Failure with LLVM 12.0.0 (<eof> parser at end of file error)"
   href="https://bugs.llvm.org/show_bug.cgi?id=50692">50692</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>OpenMP Cuda Offloading Failure with LLVM 12.0.0 (<eof> parser at end of file error)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>OpenMP
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Clang Compiler Support
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>asher.mancinelli@pnnl.gov
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>With Tesla V100-SXM3 cards and the following source file:

<span class="quote">> // example.c
> #include <stdio.h></span >
>
<span class="quote">> #define MAX 32768</span >
>
<span class="quote">> int main()
> {
>   int x[MAX], i;
>   for (i = 0; i < MAX; ++i) {
>     x[i] = 42;
>   }</span >
>
<span class="quote">>   #pragma omp target teams distribute parallel for simd map(tofrom: x[0:MAX])
>   for (i = 0; i < MAX; ++i) {
>     x[i] = x[i] + 1;
>   }
>   printf("After the target region is executed, x[0] = %d\n", x[0]);
>   return 0;
> }</span >

compiled with the following:
<span class="quote">> clang --cuda-path=/... \
>   -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda \
>   -Xopenmp-target -march=sm_70 -o example example.c</span >

Yields the following:
<span class="quote">> Program aborted due to an unhandled Error:
> Invalid record (Producer: LLVM13.0.0git Reader: LLVM 12.0.0)
> PLEASE submit a bug report to <a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash backtrace, preprocessed source, and associated run script.
> Stack dump:
> 0.Program arguments: /qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12 -cc1 -triple nvptx64-nvidia-cuda -aux-triple x86_64-unknown-linux-gnu -S -disable-free -main-file-name example.c -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -fno-rounding-math -fno-verbose-asm -no-integrated-as -mlink-builtin-bitcode /share/apps/cuda/10.1.243/nvvm/libdevice/libdevice.10.bc -target-feature +ptx64 -target-sdk-version=10.1 -mlink-builtin-bitcode /qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/lib/libomptarget-nvptx-cuda_101-sm_70.bc -target-cpu sm_70 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/lib/clang/12.0.0 -internal-isystem /qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/lib/clang/12.0.0/include/openmp_wrappers -include __clang_openmp_device_functions.h -internal-isystem /usr/local/include -internal-isystem /qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/lib/clang/12.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -internal-isystem /usr/local/include -internal-isystem /qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/lib/clang/12.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fno-dwarf-directory-asm -fdebug-compilation-dir /people/manc568/workspace/build-llvm-gcc8-tonga-scratch -ferror-limit 19 -fopenmp -fopenmp-cuda-parallel-target-regions -fgnuc-version=4.2.1 -fcolor-diagnostics -fopenmp-is-device -fopenmp-host-ir-file-path /tmp/example-1faaa0.bc -o /tmp/example-6d6124.s -x c example.c
> 1.<eof> parser at end of file
>  #0 0x0000000001c1a643 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x1c1a643)
>  #1 0x0000000001c1844e llvm::sys::RunSignalHandlers() (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x1c1844e)
>  #2 0x0000000001c1ab0f SignalHandler(int) (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x1c1ab0f)
>  #3 0x00002aefd9df2630 __restore_rt (/usr/lib64/libpthread.so.0+0xf630)
>  #4 0x00002aefdaf4a387 raise (/usr/lib64/libc.so.6+0x36387)
>  #5 0x00002aefdaf4ba78 abort (/usr/lib64/libc.so.6+0x37a78)
>  #6 0x0000000001ba0ef0 llvm::Error::fatalUncheckedError() const (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x1ba0ef0)
>  #7 0x0000000002c2b8d0 llvm::Expected<llvm::Constant*>::fatalUncheckedExpected() const (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x2c2b8d0)
>  #8 0x0000000002c2ac8d (anonymous namespace)::IRLinker::materialize(llvm::Value*, bool) (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x2c2ac8d)
>  #9 0x0000000001d66c5d (anonymous namespace)::Mapper::mapValue(llvm::Value const*) (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x1d66c5d)
> #10 0x0000000001d67ca2 (anonymous namespace)::Mapper::remapInstruction(llvm::Instruction*) (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x1d67ca2)
> #11 0x0000000001d684c1 (anonymous namespace)::Mapper::remapFunction(llvm::Function&) (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x1d684c1)
> #12 0x0000000001d6618b (anonymous namespace)::FlushingMapper::~FlushingMapper() (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x1d6618b)
> #13 0x0000000001d66b10 llvm::ValueMapper::mapValue(llvm::Value const&) (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x1d66b10)
> #14 0x0000000002c25e37 (anonymous namespace)::IRLinker::run() (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x2c25e37)
> #15 0x0000000002c241f2 llvm::IRMover::move(std::unique_ptr<llvm::Module, std::default_delete<llvm::Module> >, llvm::ArrayRef<llvm::GlobalValue*>, std::function<void (llvm::GlobalValue&, std::function<void (llvm::GlobalValue&)>)>, bool) (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x2c241f2)
> #18 0x0000000002a79ede clang::BackendConsumer::LinkInModules() (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x2a79ede)
> #19 0x0000000002a78f82 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x2a78f82)
> #20 0x0000000003533184 clang::ParseAST(clang::Sema&, bool, bool) (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x3533184)
> #21 0x0000000002471c30 clang::FrontendAction::Execute() (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x2471c30)
> #22 0x00000000023f34ea clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x23f34ea)
> #23 0x0000000002527bb4 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x2527bb4)
> #24 0x000000000096c827 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x96c827)
> #25 0x000000000096a3a2 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x96a3a2)
> #26 0x000000000096a0bd main (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x96a0bd)
> #27 0x00002aefdaf36555 __libc_start_main (/usr/lib64/libc.so.6+0x22555)
> #28 0x000000000096704d _start (/qfs/projects/ops/rh7_gpu/llvm/12.0.0-cuda10.1.243/bin/clang-12+0x96704d)
> clang-12: error: unable to execute command: Aborted (core dumped)
> clang-12: error: clang frontend command failed due to signal (use -v to see invocation)
> clang version 12.0.0 (<a href="mailto:git@github.com">git@github.com</a>:llvm/llvm-project.git d28af7c654d8db0b68c175db5ce212d74fb5e9bc)
> Target: x86_64-unknown-linux-gnu
> Thread model: posix
> InstalledDir: /share/apps/llvm/12.0.0-cuda10.1.243/bin
> clang-12: note: diagnostic msg: Error generating preprocessed source(s).
> make: *** [all] Error 25</span >

Is this a user error? These examples are from [NERSC documentation on OMP
offloading](<a href="https://docs-dev.nersc.gov/cgpu/examples/">https://docs-dev.nersc.gov/cgpu/examples/</a>), and anything that used
the omp `target` pragma resulted in the same error.

I built LLVM git tag llvmorg-12.0.0 with the following options:

<span class="quote">> CC=clang CXX=clang++ \
>   cmake \
>   -GNinja \
>   -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;libcxx;libunwind;libcxxabi;lld;openmp;compiler-rt" \
>   -DLLVM_TARGETS_TO_BUILD="X86;NVPTX" \
>   -DCLANG_OPENMP_NVPTX_DEFAULT_ARCH=sm_70 \
>   -DLIBOMPTARGET_NVPTX_COMPUTE_CAPABILITIES=37,60,70 \
>   -DCMAKE_BUILD_TYPE=Release \
>   -DLLVM_ENABLE_ASSERTIONS=ON \
>   -DFLANG_BUILD_NEW_DRIVER=ON \
>   -DCMAKE_INSTALL_PREFIX=$final_install \
>   -DCMAKE_CXX_FLAGS='--gcc-toolchain=/share/apps/gcc/9.1.0' \
>   -DLIBCXX_CXX_ABI=libcxxabi \
>   -DLIBCXX_USE_COMPILER_RT=On \
>   -DLIBCXXABI_USE_LLVM_UNWINDER=On \
>   -DLIBCXXABI_USE_COMPILER_RT=On \
>   -DLIBUNWIND_USE_COMPILER_RT=On \
>   -DCLANG_DEFAULT_CXX_STDLIB=libc++ \
>   -DCLANG_DEFAULT_RTLIB=compiler-rt \
>   -DCLANG_DEFAULT_LINKER=lld \
>   $srcdir/llvm</span >

I built llvmorg-12.0.0 with this clang:
<span class="quote">> $ clang --version
> clang version 13.0.0 (<a href="mailto:git@github.com">git@github.com</a>:llvm/llvm-project.git 7714b405a0de47e461c77fa8dbd2c21f0d34bbf2)
> Target: x86_64-unknown-linux-gnu
> Thread model: posix
> InstalledDir: /...</span >

and GCC 9.1.0 and CUDA 10.1.243.

Resulting clang install:
<span class="quote">> $ clang --version
> clang version 12.0.0 (<a href="mailto:git@github.com">git@github.com</a>:llvm/llvm-project.git d28af7c654d8db0b68c175db5ce212d74fb5e9bc)
> Target: x86_64-unknown-linux-gnu
> Thread model: posix
> InstalledDir: /...</span ></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>