I have a question:
If we have a C++ class containing the dynamic data, how can we transfer the object of that to the device using openacc with deep copy. I saw the example from the book “Parallel Programming with OpenACC” where data management is encapsulated into the class and it works good. But my question is directed to deep copy option. I could not find an example for C++. The only example I found uses shape and policy (with C, not C++) but I guess they are no longer required. So what is the way to use deep copy with C++ classes now?
So what is the way to use deep copy with C++ classes now?
Unfortunately, true deep copy didn’t get adopted into the OpenACC standard. Hence shape and policy remain a beta feature. Though we haven’t work on it for some time and no other compiler adopted it. Not sure I can recommend using it.
Most folks use CUDA Unified Memory (i.e. -gpu=managed). Static class objects still need to be manually managed, but dynamic data members do not making things much easier to program.
Even though I wrote the “Parallel Programming with OpenACC” example in 2015 so it’s a bit dated, encapsulation is still how I’d recommend doing manual deep copy. The only change I’d probably make is to move the device data creation/delete from the constructor/destructor to their own methods. Not an issue with a single class, but becomes problematic when using classes with dynamic data members as members of another class. I posted an example of how to do this here: C++ class in OpenACC
If you encounter specific issues, let me know and we can work through the problem.
-Mat
Thank you Mat. That was really helpful.