I’m porting cpu random generator to gpu, it is part of larger c++ project.
I have random.cu file with kernel function and simple function to invoke that kernel from c++ host code
void cudarand(float* rnd)
{
int* seed=(int*)malloc(5000*sizeof(int));
for (int i =0 ; i<5000; i++)
{
seed[i]=(int)abs(10000000*rand()/ (RAND_MAX + 1.0));
}
size_t size = sizeof(rnd);
int* cuda_seed;
float* cuda_rnd;
cudaMalloc(&cuda_seed, sizeof(seed));
cudaMemcpy(cuda_seed, seed, sizeof(seed), cudaMemcpyHostToDevice);
cudaMalloc(&cuda_rnd, sizeof(rnd));
cudarandKernel<<<1,5000>>>(cuda_seed, cuda_rnd);
cudaMemcpy(rnd, cuda_rnd, sizeof(rnd), cudaMemcpyDeviceToHost);
cudaFree(cuda_rnd);
}
In host code I include “random.h”, which also is included in random.cu file
random.h is
#ifndef RANDOM_H
#define RANDOM_H
void cudarand(float* rnd);
From host code I pass array which should be filled by my kernel, but it remains empty. I tried that same kernel in separate project with only one .cu file and it works just perfect. What may be wrong?
Thanks in advance.