如何知道 Python 当前正在使用哪个 GPU 设备? [英] How to know which GPU device is currently being used in Python?

查看:93
本文介绍了如何知道 Python 当前正在使用哪个 GPU 设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 docker 中有两个 NVIDIA 设备.这是两个模型同时运行时的 GPU 使用信息.

I have two NVIDIA devices in my docker. Here is the GPU usage information when two models are running at the same time.

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
+-----------------------------------------------------------------------------+
Mon May 31 10:51:54 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 418.43       Driver Version: 418.43       CUDA Version: 10.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 108...  Off  | 00000000:03:00.0 Off |                  N/A |
| 37%   64C    P2    81W / 250W |  10909MiB / 11178MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   1  GeForce GTX 108...  Off  | 00000000:04:00.0 Off |                  N/A |
| 28%   50C    P8     9W / 250W |    147MiB / 11178MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
+-----------------------------------------------------------------------------+

很明显两个模型都在使用设备0.我有两个问题:

It is obviously two models are using device 0. Here I have two questions:

  1. 我如何知道使用的是哪个设备?
  2. 如果一个模型使用设备0,我们是否可以自动让另一个模型使用设备1?
  1. How can I know which device is used?
  2. If one model uses device 0, can we automatically let another model uses device 1?

推荐答案

我想说的是 Python 本身并没有使用 GPU,而是使用了像 Torch 这样的框架......你在这里使用的是机器学习框架吗?

I would say Python itself is not using a GPU per se, but rather a framework like Torch... are you using a machine learning framework here?

这篇关于如何知道 Python 当前正在使用哪个 GPU 设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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