3D array confusion again

Hi everybody,

I am trying to pass a 3D-array of floats from host to device, which causes some headache, I hope somebody can help me out. So I would like to have an array of, say, 512x512x8 floats. Tried to do this with 3D arrays, but without success so far.

Of course I already read through the threads about this topic and did some google search, but I was not able to figure out how it actually works. I would really appreciate augmenting the documentation a bit.

I tried the following:

#define BUFFER_WIDTH		512

#define MAX_FORCES		8


cudaChannelFormatDesc desc = cudaCreateChannelDesc<float>();

cudaExtent extent = make_cudaExtent( BUFFER_WIDTH, BUFFER_WIDTH, MAX_FORCES );

handleCudaError( cudaMalloc3DArray( &( this->forceWeightArray ), &desc, extent, cudaArrayDefault ) );

cudaMemcpy3DParms params = {0};

params.dstArray = this->forceWeightArray;

params.dstPos.x = 0;

params.dstPos.y = 0;

params.dstPos.z = 0;

params.extent = extent;

params.kind = cudaMemcpyHostToDevice;

params.srcPtr = make_cudaPitchedPtr( (void*)( this->forceWeightData ), BUFFER_WIDTH * sizeof( float ), BUFFER_WIDTH, BUFFER_WIDTH );

handleCudaError( cudaMemcpy3D( &params ) );

cudaMemcpy3D fails with “invalid argument”. I tried different extents, pitches, widths and heights, but couldn’t get it to work.

I’ve got several questions there:

  • extent.width/height/depth in element count, right? for both calls?

  • pitch in bytes, right?

  • width of pitched pointer in element count, right?

  • height of pitched pointer in element count, right?

Can anybody give me a working code snippet on this?


Stumbled across the simpleLayeredTexture sample and finally figured it out: the error was the cudaArrayDefault parameter, which should be cudaArrayLayered.