I am using pyCUDA for CUDA programming. I need to use random number inside kernel function. CURAND library doesn\'t work inside it (pyCUDA). Since, there is lot of work to b
There is one problem I have with the accepted answer.
We have a name mangling there which is sort of nasty (these _Z10initkerneli
and _Z14randfillkernelPfi
).
To avoid that we can wrap the code in the extern "C" {...}
clause manually.
code = """
#include
const int nstates = %(NGENERATORS)s;
__device__ curandState_t* states[nstates];
extern "C" {
__global__ void initkernel(int seed)
{ .... }
__global__ void randfillkernel(float *values, int N)
{ .... }
}
"""
Then the code is still compiled with no_extern_c=True
:
mod = SourceModule(code % { "NGENERATORS" : N }, no_extern_c=True)
and this should work with
init_func = mod.get_function("initkernel")
fill_func = mod.get_function("randfillkernel")
Hope that helps.