cudaMemcpy problem

typedef struct {
	int M;
	int N;
	int records[NMAX][SZM];
	int times[NMAX];
	bool prime[NMAX];
} DATASET;

typedef int ITEMSET[SZM];

__device__ DATASET d_db;

DATASET db;

int main(void)
{

	loadDB();
	
	cudaMemcpy(&d_db, &db, sizeof(DATASET), cudaMemcpyHostToDevice);
        ...

I have a device variable d_db a variable db on the host. After I load same value on my db variable, I want to copy this variable on device. Compiling there are no errors, but when I execute the code there are some wornings about cache and sometimes the pc is restarted. What I’m doing wrong?

Please use proper cuda error checking before asking for help here. Even if you don’t understand the results of it (or even if the results are no error), it will be useful for others who are trying to help you. If you don’t know what “proper cuda error checking” is, please google “proper cuda error checking” and take the first hit.

We don’t use cudaMemcpy to copy to a device variable. We use cudaMemcpyToSymbol. This is covered in the documentation:

http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#variable-type-qualifiers

We also don’t take the address of the device variable. You use its symbol name directly:

cudaMemcpyToSymbol(d_db, &db, sizeof(DATASET));