update texture on device


I’m new to the CUDA SDK and to the GPU programming in general. I’m a 3rd year CS student and I’m trying to implement a Anisotropic Diffusion algorithm with CUDA, based on the sobel filter source code which is provided with CUDA SDK.

While in sobel filter I don’t need to update the texture after each iteration, in my implementation I’m required to do so (because the anistropic diffusion algorithm I implement is an increamental algorithm, so I must update the texture to the result of the previous iteration). To be more precise, the algorithm I wrote changes the “data” variable (pixels of the image), and by copying the modified “data” to “array” (which is a cudaArray on the device) I managed to update the texture (the texture is bound to “array”).

Now, this is my modified display function (which is activated by GlutMainLoop):

The only mofication I made to the original Display function is adding the bolded line.

The kernel’s “SobelFilter” function is also modified to implement the Anisotropic Diffusion algorithm.

This code works as expected in emulation mode. However, in non emulation mode I get an exception after the bolded line (means the copy of the updated info in “data” to the “array” on the device doesn’t take place).

The exception is:

I’m using VC8 with 8800GTX. I tried to use cudaMallocArray again, and to free the texture and the array, I also added __synchthreads to the _global function in the kernel. None of those helped.

I’m stuck… :(

If anyone can help me I will be gratefull. :)



don’t you want cudaMemcpyDeviceToDevice ? I’ve never done OpenGL-CUDA integration before so I could be wrong, but isn’t data a pointer to device memory?

“data” is a host memory pointer, because it is the data that is assigned to the pixel buffer that is displayed on the screen. And it contains the pixel value as loaded from the file in the beginning of the program. This is the only part I use OpenGL.

You were right, it works!

Thanks alot!