I have written a simple pseudo-random number generator using cuRand
. After successfully compiling it, I try running the executable but after running several times it works properly and gives me random number.
What am I missing here should I do some initialization for my device in order to make it properly work in first run?
Here is my code :
void initializeCUDA(int argc, char **argv, int &devID, int &iSizeMultiple)
{
// By default, we use device 0, otherwise we override the device ID based on what is provided at the command line
cudaError_t error;
devID = 0;
if (checkCmdLineFlag(argc, (const char **)argv, "device"))
{
devID = getCmdLineArgumentInt(argc, (const char **)argv, "device");
error = cudaSetDevice(devID);
if (error != cudaSuccess)
{
printf("cudaSetDevice returned error code %d, line(%d)\n", error, __LINE__);
exit(EXIT_FAILURE);
}
}
// get number of SMs on this GPU
error = cudaGetDevice(&devID);
if (error != cudaSuccess)
{
printf("cudaGetDevice returned error code %d, line(%d)\n", error, __LINE__);
exit(EXIT_FAILURE);
}
if (checkCmdLineFlag(argc, (const char **)argv, "sizemult"))
{
iSizeMultiple = getCmdLineArgumentInt(argc, (const char **)argv, "sizemult");
}
iSizeMultiple = art_min(iSizeMultiple, 10);
iSizeMultiple = art_max(iSizeMultiple, 1);
cudaDeviceProp deviceProp;
cudaGetDeviceProperties(&deviceProp, devID);
checkCudaErrors(cudaGetDeviceProperties(&deviceProp, DEVICE_ID));
DEVICE_ID = devID;
printf("GPU Device %d: \"%s\" with compute capability %d.%d\n\n", devID, deviceProp.name, deviceProp.major, deviceProp.minor);
// use a larger block size for Fermi and above
block_size = (deviceProp.major < 2) ? 16 : 32;
}
And this is my PRNG code:
checkCudaErrors(cudaMalloc((void **) &d_data, mem_size));
size_t n = size_mat;
curandGenerator_t gen;
/* Create pseudo-random number generator */
(curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_DEFAULT));
/* Set seed */
(curandSetPseudoRandomGeneratorSeed(gen, 1234ULL));
/* Generate n floats on device */
(curandGenerateUniform(gen, d_data, n));
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire