核心函式中要用data結構作用引數
1 typedef struct 2 { 3 int* value; 4 int* num; 5 } data;
1 //host端 2 3 data* h_input; 4 h_input=(data*)malloc(sizeof(data)); 5 h_input->value=(int*)malloc(sizeof(int)*N); 6 h_input->num=(int*)malloc(sizeof(int)*N); 7 8 data tmp; //用於過渡 9 cudaMalloc((void**)& tmp->value,sizeof(int)*N); 10 cudaMalloc((void**)&tmp->num,sizeof(int)*N);
1 //device端 2 3 data* d_input; 4 cudaMalloc((void**)&d_input,sizeof(data)); 5 6 //將host端資料複製端device端 7 cudaMemcpy(tmp->value,h_input->value,sizeof(int)*N,cudaMemcpyHostToDevice); 8 cudaMemcpy(tmp->num,h_input->num,sizeof(int)*N,cudaMemcpyHostToDevice); 9 cudaMemcpy(d_input,&tmp,sizeof(data),cudaMemcpyHostToDevice);
結構體複製的示意圖如下所示: