I want to generate white noise (normal distribution) using CUDA. Below is my attempt.
enter code here
#define SCALE 1.0
#define SHIFT 0.0
#define BLOCKS 64
#define THREADS 64
__global__ void setup_kernel(curandState *state)
{
int id = threadIdx.x + blockIdx.x * blockDim.x;
curand_init(7+id, id, 0, &state[id]);
}
__global__ void generate_normal_kernel(curandState *state, int *result)
{
int id = threadIdx.x + blockIdx.x * blockDim.x;
float x;
curandState localState = state[id];
for(int n = 0; n < 100000; n++) {
x = (curand_normal(&localState) * SCALE)+SHIFT;
}
state[id] = localState;
result[id] = (int) x;
}
int main(int argc, char *argv[])
{
int i;
unsigned int total;
curandState *devStates;
int *devResults, *hostResults;
int device;
struct cudaDeviceProp properties;
CUDA_CALL(cudaGetDevice(&device));
CUDA_CALL(cudaGetDeviceProperties(&properties,device));
hostResults = (int *)calloc(THREADS * BLOCKS, sizeof(int));
CUDA_CALL(cudaMalloc((void **)&devResults, BLOCKS * THREADS *
sizeof(int)));
CUDA_CALL(cudaMemset(devResults, 0, THREADS * BLOCKS *
sizeof(int)));
CUDA_CALL(cudaMalloc((void **)&devStates, THREADS * BLOCKS *
sizeof(curandState)));
setup_kernel<<<BLOCKS, THREADS>>>(devStates);
generate_normal_kernel<<<BLOCKS, THREADS>>>(devStates, devResults);
CUDA_CALL(cudaMemcpy(hostResults, devResults, BLOCKS * THREADS *
sizeof(int), cudaMemcpyDeviceToHost));
I_TCS = ITCSAmp*hostResults;
/* Cleanup */
CUDA_CALL(cudaFree(devStates));
CUDA_CALL(cudaFree(devResults));
free(hostResults);
return EXIT_SUCCESS;
}
===============================================================================
But I got the following errors,
error: identifier "CUDA_CALL" is undefined
error: expression must have arithmetic or enum type
error: expression must have arithmetic or enum type
error: expression must have arithmetic or enum type
warning: variable "total" was declared but never referenced
error: identifier "devStates" is undefined
error: identifier "CUDA_CALL" is undefined
error: identifier "devResults" is undefined
error: identifier "hostResults" is undefined
It thought I defined them already, but obviously it didn't work. If you have any suggestions or know how might I change the code, I will be really thankful for your help!