title: Using Clang with OpenMP Offloading to NVIDIA GPUs
body: <p>I wrote a simple c code, and I would like to offload it to GPU in windows 10. I installed Visual Studio 2017 Enterprise and latest release clang from <a href="https://releases.llvm.org/" rel="nofollow noreferrer">https://releases.llvm.org/</a> and CUDA 10.1. I used this command to compile the code:</p>
  
  <pre><code>&gt;clang -pedantic -Wall -o ompGO test.c -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -lc -lcudart -L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\lib\x64" --cuda-path="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1"
  </code></pre>
  
  <p>But I keep getting weird errors like:</p>
  
  <pre><code>clang: warning: No library 'libomptarget-nvptx-sm_35.bc' found in the default clang lib directory or in LIBRARY_PATH. Expect degraded performance due to no inlining of runtime functions on target devices. [-Wopenmp-target]
  test.c:40:2: warning: no newline at end of file [-Wnewline-eof]
  }
   ^
  1 warning generated.
  In file included from test.c:1:
  In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\stdio.h:12:
  In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:10:
  In file included from C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:48:
  In file included from C:\Program Files\LLVM\lib\clang\10.0.0\include\vadefs.h:18:
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\vadefs.h:28:33: error: expected ';' after top level declarator
          typedef unsigned __int64  uintptr_t;
                                  ^
  In file included from test.c:1:
  In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\stdio.h:12:
  In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:10:
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:83:1: error: expected identifier
  _CRT_BEGIN_C_HEADER
  ^
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:76:29: note: expanded from macro '_CRT_BEGIN_C_HEADER'
          __pragma(pack(push, _CRT_PACKING))
                              ^
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\vadefs.h:14:22: note: expanded from macro '_CRT_PACKING'
  #define _CRT_PACKING 8
                       ^
  In file included from test.c:1:
  In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\stdio.h:12:
  In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:10:
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:83:20: error: expected ';' after top level declarator
  _CRT_BEGIN_C_HEADER
                     ^
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:180:29: error: expected ';' after top level declarator
      typedef unsigned __int64 size_t;
                              ^
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:283:51: error: unknown type name 'uintptr_t'; did you mean 'intptr_t'?
          void __cdecl __security_check_cookie(_In_ uintptr_t _StackCookie);
                                                    ^
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:182:30: note: 'intptr_t' declared here
      typedef __int64          intptr_t;
                               ^
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:284:9: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec
        attributes
          __declspec(noreturn) void __cdecl __report_gsfailure(_In_ uintptr_t _StackCookie);
          ^
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:284:67: error: unknown type name 'uintptr_t'; did you mean 'intptr_t'?
          __declspec(noreturn) void __cdecl __report_gsfailure(_In_ uintptr_t _StackCookie);
                                                                    ^
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:182:30: note: 'intptr_t' declared here
      typedef __int64          intptr_t;
                               ^
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:288:8: error: unknown type name 'uintptr_t'; did you mean 'intptr_t'?
  extern uintptr_t __security_cookie;
         ^
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:182:30: note: 'intptr_t' declared here
      typedef __int64          intptr_t;
                               ^
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:296:1: error: a parameter list without types is only allowed in a function definition
  _CRT_END_C_HEADER
  ^
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:79:23: note: expanded from macro '_CRT_END_C_HEADER'
          __pragma(pack(pop))
                        ^
  In file included from test.c:1:
  In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\stdio.h:12:
  C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:12:1: error: expected function body after function declarator
  _CRT_BEGIN_C_HEADER
  ^
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:76:9: note: expanded from macro '_CRT_BEGIN_C_HEADER'
          __pragma(pack(push, _CRT_PACKING))
          ^
  In file included from test.c:1:
  In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\stdio.h:12:
  C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:279:10: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
  _ACRTIMP __declspec(noreturn) void __cdecl _invalid_parameter_noinfo_noreturn(void);
           ^
  C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:281:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
  __declspec(noreturn)
  ^
  C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:287:16: error: unknown type name 'uintptr_t'; did you mean 'intptr_t'?
      _In_       uintptr_t _Reserved);
                 ^
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:182:30: note: 'intptr_t' declared here
      typedef __int64          intptr_t;
                               ^
  In file included from test.c:1:
  In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\stdio.h:12:
  C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:561:13: error: unknown type name 'size_t'; did you mean 'time_t'?
      typedef size_t rsize_t;
              ^
  C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:551:28: note: 'time_t' declared here
          typedef __time64_t time_t;
                             ^
  C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:2010:1: error: a parameter list without types is only allowed in a function definition
  _CRT_END_C_HEADER
  ^
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:79:23: note: expanded from macro '_CRT_END_C_HEADER'
          __pragma(pack(pop))
                        ^
  In file included from test.c:1:
  In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\stdio.h:13:
  In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt_wstdio.h:13:
  C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt_stdio_config.h:12:1: error: expected function body after function declarator
  _CRT_BEGIN_C_HEADER
  ^
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:76:9: note: expanded from macro '_CRT_BEGIN_C_HEADER'
          __pragma(pack(push, _CRT_PACKING))
          ^
  In file included from test.c:1:
  In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\stdio.h:13:
  C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt_wstdio.h:31:14: error: unknown type name 'FILE'
  _ACRTIMP_ALT FILE* __cdecl __acrt_iob_func(unsigned _Ix);
               ^
  C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt_wstdio.h:49:17: error: unknown type name 'FILE'
          _Inout_ FILE* _Stream
                  ^
  C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt_wstdio.h:58:17: error: unknown type name 'FILE'
          _Inout_ FILE*   _Stream);
                  ^
  fatal error: too many errors emitted, stopping now [-ferror-limit=]
  20 errors generated.
  </code></pre>
  
  <p>The code is as follow:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  #include &lt;conio.h&gt;
  #include &lt;time.h&gt;
  #include &lt;stddef.h&gt;
  #include &lt;stdlib.h&gt;
  
  #include &lt;omp.h&gt;
  
  int main (){
  
  
  
      const int N = 1000;
      unsigned int i;
      unsigned int j;
      float *a;
      float *b;
      float *c;
  
      a = (float *)malloc(N * sizeof(float));
      b = (float *)malloc(N * sizeof(float));
      c = (float *)malloc(N * sizeof(float));
          //srand((unsigned int)time(NULL));
  
      for (i = 0; i &lt; N; i++) {
          a[i] = 0;
          b[i] = ((float)rand() / (float)(RAND_MAX)) * 4.0;
          c[i] = ((float)rand() / (float)(RAND_MAX)) * 4.0;
      }
  
      #pragma omp target data map (to: c[0:N], b[0:N]) map(tofrom: a[0:N])
      #pragma omp target teams distribute parallel for
      for (j=0; j&lt;N; j++)
      {
          a[j] = b[j]+3.73*c[j];
      }
  
      return 0;
  }
  </code></pre>
  
  <p>I would be grateful if anybody could help me. Apparently, there is error even in including stdio.h. I should highlight that I can compile c codes with clang but when I want to use OpenMP and GPU I got these errors.</p>