llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

'Incomplete type' error when mapping a global extern std::array

Open jtramm opened this issue 5 years ago • 1 comments

Bugzilla Link 50508
Resolution FIXED
Resolved on Aug 06, 2021 05:36
Version unspecified
OS Linux
CC @alexey-bataev,@jdoerfert,@jyu2-git,@jtramm,@RaviNarayanaswamy

Extended Description

An error occurs when compiling the following file (transfer.cpp) that attempts to map a global scope std::array object declared as extern:

#include #pragma omp declare target extern std::array<double, 4> arr; #pragma omp end declare target void copy_host_to_device() { #pragma omp target update to(arr) } void copy_device_to_host() { #pragma omp target update from(arr) }

Compiled with clang++ (version 13.0.0 (https://github.com/llvm/llvm-project.git 59d938e649e62db0cef4903d495e838fbc6a6eb8) for a V100 target as:

clang++ -Wall -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_70 -c transfer.cpp -o transfer.o

The error given is:

transfer.cpp:9:32: error: incomplete type 'std::array<double, 4>' where a complete type is required #pragma omp target update to(arr) ^~~ transfer.cpp:9:3: error: expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update' #pragma omp target update to(arr) ^ transfer.cpp:14:34: error: incomplete type 'std::array<double, 4>' where a complete type is required #pragma omp target update from(arr) ^~~ transfer.cpp:14:3: error: expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update' #pragma omp target update from(arr) ^ 4 errors generated.

As a workaround (found by Johannes Doerfert), it works if the array is instantiated in the first function as:

void copy_host_to_device() { arr[0]; #pragma omp target update to(arr) }

The code for this reproducer is available at:

https://github.com/jtramm/omp_target_issues/blob/master/array_simple/transfer.cpp

and a larger version with a main can be found at:

https://github.com/jtramm/omp_target_issues/tree/master/array

jtramm avatar May 27 '21 15:05 jtramm

This is fix in https://reviews.llvm.org/D107200

jyu2-git avatar Aug 06 '21 12:08 jyu2-git