The problem
I am compiling a CUDA shared library that I've written, for this library, I need the capability to randomly sample stuff, therefore, as specified by the docs, I am initializing an array of curandState_t
:
/**
* @brief Sets up random number generators for each thread
*
* @param state pointer to the array of curandState
* @param seed seed for the random number generator
*/
__global__ void rand_setup(curandState_t* state, unsigned long seed)
{
/* 3D grid of 3D blocks id */
size_t gid = getGlobalIdx_3D_3D();
curand_init(seed, gid, 0, &state[gid]);
printf("Initializing random number generator for thread %d");
}
The getGlobalIdx_3D_3D()
call just retrieves the global ID through a bunch of tedious calculations, such as:
/**
* @brief Get the global identifier of the thread
*
* thanks to: https://cs.calvin.edu/courses/cs/374/CUDA/CUDA-Thread-Indexing-Cheatsheet.pdf
* for the snippet
*
* @return size_t The global index of the thread
*/
__device__ size_t getGlobalIdx_3D_3D()
{
size_t blockId = blockIdx.x + blockIdx.y * gridDim.x
+ gridDim.x * gridDim.y * blockIdx.z;
size_t threadId = blockId * (blockDim.x * blockDim.y * blockDim.z)
+ (threadIdx.z * (blockDim.x * blockDim.y))
+ (threadIdx.y * blockDim.x) + threadIdx.x;
return threadId;
}
The errors
I am getting a cascade of compilation errors (I have just completed a substantial amount of work), however, many of them seem to stem from the fact that curandState_t
is not recognized as a proper type, hence I get this annoying dump:
D:\Repos\MulticoreTree\shared\libkernel.cu(325): error: attribute "__global__" does not apply here
D:\Repos\MulticoreTree\shared\libkernel.cu(325): error: incomplete type is not allowed
D:\Repos\MulticoreTree\shared\libkernel.cu(325): error: identifier "curandState_t" is undefined
D:\Repos\MulticoreTree\shared\libkernel.cu(325): error: identifier "state" is undefined
D:\Repos\MulticoreTree\shared\libkernel.cu(325): error: type name is not allowed
D:\Repos\MulticoreTree\shared\libkernel.cu(325): error: expected a ")"
D:\Repos\MulticoreTree\shared\libkernel.cu(326): error: expected a ";"
D:\Repos\MulticoreTree\shared\libkernel.cu(407): warning #12-D: parsing restarts here after previous syntax error
Looking online for documentation, there doesn't seem to be anything that tells me to import a specific header, also, I have #include <cuda_runtime.h>
at the top of my file, so what could be wrong?
I personally think that the type is not being recognized, but there might also be a problem with something else in the function's signature causing it to fail compilation.
Aucun commentaire:
Enregistrer un commentaire