I have a rather big code in C++, I had to integrate some new class to the base class as shown below.
class A
{
int N;
B b;
double *__restrict__ w;
construct();
}
A::construct()
{
w=new double[N];
#pragma acc data enter create(this)
#pragma acc update device(this)
#pragma acc data enter create(w)
// allocate class A
b.construct()
}
class B
{
double *__restrict__ u;
double *__restrict__ v;
B(){};
construct();
}
B::construct()
{
u=new double[N];
v=new double[N];
#pragma acc data enter create(this)
#pragma acc update device(this)
#pragma acc data enter create(u)
#pragma acc data enter create(v)
}
I think I am running into the deep copy issue as the pointers of class B are invalidated and hence the behavior of the code on GPU i undefined. I would appreciate the feedback on how to perform the class inclusion in another class without getting into the deep copy issue. I suspect the update device (this) somehow causes this.
Do you have a full example which recreates the error you're seeing? I wrote a little test example using your code snip-it and it worked fine. (See below)
If you were updating the "this" pointer after creating the arrays, then it would be a problem since you'd be overwriting the device pointers with the host pointers. But as you show above, it shouldn't be an issue.