Hi,
I have some trouble using the “enter data” directive and I am hoping for some clarification.
The following code defines a simple struct containing a pointer to be used for a dynamic array:
struct my_struct {
float* x;
};
I would like to use a function with a static array of this struct as argument to copy data from the host to the device:
void copy2device(my_struct s[6]){// or void copy2device(my_struct s[])
#pragma acc enter data copyin(s[0].x[0:10])
#pragma acc enter data copyin(s[1].x[0:4])
#pragma acc enter data copyin(s[2].x[5:12])
}
pgc++ 15.7 generates the following output:
copy2device(my_struct *):
56, Accelerator clause: upper bound for dimension 0 of array 's' is unknown
Generating enter data copyin(s[:1],s->x[:10],s->x[:4],s->x[5:12])
So it seems that the compiler doesn’t know the length of array s, fair enough, and decides to only copy the struct contained in the first element of the array (s[:1]). What do the following statements, i.e. s->x[:10],s->x[:4],s->x[5:12], mean in this context? It would only make sense to allocate memory for x of the struct in the first array element, but it only mention s-> and no index for s. So there are three similar statements for allocating memory for x, but which one will be used in the end?
If I put:
#pragma acc enter data copyin(s[0:6])
The compiler no longer complains about an unknown upper bound for s:
copy2device(my_struct *):
56, Generating enter data copyin(s[:6],s->x[:10],s->x[:4],s->x[5:12])
But does it now allocate different amounts of memory for x of my_struct in the various elements of the array s?
To further complicate things I put the “enter data” into a switch statement. Some control structure might be needed to decide on when to copy what to the device:
void copy2device(my_struct s[6], int t){
#ifdef _OPENACC
#pragma acc enter data copyin(s[0:6])
switch(t){
case 0:
#pragma acc enter data copyin(s[0].x[0:10])
break;
case 1:
#pragma acc enter data copyin(s[1].x[0:4])
break;
case 2:
#pragma acc enter data copyin(s[2].x[5:12])
break;
default:
break;
}
#endif
}
In this case the compiler seems to ignore all “enter data” statements within the switch statement. Am I doing anything illegal wrt the OpenACC standard?
copy2device(my_struct *, int):
29, Generating enter data copyin(s[:6])
Putting “enter data copyin(s)” within the switch statement, the compiler does not report anything, i.e. it is not generating any data copying.
I am a bit confused about this behavior and would be thankful for any kind of clarification.
Thanks,
LS