I am trying to use structs in my CUDA program, however I seem to be missing something important here. I have simplified the following code to exploit the problem:
struct genericArray
{
float* values;
};
void runTest()
{
genericArray h_idata;
// allocate host memory
h_idata.values = (float*) malloc( sizeof( float) * N);
// initalize the memory
for( unsigned int i = 0; i < N; ++i)
{
h_idata.values[i] = (float) i;
}
// allocate device memory
genericArray d_idata;
CUDA_SAFE_CALL( cudaMalloc( (void**) &(d_idata.values), sizeof( float) * N));
// copy host memory to device
CUDA_SAFE_CALL( cudaMemcpy( &(d_idata.values), &(h_idata.values), sizeof( float) * N, cudaMemcpyHostToDevice) );
}
I have omitted the rest of the method runTest for brevity.
The error occurs at the final call to cudaMemcpy. My program crashes with an error:
Can anyone tell me what’s going wrong here?