CUDA pseudorandom number generator CURAND

Hello

I read the manual “CUDA Toolkit 4.0 CURAND Guide PG-05328-040_v01 | January 2011”

From : CUDA Toolkit Documentation

When I compile the source from my PC so I have to change path of cuda.h and curand.h

/*

* This program uses the host CURAND API to generate 100

* pseudorandom floats .

*/

# include "stdio.h"

# include "stdlib.h"

# include "../include/cuda.h"

# include "../include/curand.h"

# define CUDA_CALL (x) do { if ((x) != cudaSuccess ) { \

	printf (" Error at %s:%d\n", __FILE__ , __LINE__ );\

	return EXIT_FAILURE ;}} while (0)

# define CURAND_CALL (x) do { if ((x) != CURAND_STATUS_SUCCESS ) { \

	printf (" Error at %s:%d\n", __FILE__ , __LINE__ ); \

	return EXIT_FAILURE ;}} while (0)

int main (int argc , char * argv [])

{

	size_t n = 100;

	size_t i;

	curandGenerator_t gen;

	float * devData , * hostData ;

	/* Allocate n floats on host */

	hostData = ( float *) calloc (n, sizeof ( float ));

	/* Allocate n floats on device */

	CUDA_CALL ( cudaMalloc (( void **)& devData , n * sizeof ( float )));	//HERE IS 26TH line

	/* Create pseudo - random number generator */

	CURAND_CALL ( curandCreateGenerator (& gen ,	CURAND_RNG_PSEUDO_DEFAULT ));

	/* Set seed */

	CURAND_CALL ( curandSetPseudoRandomGeneratorSeed (gen , 1234));	//HERE IS 32TH LINE

	/* Generate n floats on device */

	CURAND_CALL ( curandGenerateUniform (gen , devData , n));

	/* Copy device memory to host */

	CUDA_CALL ( cudaMemcpy ( hostData , devData , n * sizeof ( float ),

	cudaMemcpyDeviceToHost ));

	/* Show result */

	for(i = 0; i < n; i++) {

		printf ("%1.4 f ", hostData [i]);

	}

	printf ("\ n");

	/* Cleanup */

	CURAND_CALL ( curandDestroyGenerator (gen));

	CUDA_CALL ( cudaFree ( devData ));

	free ( hostData );

	return EXIT_SUCCESS ;

}

I wonder the result.

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\sarit>nvcc -arch=sm_13 c

udarand.cu

cudarand.cu

cudarand.cu(26): error: identifier "x" is undefined

cudarand.cu(26): error: expected a ";"

cudarand.cu(29): error: expected a ";"

cudarand.cu(32): error: expected a ";"

cudarand.cu(35): error: expected a ";"

cudarand.cu(38): error: expected a ";"

cudarand.cu(45): warning: unrecognized character escape sequence

cudarand.cu(48): error: expected a ";"

cudarand.cu(49): error: expected a ";"

cudarand.cu(19): warning: variable "gen" was declared but never referenced

cudarand.cu(20): warning: variable "devData" was declared but never referenced

8 errors detected in the compilation of "C:/Users/7-64/AppData/Local/Temp/tmpxft

_00000498_00000000-6_cudarand.cpp1.ii".

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\sarit>

Here is my nvcc version. (If need)

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\sarit>nvcc --version

nvcc: NVIDIA (R) Cuda compiler driver

Copyright (c) 2005-2011 NVIDIA Corporation

Built on Fri_May_13_01:41:59_PDT_2011

Cuda compilation tools, release 4.0, V0.2.1221

There is a “x” in the argument. So what does this mean ?

cudarand.cu(26): error: identifier "x" is undefined

I deleted “ULL” at 32th line, even it does not relevant to 8 erros.

The line number has been shortened in order to view in compact page.

Where should I start to figure out the problem ?

Any help would be appreciated.

It looks like something is going wrong with the interpretation of the preprocessor macros you have. (That’s where the “x” is coming from, I assume.) I’m not sure what the problem is beyond that.

Thank you for your reply.

Is there anyboy got this problem please let me know.

My OS = M$ 7-64.

MS visual studio professional 2008.

TwT

I take a look at my classic book, “Numerical Recipe in C”

After that I try to use ran2() on GPU.

Badluck,

"static" is not allowed within a __device__ or __global__ function

External Image

I copy directory common from “CUDA by Example” and place in the toolkit

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0>dir

 Volume in drive C has no label.

 Volume Serial Number is F417-A0D2

Directory of C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0

07/08/2011  03:11 AM    <DIR>          .

07/08/2011  03:11 AM    <DIR>          ..

06/28/2011  03:01 PM    <DIR>          bin

07/08/2011  03:11 AM    <DIR>          common

06/28/2011  03:01 PM    <DIR>          computeprof

06/28/2011  03:01 PM    <DIR>          doc

06/28/2011  03:01 PM    <DIR>          extras

06/28/2011  03:01 PM    <DIR>          include

06/28/2011  03:01 PM    <DIR>          lib

06/28/2011  03:01 PM    <DIR>          open64

07/08/2011  03:20 AM    <DIR>          sarit

06/28/2011  03:01 PM    <DIR>          src

               0 File(s)              0 bytes

In directory common you will found file book.h as uaual.

Therefore I modify my #include and get rid of the CUDA_CALL

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\sarit>nvcc ridda.cu

ridda.cu

tmpxft_00001a00_00000000-3_ridda.cudafe1.gpu

tmpxft_00001a00_00000000-8_ridda.cudafe2.gpu

ridda.cu

tmpxft_00001a00_00000000-3_ridda.cudafe1.cpp

tmpxft_00001a00_00000000-14_ridda.ii

tmpxft_00001a00_00000000-15_ridda.obj : error LNK2019: unresolved external symbo

l curandDestroyGenerator referenced in function main

tmpxft_00001a00_00000000-15_ridda.obj : error LNK2019: unresolved external symbo

l curandGenerateUniform referenced in function main

tmpxft_00001a00_00000000-15_ridda.obj : error LNK2019: unresolved external symbo

l curandSetPseudoRandomGeneratorSeed referenced in function main

tmpxft_00001a00_00000000-15_ridda.obj : error LNK2019: unresolved external symbo

l curandCreateGenerator referenced in function main

a.exe : fatal error LNK1120: 4 unresolved externals

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\sarit>

External Image