How to write the result to 2D texture?

Hi, I want to do the following flow under the CUDA:

  1. Read the element(pixel) from 2D texture(A)
  2. Calculate for each element
  3. Write the reseult to 2D texture as the element of 2D texture ( B )
  4. goto 2 if not finish for all elements for texture A

However I can’t find how to directly write data to 2D texture on CUDA
while we find OpenGL have render-to-texture function.

Now I have no alternative but to do the following way:

  1. Read the element from 2D texture(A)
  2. Calculate for each element
  3. Write the result per element to the element of normal array B on Global memory
  4. goto 2 if not finish for all elements for texture A
  5. Copy normal array B on Global memory to CUDA array ( cudaMemcpyToArray() )
  6. Bind the texture B to CUDA Array ( cudaBindTextureToArray() )

Is 2D texture read-only? :(
My way is the fastest if 2D texture is read-only? :))

You’re correct, unfortunately it’s not possible to write directly to 2D textures in CUDA currently. Device to device memcpys are very fast, however (70Gb/sec).

If you don’t need 2D access, it is possible to bind 1D textures to global memory directly and access them using tex1Dfetch(). The particles sample in the SDK does this.

Well, according to this post that 70Gb/sec is not true for cudaMemcpyToArray() which you need to get 2D access

Thank you, Simon and DenisR.
Let me summrize this article.

Question : How to write the result to 2D texture?
Answer : We cannot write the result to 2D texture.
Note : cudaMemcpyToArray() function is slow in 2D access.

I would say, to have 2D texture access you need to use cudaMemcpyToArray(), which can be quite slow compared to a normal Device2Device copy (3 vs 70 Gb/s). I believe there is now some explanation for this difference in speed in the thread I pointed to.