Invalid argument in cudaMemcpy3D using width in bytes?

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:

// prepare texture 
cudaChannelFormatDesc t_desc = cudaCreateChannelDesc<baseType>();
// CUDA extent parameters w - Width in bytes, h - Height in elements, d - Depth in elements
cudaExtent t_extent = make_cudaExtent(NCOLS*sizeof(baseType), NROWS, DEPTH);
// CUDA arrays are opaque memory layouts optimized for texture fetching
cudaArray *i_ArrayPtr = NULL;
// allocate 3D
status = cudaMalloc3DArray(&i_ArrayPtr, &t_desc, t_extent);

And set up the 3D settings as follows:

// prepare input data
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 - . ?

+5
1

CUDA , . , . cudaMalloc3DArray, . cudaMalloc3D, .

+6

All Articles