cudaMemcpyToArray failing on certain textures

Hello, I’m a sophomore CS student who just started coding with CUDA,

and I would really appreciate sharing of knowledge from anyone who knows what’s the problem with this.

I have gone through many CUDA tutorials but I just couldn’t figure this out.

I’m trying to port raycasting code that’s written in cg into Cuda.

(I know Cg already takes care of GPU parallelism (right?), but this is solely for learning purpose

[or perhaps since the cg contains non-trivial computation, Cuda could actually enhance performance?])

Anyway, the original cg file does texture fetch on three textures, which can be easily implemented in CUDA.

So, I’m trying to bind three 2D textures to Cuda arrays.

Those three textures have the same width and height and same float4 type.

I followed all the steps of cudaMallocArray->cudaMemcpyToArray->cudaBindTextureToArray.

It works for one texture, but the other two textures give access violation reading location in

cudaMemcpyToArray(back_array, 0, 0, back_img, size, cudaMemcpyHostToDevice);

I rearranged orders but it still fails those two particular textures.

Before I pour my code in, can anyone figure out the reason for cudaMemcpyToArray failing on certain texture?

Beforehand, is it possible to bind three textures to three different arrays? Is there any precaution to which I did not pay attention?

Thank you.

Eric Lee.