How to operate on video memory with GPU process?

There is another process on the PC that is displaying some graphics on a monitor. I want to grab a part of the video display [that is, a part of the video memory] and copy it elsewhere on the GPU global memory and operate on it and then copy it back to video memory for display. How do I find the video memory which I presume is within the gpu global memory and then how do I copy it?

The only way you’ll get anything like this into CUDA, without making a trip to the host and back, is via a CUDA/graphics interop API. That is not a complete recipe, just a necessary component (for direct transfer). The CUDA/graphics interop APIs are documented with relevant sample codes. Apart from this, it’s not possible for CUDA to copy memory of any other type, that is not owned/allocated by CUDA.

Is video memory part of global memory or is it a separate memory on the GT 1030 board i use? where in the nvidia docs does it cover video memory layout and access ?


CUDA’s global memory and the buffers used by OpenGL/DirectX are all part of the GDDR5 memory on the board. Basically these are different logical views / mappings of the physical memory. For the graphics view of this memory you would want to consult DirectX or OpenGL documentation. I seem to recall APIs in OpenGL to read the front and back buffers, but it’s been a very long time and my memory is hazy.

As txbob indicated, you would want to take a look at CUDA’s graphics inter-op documentation and examples. Note that the inter-op path may not necessarily be blazingly fast. An alternative may be the processing of the data on the graphics side by use of compute shaders which are a feature of both OpenGL and DirectX, if I recall correctly.

However, no matter which path you chose, I don’t think you will be able to read the memory belonging to a different process, something your questions seems to imply you would like to do. If you could do that, that would be a giant security hole. In general, each OS process owns its own resources (such as memory), and these resources are for the exclusive use of that process.