<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 - omp declare target global variable bug"
   href="https://bugs.llvm.org/show_bug.cgi?id=40935">40935</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>omp declare target global variable bug
          </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>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>Clang Compiler Support
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>csdaley@lbl.gov
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hello all,

There are problems when using a globally-scoped device array which has an "omp
declare target" around the array declaration.

Please see the test problem shown below. The host and device arrays should sum
to 10. The device array sums to 0 when using the LLVM/Clang compiler on a
system with Intel Skylake CPUs and NVIDIA Volta GPUs. I am using the master
branch of a version of LLVM/Clang from 20 Feb 2019.

$ clang -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda main.c -o main && srun -n
1 ./main
host=10, device=0 - FAILURE

$ more base.h main.c
::::::::::::::
base.h
::::::::::::::
#include <stdio.h>

#define SZ 10
#pragma omp declare target
extern int data[SZ];
#pragma omp end declare target

void check_data(void);
::::::::::::::
main.c
::::::::::::::
#include "base.h"
#pragma omp declare target
int data[SZ];
#pragma omp end declare target

int main()
{
  int i;
  for (i=0; i<SZ; ++i) data[i] = 1;
#pragma omp target update to(data)
  check_data();
  return 0;
}

void check_data(void)
{
  int sum_host = 0.0, sum_device = 0.0, i;
  for (i=0; i<SZ; ++i) sum_host += data[i];

#pragma omp target map(tofrom:sum_device)
#pragma omp teams distribute parallel for reduction(+:sum_device)
  for (i=0; i<SZ; ++i) sum_device += data[i];

  printf("host=%d, device=%d - %s\n", sum_host, sum_device,
         sum_host - sum_device == 0 ? "SUCCESS" : "FAILURE");
}

This test program, which does not need a globally-scoped array, works when
commenting out the "omp declare target" around "extern int data[SZ]".</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>