Confused about calls within device code

I’m new to PGI and I’m still trying to get a hold of things. I’m using cudafortran and am a little confused about how calls within device code work. I understand that for subroutines and function they need to be compiled in the same module file to use them within each other. What should I do for functions that are called but not defined by me? For example, I cannot call random_number(x) within my subroutine. I assume this is because random_number is defined somewhere else and this is not in the module that contains the subroutine calling it. How would I go about bringing random_number in?

Hi Cattaneo,

Only calls to subroutines that have device versions are able to be called from device code. While many intrinsic have been ported to the GPU, a few have not.

In particular, random_number does not have a device version. This is mostly due to the issue that random_number is not thread safe and must maintain a global state between calls so using it on the device would cause issues.

Instead, it’s suggested that you use the cuRAND library to generate device random numbers. Examples for using cuRAND can be found in “$PGI//CUDA-Libraries/cuRAND/test_rand_cuf” and “$PGI/20[19|20]/examples/CUDA-Fortran/CUDA-Fortran-Book/chapter5”.

Hope this helps,
Mat

Thank you very much for the reply. Is there a list somewhere of the ones that have been ported? I cannot find one.

Is there a list somewhere of the ones that have been ported?

No, sorry.