Writing to a 3D cudaArray


I’m allocing a 3d cudaArray which then may be bound to a 3d texture. After allocing and binding I’d like to fill this array with, but I’d like to fill each element in this 3d array individually.

Is there a more elegant way to set just one element in the array than using cudaMemcpy3D and in the case there isn’t, how do i set up the cudaMemcpy3DParms struct to copy just one float properly (i utterly failed in doing so).

One more info: cudaMemcpy3D is called inside a device kernel to set the result of the kernel to this global array.

Thanks in advance and best regards,

You can’t do that. cudaArrays are a opaque types - they are intended only to be used by the texturing hardware, and the only way to get data into them is by copying values from a block equivalently sized linear memory.

You can’t do that either. You should set values in a linear memory array first, then use cudaMemcpy3D to copy the contents of that whole array into the cudaArray. There is no random write access in cudaArrays, only random read access via the texture read functions.

cudaMemcpy3D is a host API function, it can’t be called from inside device kernels. All of the operations on cudaArrays (other than actual texture reads) must be done in host code.