Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can two process shared same GPU memory? (CUDA)

In CPU world one can do it via memory map. Can similar things done for GPU?

If two process can share a same CUDA context, I think it will be trivial - just pass GPU memory pointer around. Is it possible to share same CUDA context between two processes?

Another possibility I could think of is to map device memory to a memory mapped host memory. Since it's memory mapped, it can be shared between two processes. Does this make sense / possible, and are there any overhead?

like image 493
Helin Wang Avatar asked Feb 03 '17 20:02

Helin Wang


People also ask

Can CUDA use shared GPU memory?

Shared memory is a powerful feature for writing well optimized CUDA code. Access to shared memory is much faster than global memory access because it is located on chip. Because shared memory is shared by threads in a thread block, it provides a mechanism for threads to cooperate.

Is GPU memory shared?

Your system will dedicate up to 50% of your physical RAM to shared GPU memory, regardless if you have an integrated or a dedicated GPU.

How is memory allocated in CUDA?

Memory management on a CUDA device is similar to how it is done in CPU programming. You need to allocate memory space on the host, transfer the data to the device using the built-in API, retrieve the data (transfer the data back to the host), and finally free the allocated memory.

Do games use shared GPU memory?

The OS will use it freely so you shouldn't worry about it technically being half of your RAM. If you have an integrated GPU, shared GPU memory is the maximum amount of memory your iGPU can use. Since integrated GPUs don't have dedicated GPU memory they have to use system RAM to run games and apps.


1 Answers

CUDA MPS effectively allows CUDA activity emanating from 2 or more processes to share the same context on the GPU. However this won't provide for what you are asking for:

can two processes share the same GPU memory?

One method to achieve this is via CUDA IPC (interprocess communication) API.

This will allow you to share an allocated device memory region (i.e. a memory region allocated via cudaMalloc) between multiple processes. This answer contains additional resources to learn about CUDA IPC.

However, according to my testing, this does not enable sharing of host pinned memory regions (e.g. a region allocated via cudaHostAlloc) between multiple processes. The memory region itself can be shared using ordinary IPC mechanisms available for your particular OS, but it cannot be made to appear as "pinned" memory in 2 or more processes (according to my testing).

like image 87
2 revs Avatar answered Sep 19 '22 13:09

2 revs