I did a simple texture3D test and found strange behavior when copying data to a device. The cudaMemcpy3D function returns an "invalid argument".
I found that the problem is with cudaExtent. According to the CUDA Toolkit 4.0 Reference Guide, cudaExtent parameters are as follows:
- w - Width in bytes
- h - Element height
- d - Depth in elements
So, I prepared the texture as follows:
cudaChannelFormatDesc t_desc = cudaCreateChannelDesc<baseType>();
cudaExtent t_extent = make_cudaExtent(NCOLS*sizeof(baseType), NROWS, DEPTH);
cudaArray *i_ArrayPtr = NULL;
status = cudaMalloc3DArray(&i_ArrayPtr, &t_desc, t_extent);
And set up the 3D settings as follows:
cudaMemcpy3DParms i_3DParms = { 0 };
i_3DParms.srcPtr = make_cudaPitchedPtr( (void*)h_idata, NCOLS*sizeof(baseType), NCOLS, NROWS);
i_3DParms.dstArray = i_ArrayPtr;
i_3DParms.extent = t_extent;
i_3DParms.kind = cudaMemcpyHostToDevice;
And finally, I copied the data to the deviceโs memory:
// copy input data from host to device
status = cudaMemcpy3D( &i_3DParms );
The problem is resolved if I set only the number of elements in size x as:
cudaExtent t_extent = make_cudaExtent(NCOLS, NROWS, DEPTH);
, .
, - cudaExtent - . ?