Problems with using routine

It seems like using routine might bring a lot of potential problems.
The compiler need to compile all the function calls, including some libraries to the
accelerator.

I tried to compile one of my routines, but encounter something like this :

PGCC-S-0000-Internal compiler error. Call in OpenACC region to support routine - modff

It seems OpenACC cannot compile function “modf” in the standard math library.

Is there any way to fix this ?

Thanks.

Hi EvanzzzZ,

Normally you’d just add “accelmath.h” to get the device callable versions of the math.h routines. However, it appears that we don’t have a version of “modf” available. I put in an RFE (TPR#21825) and sent it to engineer to see what we can do. Can you work around this limitation by using the mod operator?

The compiler need to compile all the function calls, including some libraries to the accelerator.

Correct. There needs to be device versions of all routines called from device code. For system routines, we try to provide device version when possible. However some system routines such as file I/O simply isn’t available on the device so can’t be used.

  • Mat

Actually I didn’t use “accelmath.h”, I simply include “math.h”. And it seems like the compiler could compile for functions like “cos”, “log”, etc.

Probably not. I might need to think some other way to rewrite the function.
One more question, I guess when you using
“routine” to inform the compile the function fun1(),
it would also automatically compile all the routines that inside the fun1(), right ?

Also, I guess it didn’t support rand() function either ?


Thanks.

it would also automatically compile all the routines that inside the fun1(), right ?

No and Yes, sometimes.

If fun1 calls fun2, fun2 needs a device version as well. You need to decorate all routines called from device code with “#pragma acc routine” or have device version (such as one written in CUDA C) available.

However as a PGI feature for C++, we will automatically generate sequential device code for routines called from a compute region. With C++ templates, class members, lambdas, etc., it’s not feasible for a user to add the routine pragma everywhere and why we add this support. It is limited to routines who’s source is visible to the compiler so doesn’t work if the called routine is a separate source file.

  • Mat