[llvm-bugs] [Bug 40935] New: omp declare target global variable bug

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Mar 2 08:53:31 PST 2019


https://bugs.llvm.org/show_bug.cgi?id=40935

            Bug ID: 40935
           Summary: omp declare target global variable bug
           Product: OpenMP
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Clang Compiler Support
          Assignee: unassignedclangbugs at nondot.org
          Reporter: csdaley at lbl.gov
                CC: llvm-bugs at lists.llvm.org

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]".

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190302/5c0655a9/attachment.html>


More information about the llvm-bugs mailing list