两个进程可以共享相同的GPU内存吗? (CUDA) [英] can two process shared same GPU memory? (CUDA)

查看:897
本文介绍了两个进程可以共享相同的GPU内存吗? (CUDA)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CPU世界中,可以通过内存映射来做到这一点.可以为GPU做类似的事情吗?

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

如果两个进程可以共享相同的CUDA上下文,我认为这将是微不足道的-只需传递GPU内存指针即可.是否可以在两个进程之间共享相同的CUDA上下文?

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?

推荐答案

CUDA MPS有效地允许来自2个或更多进程的CUDA活动在GPU上共享相同的上下文.但是,这不能满足您的要求:

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:

两个进程可以共享相同的GPU内存吗?

can two processes share the same GPU memory?

一种实现此目标的方法是通过CUDA IPC(进程间通信)API.

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

这将允许您在多个进程之间共享分配的设备存储区(即,通过cudaMalloc分配的存储区). 此答案包含其他资源,以了解CUDA IPC.

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.

但是,根据我的测试,这无法在多个进程之间共享主机固定的内存区域(例如,通过cudaHostAlloc分配的区域).可以使用可用于您特定操作系统的普通IPC机制来共享内存区域本身,但是不能使其在2个或更多进程中显示为固定"内存(根据我的测试).

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).

这篇关于两个进程可以共享相同的GPU内存吗? (CUDA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆