# GPU Device Ordering

**URL:** <https://discuss.pytorch.org/t/gpu-device-ordering/60785>\
**Category:** Uncategorized\
**Created:** [November 12, 2019, 8:25pm UTC](https://discuss.pytorch.org/t/gpu-device-ordering/60785 "2019-11-12T20:25:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Novak](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/novak/32/15362_2.png) [@Novak](https://discuss.pytorch.org/u/Novak)\
**Post date:** [November 12, 2019, 8:25pm UTC](https://discuss.pytorch.org/t/gpu-device-ordering/60785/1 "2019-11-12T20:25:21Z")

</div>

I have a system with a GTX 1070 and a Titan RTX installed in it.

Nvidia-smi yields:

> | 0 GeForce GTX 1070 Off | 00000000:03:00.0 Off | N/A |  
> | 1 TITAN RTX Off | 00000000:04:00.0 Off | N/A |

However,

> print(torch.cuda.get\_device\_name(“cuda:0”))  
> print(torch.cuda.get\_device\_name(“cuda:1”))

yields:

> TITAN RTX  
> GeForce GTX 1070

Clearly, the results are out of order with each other. This presents no real difficulty, since I can always identify them at least up to the card type directly, so this is mostly curiosity:

Is this typical/intended behavior? Are there intended guarantees (or no guarantees) for card order of nvidia-smi vs the internal ordering seen through PyTorch?

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [November 12, 2019, 9:09pm UTC](https://discuss.pytorch.org/t/gpu-device-ordering/60785/2 "2019-11-12T21:09:52Z")

</div>

`nvidia-smi` shows the devices by PCI order, while the CUDA driver and Runtime API should sort the devices based on their “performance”.  
To get the same order in your PyTorch script, you could try to set

```auto
export CUDA_DEVICE_ORDER=PCI_BUS_ID

```

before running your script.

---

<div class="post-metadata">

**Author:** ![Novak](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/novak/32/15362_2.png) [@Novak](https://discuss.pytorch.org/u/Novak)\
**Post date:** [November 12, 2019, 9:23pm UTC](https://discuss.pytorch.org/t/gpu-device-ordering/60785/3 "2019-11-12T21:23:41Z")

</div>

Yes, that looks like the “solution” to this not-quite-a-problem.  
Previously, all my systems were either homogeneous, or sorted in the correct order by luck.

Thanks!
