3D texture problem

I am trying to use a 3D texture to do trilinear interpolation. But I found my code gave errors depending on my 3D matrix size. Some matrix sizes can work well, but some don’t.

For example:
X Y Z that work:
( 4, 4, 4 ), ( 368, 176, 176 );

X Y Z gave error “cudaMemcpy3D: invalid argument”
( 256, 256, 128 ), (512, 512, 256);

X Y Z gave error “cudaMemcpy3D: invalid configuration argument”
( 368, 368, 368 ), (512, 4, 4 );

X Y Z gave error “cudaMalloc3DArray: out of memory.”
(512, 512, 512 )

Could any one help me to solve this problem. It really drove me crazy.

cudaMemcpy3D is tricky, you need to supply it with stride etc. There are a lot of similar threads in the forum. Also old cuda documentions was not complete.

Do you have an example code about 3D texture which supplied with stride? So that I can learn and modify my code.

Thank you for replying so fast.

I suggest to serch forum with memcpy3d and search sdk, there is an example of using 3D textures.