I want to make a cudaArray that is a copy of an existing one, except that it has a 1-cell thick border of '0’s.
My attempt to achieve this:
...
cudaMallocArray(&edge, &channelDesc, M, N);
cudaMallocArray(&old, &channelDesc, (M+2), (N+2));
...
cudaMallocPitch((void **) &zero, &zerop, sizeof(float)*(M+2), (N+2));
cudaMemset2D(zero, zerop, 0.f, sizeof(float)*(M+2), (N+2));
cudaMemcpy2DToArray(old, 0, 0, zero, zerop, sizeof(float)*(M+2), (N+2), cudaMemcpyDeviceToDevice);
cudaFree(zero);
cudaMemcpyArrayToArray(old, 1, 1, edge, 0, 0, sizeof(float)*N*M, cudaMemcpyDeviceToDevice);
...
(‘edge’ is an N x M cudaArray and ‘old’ is an (N+2) x (M+2) cudaArray)
What I hoped this would do is create a 2D array called ‘zero’, which I fill with zeros, and then copy to my cudaArray ‘old’, setting all elements in ‘old’ to zero.
I then copy my existing cudaArray (‘edge’) to ‘old’, starting at the [1][1] cell of ‘old’.
I have reason to believe, however, that this is not doing what I intended. Do you think this code snippet should do what I want?
Thanks