Hello everyone!
I assume the topic title is quite self-explanatory, so I’ll just post the simple code which gives me that error (I’m not copying error checking parts, but I check the result of every function call, and the only error I get is the one from cudaMemcpy2DFromArray):
cudaSetDevice(0);
// CUDAPixel is a simple regular struct I defined; test_dst is the destination buffer in the device
CUDAPixel *test_dst;
// I'm going to use cudaMallocPitch to allocate device memory
size_t test_pitch;
// Size of the matrix
int test_width = 10;
int test_height = 5;
// test_src points to the data source on the host; I'm just allocating it, the content is not important for the test
CUDAPixel *test_src = new CUDAPixel[test_width*test_height];
// Allocate device memory
cudaMallocPitch(&test_dst, &test_pitch, test_width*sizeof(CUDAPixel), test_height);
// Copy test_src (regular array in host memory) to test_dst (2D array in device memory)
cudaMemcpy2DFromArray(test_dst, test_pitch, (const struct cudaArray*) test_src, 0, 0, test_width*sizeof(CUDAPixel), test_height, cudaMemcpyHostToDevice);
The last instruction gives me the “invalid copy direction for memcpy” error. Am I missing anything?
Thanks for your help!