Calling functions/methods in OpenAcc programme environment

Hello. I am new in OpenAcc and I have a few questions. Is it possible to move/copy objects of a class in C++ from CPU to the GPU and use their methods in the GPU environment?

Hi kspan,

Yes. The compiler will automatically create device callable routines including C++ class methods if the source for those routines are visible to the compiler during compilation and it detects that the routines are called from device code. If not visible, then you just need to add a “#pragma acc routine(methodname)” in the header file to tell the compiler to create device callable versions.

You can find some examples that I wrote on using OpenACC in a C++ Class in the Chapter 5 of the GitHub repository for the example code from Parallel Progamming with OpenACC book:

Take a look at the “accList.h” file for the accList class definition and "accList.double.cpp ", “accList.nested.double.cpp” or “accList.soaFloat3.cpp” for examples on it’s use.

Let me know if you have questions.