Need Help with cudaMemcpy3D need device to cudaArray copy

Hi all!

I came across a rather persistent problem with cudaMemcpy3D (or more likely, my understanding of it) while working on my thesis.

I want to copy a device Array of floats into a cudaArray. The device array contains linear voxel data.

When I first copy the divice Array to a host Array, the following code works:

[codebox]size_t brick_pitch = width * sizeof( cuda_voxel_t );

cudaPitchedPtr srcPtr = make_cudaPitchedPtr((void*)srcArray, brick_pitch, width, height);

cudaMemcpy3DParms copyParams = { 0 };

copyParams.dstArray = dstArray;

copyParams.dstPos = dstPos;

copyParams.extent = dstSize;

copyParams.srcPtr = srcPtr;

copyParams.kind = cudaMemcpyHostToDevice;

HVR_CUDA_SAFE_CALL( cudaMemcpy3D( &copyParams ) );[/codebox]

But I want to Copy directly from device to device.

the following Code compiles and doesn’t crash, but produces artifacts when displayed:

[codebox]size_t brick_pitch = width * sizeof( cuda_voxel_t );

int linSize = brick_pitch * height * depth;

cudaPitchedPtr srcPtr;

cudaExtent pitchedVolSize = make_cudaExtent(brick_pitch, width, height);

HVR_CUDA_SAFE_CALL(cudaMalloc3D(&srcPtr, pitchedVolSize));

cudaMemcpy( srcPtr.ptr, (void*)srcArray, linSize, cudaMemcpyDeviceToDevice );

cudaMemcpy3DParms copyParams = { 0 };

copyParams.dstArray = dstArray;

copyParams.dstPos = dstPos;

copyParams.extent = dstSize;

copyParams.srcPtr = srcPtr;

copyParams.kind = cudaMemcpyDeviceToDevice;

HVR_CUDA_SAFE_CALL( cudaMemcpy3D( &copyParams ) );

cudaFree( srcPtr.ptr );[/codebox]

I realize that this can’t be the way to go, I also tried the cudaMallocPitch method, but that resulted in crashing at the cudaMemcpy3D line.

What I want to know is: How do I set up the pitchedPointer in Order to copy from a device array to a cudaArray?

thanks a lot!