<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 is not defined when compiling for CUDA"
   href="https://llvm.org/bugs/show_bug.cgi?id=31239">31239</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>_OPENMP is not defined when compiling for CUDA
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>CUDA
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>crtrott@sandia.gov
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This occurs in a similar situation as reported in <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED FIXED - -fopenmp does not define _OPENMP macro"
   href="show_bug.cgi?id=23492">bug 23492</a>.
Basically when compiling with CUDA support the _OPENMP macro is only set in the
host compilation phase but not when __CUDA_ARCH__ is defined. 

This leads to incomplete type issues in our code. We are NOT trying to use
OpenMP in any device or host device function. We are also not using any OpenMP
target stuff. This is just trying to use OpenMP3 and Cuda in the same object
file. 

NVCC has _OPENMP defined in both compilation phases. 

Small reproducer:
<<<<
#include<cstdio>
int main() {

  #ifdef _OPENMP
  #ifdef __CUDA_ARCH__
  #warning "OPENMP CUDA_ARCH"
  #else
  #warning "OPENMP"
  #endif
  #else
  #ifdef __CUDA_ARCH__
  #warning "DOH CUDA_ARCH"
  #else
  #warning "DOH"
  #endif
  #endif
}
<<<

Output with NVCC: 
nvcc -Xcompiler -fopenmp -x cu -c main.cpp
nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are
deprecated, and may be removed in a future release (Use
-Wno-deprecated-gpu-targets to suppress warning).
main.cpp:6:4: warning: #warning "OPENMP CUDA_ARCH" [-Wcpp]
   #warning "OPENMP CUDA_ARCH"
    ^
main.cpp:8:4: warning: #warning "OPENMP" [-Wcpp]
   #warning "OPENMP"
    ^
[crtrott@apollo BugOMPClang]$ nvcc -Xcompiler -fopenmp -x cu -c main.cpp
-arch=sm_35
main.cpp:6:4: warning: #warning "OPENMP CUDA_ARCH" [-Wcpp]
   #warning "OPENMP CUDA_ARCH"
    ^
main.cpp:8:4: warning: #warning "OPENMP" [-Wcpp]
   #warning "OPENMP"
    ^


Output with Clang:
/home/projects/x86-64/clang/head/bin/clang++ -x cuda --cuda-gpu-arch=sm_35
-fopenmp=libomp
--gcc-toolchain=/projects/sems/install/rhel6-x86_64/sems/compiler/gcc/5.3.0/base
-c main.cpp 
main.cpp:12:4: warning: "DOH CUDA_ARCH" [-W#warnings]
  #warning "DOH CUDA_ARCH"
   ^
1 warning generated.
main.cpp:8:4: warning: "OPENMP" [-W#warnings]
  #warning "OPENMP"
   ^
1 warning generated.

This was with 
Clang: 61a39e4b5bf70f40db70d51f71948a66e567c559
LLVM: 6f185f662a9dc692c12417784c9756bc3212cde8
checked out from github.com/llvm-mirror</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>