cudamemcpy2d 返回错误 - 以下是下面代码中的代码,我提到了我遇到错误的行。请查看并帮助我。
main(){
int nrow = 16,ncol = 41;
//
double **x = new double*[nrow];
double **y = new double*[nrow];
for(int i=0; i<nrow; i++){
x[i] = new double[ncol];
y[i] = new double[ncol];
}
// both x and y are filled with some values and function is called;
function(x,y, nrow, ncol);
}
void function(double **x, double **y, int nrow, ncol){
double *dev_x, *dev_y;
size_t pitch_x, pitch_y;
cudaMallocPitch((void **) &dev_x, &pitch_x, (n_col*sizeof(double)), nrow);
cudaMallocPitch((void **) &dev_y, &pitch_y, (n_col*sizeof(double)), nrow);
// this below line is returning error invalid value
cudaMemcpy2D((void *)dev_x, pitch_x, (void *) *x, sizeof(double)*ncol, sizeof(double)*ncol, nrow, cudaMemcpyDeviceToHost);
//launch a kernel
kernel<<< 1, 1>>>(dev_x, dev_y, nrow, ncol);
//below also gives the same error..
cudaMemcpy2D((void *) *x, sizeof(double)*ncol, dev_x, pitch_x, sizeof(double)*ncol, nrow, cudaMemcpyHostToDevice);
}
请帮忙谢谢