运行 一个 GPU 上的多个 CUDA 应用程序

Running more than one CUDA applications on one GPU

CUDA文档没有具体说明多少个CUDA进程可以共享一个GPU。例如,如果我在系统中只安装了一张 GPU 卡的情况下由同一用户启动多个 CUDA 程序,会有什么影响?会保证执行的正确性吗?这种情况下GPU是如何调度任务的?

来自独立主机进程的

CUDA activity 通常会创建独立的 CUDA contexts,每个进程一个。因此,从不同主机进程启动的 CUDA activity 将在同一设备上的不同 CUDA 上下文中进行。

CUDA activity 在单独的上下文中将被序列化。 GPU 将从一个进程执行 activity,当 activity 空闲时,它可以上下文切换到另一个上下文以完成从另一个进程启动的 CUDA activity。 未指定详细的上下文调度行为。 (运行 单个 GPU 上的多个上下文通常也不能违反基本 GPU 限制,例如设备分配的内存可用性。)请注意,上下文间 switching/scheduling 行为未指定,并且也可能因机器而异设置。随意观察或微基准测试可能表明来自较新设备上的单独进程的内核可以 运行 同时(在 MPS 之外),但这是不正确的。 ,但这并没有改变这样一个事实,即在任何给定的时刻,只有一个上下文的代码可以 运行。

这种情况下的 "exception"(从独立主机进程序列化 GPU activity)将是 CUDA 多进程服务器。简而言之,MPS acts as a "funnel" to collect CUDA activity emanating from several host processes, and run that activity as if it emanated from a single host process. The principal benefit is to avoid the serialization of kernels which might otherwise be able to run concurrently。规范的用例是启动多个 MPI 等级,这些等级都打算使用单个 GPU 资源。

请注意,以上描述适用于 "Default" compute mode. GPUs in "Exclusive Process" or "Exclusive Thread" compute modes will reject any attempts to create more than one process/context on a single device. In one of these modes, attempts by other processes to use a device already in use will result in a CUDA API reported failure. The compute mode is modifiable in some cases using the nvidia-smi utility.

中的 GPU

我是这个话题的新手。但是我发现可以只在一个 GPU 上模拟多个 GPU。 "Developing for multiple GPUs will allow a model to scale with the additional resources. If developing on a system with a single GPU, we can simulate multiple GPUs with virtual devices. This enables easy testing of multi-GPU setups without requiring additional resources."

来源:https://www.tensorflow.org/guide/gpu#allowing_gpu_memory_growth

也许使用这种技术,我们可以 运行 这些虚拟 GPU 之一上的每个模型(至少用于推理)。