mary
mary

Reputation: 305

CUDA MemcpyHostToDevice

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?

Upvotes: 1

Views: 266

Answers (1)

mary
mary

Reputation: 305

Using __device__ variables you need to use MemcpyToSymbol and MemcpyFromSymbol instead of cudaMemcpy. So in my case I have to use

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

Upvotes: 2

Related Questions