0

i want to fill my arrays on GPU side:

in order to do that :

First i created arrays for host side and device side:

int *d_A = NULL;
int *h_A = NULL;

then i allocate memory for host array:

h_A = (int *)malloc(numOfData*sizeof(int));

and then i allocate for device array:

cudaMalloc((void **) &d_A, numOfData * sizeof(int));

and then i pass the d_A to the gpu side

cudaMemcpy(d_A, h_A, numOfData, cudaMemcpyHostToDevice);

and call function

  generateVector<<<1,2>>>(d_A,numOfData);

generate function is below:

_global__ void generateVector(int * d_Data,int count) {

    for (int i = 0; i < count; i++) {
        d_Data[i] = rand_from_0_to_100_gen();
    }
}

I know GPU side does now allow me to use rand function to fill my array. What can i do then? What is the possible solution?

  • Here's [an example](http://stackoverflow.com/questions/15247522/cuda-random-number-generation/15252202#15252202) showing how to create random numbers on the GPU. Note that in that particular case, each thread generates the same random sequence, but this is easily changeable by passing a different seed perhaps based on `threadIdx.x` to each thread. – Robert Crovella Apr 03 '13 at 22:44
  • Also, see http://stackoverflow.com/questions/11024718/can-thrust-generate-random-numbers-on-the-device – Steve Apr 03 '13 at 23:12
  • Please edit your existing question rather than adding a new one. – ChrisF Apr 04 '13 at 11:17

1 Answers1

-1

I believe, by far the easiest way for you would be to use CURAND library. You can find some samples in CUDA SDK - take a look at Monte-Carlo ones.

Eugene
  • 9,242
  • 2
  • 30
  • 29