Accessing a memory block created in another program.

Hello,

I have one program (OpenCL) where I’m processing an image and I want to access the buffer I have uploaded to the GPU from another program.
The question is it possible if I have an address on a GPU and if yes, how do I do that?

Thank,
Nikolay.

The answer is a clear no, and it has to do with security and per-process isolation.

Each process gets its own CUDA context with its own memory space. Even if the (virtual) memory space address in two CUDA contexts is identical, it will map to different physical memory on the GPU.

Resources can be shared, but only among threads (not processes) that operate within the same CUDA context.

There still might be data leakage from one process to another when one process has allocated memory and filled it with data and then freed it without clearing the memory first. Then another process might get the same physical memory assigned in a new allocation - and there could be (possibly sensitive) information from another process in it.

From the top of my head, if you are working on Linux, you can share stuff among your programs by using the OS shared memory (read some IPC and mmap() documentation, just in case you are unfamiliar with it).

Keep in mind this is host shared memory and the spaces have their own IDs. But this would involve bringing stuff back and forth between host and device. At least you get some sort of shared space between different programs.