cuda array

I have a 3D image, which is represented by a 1D c++ array. Now I want to use cuda to process this image. Can I create a 1D cuda array and copy the 1D c++ array to cuda array and then bind the cuda array with texture and use texture fetch to access it?

sure, or you could use 3D textures if your dimensions are appropriate.

To 3D image which one is better? 1D or 3D texture?

If you are accessing the 3D image with some level of locality (for example, accessing neighbouring pixels for a 3D convolution), you’re better of using a 3D texture so that you make good use of the texture cache.

The cuda programming guide says that the texture is specific for 2D locality. It still works well for 3D image?

Well, you dont have 3D monitors… Your image is still 2D. And I dont believe JPEG or BMP formats have 3D information embedded in it. So, although a picture might have a 3D view… it really does not have any 3D information in it…

OR may b, its just my 3D ignorance… Appreciate an enlightenment.

I can save the 3D image into 1D, 2D or 3D array. I need to explicitly compute the address if using 1D, but 1D can save memory space. If using 3D the address is computed implicitly and maybe I can make use of the locality. I want to know to 3D image, which one is better?

Well, do you have 3D local data access or not? If you do, you will see a benefit from using 3D textures vs 1D or 2D as you will have fewer cache misses.

An example of a 3D local data access is where one thread reads all the 3D neighboring values as has been said already in this thread.
Explicity, this means that your thread reads
i,j,k
i+1,j,k
i,j+1,k
i,j,k+1
i-1,j,k