简体   繁体   English

在 Python 中使用 CUDA 进行 GPU 控制

[英]GPU control using CUDA in Python

I want to use Tensorflow-gpu in Python.我想在 Python 中使用 Tensorflow-gpu。 My PC has two GPUs.我的电脑有两个 GPU。 (GPU-A and GPU-B) (GPU-A 和 GPU-B)

I want to specify the GPU to be used.我想指定要使用的 GPU。

So when I run the program, I used the following command:所以当我运行程序时,我使用了以下命令:

CUDA_VISIBLE_DEVICES = 1

The GPU to be used can be specified according to the value.可以根据该值指定要使用的GPU。 Specifically, it was assigned as follows.具体而言,分配如下。

CUDA_VISIBLE_DEVICES = 0

I was able to use GPU-B.我能够使用 GPU-B。

On the other hand另一方面

CUDA_VISIBLE_DEVICES = 1

At that time, I was able to use GPU-A.那时,我能够使用GPU-A。

However, I cannot know in advance whether GPU-A or GPU-B corresponds to the value 0 or 1. I found a statement that "this index is assigned in descending order of computing power".但是,我无法提前知道GPU-A或GPU-B对应的值是0还是1。我发现了“这个索引是按计算能力降序分配”的说法。 However, GPU-A can calculate faster than GPU-B.但是,GPU-A 的计算速度比 GPU-B 快。 I think that "indexes are assigned in order of the revision number (Compute Capability), not the calculation speed".我认为“索引是按照修订号(计算能力)而不是计算速度的顺序分配的”。 In fact, GPU-B has higher compute capability than GPU-A.实际上,GPU-B 的计算能力比 GPU-A 更高。

If the hypothesis is correct, I have another question.如果假设是正确的,我还有一个问题。 If multiple GPUs with the same Compute Capability are used, how will they be assigned?如果使用多个具有相同计算能力的 GPU,它们将如何分配?

You can try running nvidia-smi in your terminal.您可以尝试在终端中运行nvidia-smi The output you get shows you GPU ordering.您获得的输出显示了 GPU 排序。 For example:例如:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 410.104      Driver Version: 410.104      CUDA Version: 10.0     |
|-------------------------------+----------------------+----------------------+
| 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:01:00.0 Off |                  N/A |
|  0%   52C    P8    21W / 250W |      2MiB / 11176MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   1  GeForce GT 1030     Off  | 00000000:02:00.0  On |                  N/A |
| 41%   54C    P0    N/A /  30W |   1055MiB /  2001MiB |      6%      Default |
+-------------------------------+----------------------+----------------------+

Here, I have 2 GPUs:在这里,我有 2 个 GPU:

  1. GPU 0: GTX 1080Ti GPU 0:GTX 1080Ti
  2. GPU 1: GT 1030 GPU 1:GT 1030

You can then further use indexes in TensorFlow .然后,您可以进一步在TensorFlow使用索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM