# What does “export CUDA\_VISIBLE\_DEVICES=1” really do?

**URL:** <https://discuss.pytorch.org/t/what-does-export-cuda-visible-devices-1-really-do/90340>\
**Category:** Uncategorized\
**Created:** [July 24, 2020, 12:49am UTC](https://discuss.pytorch.org/t/what-does-export-cuda-visible-devices-1-really-do/90340 "2020-07-24T00:49:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![111357](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/1/74df32/32.png) [@111357](https://discuss.pytorch.org/u/111357)\
**Post date:** [July 24, 2020, 12:49am UTC](https://discuss.pytorch.org/t/what-does-export-cuda-visible-devices-1-really-do/90340/1 "2020-07-24T00:49:03Z")

</div>

In a multi-GPU computer(Ubuntu 16),  
I want to use `GPU1` and do the following setting in the shell:

```auto
$ export CUDA_VISIBLE_DEVICES=1
$ python

```

But, I got an error when I set the device of the tensor:

```auto
Python 3.8.3 (default, May 19 2020, 18:47:26) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> a = torch.Tensor(1).to("cuda:0")
>>> a = torch.Tensor(1).to("cuda:1")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: CUDA error: invalid device ordinal

```

Why I can’t specify the device of Tensor to `GPU1` by `to`.

---

<div class="post-metadata">

**Author:** ![111357](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/1/74df32/32.png) [@111357](https://discuss.pytorch.org/u/111357)\
**Post date:** [July 24, 2020, 12:50am UTC](https://discuss.pytorch.org/t/what-does-export-cuda-visible-devices-1-really-do/90340/2 "2020-07-24T00:50:59Z")

</div>

@ptrblck, Could you please give me some advice? 🤣

---

<div class="post-metadata">

**Author:** ![ebarsoum](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ebarsoum/32/5515_2.png) [@ebarsoum](https://discuss.pytorch.org/u/ebarsoum)\
**Post date:** [July 24, 2020, 1:29am UTC](https://discuss.pytorch.org/t/what-does-export-cuda-visible-devices-1-really-do/90340/3 "2020-07-24T01:29:10Z")

</div>

Setting CUDA\_VISIBLE\_DEVICES=1 mean your script will only see one GPU which is GPU1. However, inside your script it will be cuda:0 and not cuda:1. Because it only see one GPU and its index start at 0.

For example if you do: CUDA\_VISIBLE\_DEVICES=2,4,5, your script will see 3 GPUs with index 0, 1 and 2.

---

<div class="post-metadata">

**Author:** ![111357](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/1/74df32/32.png) [@111357](https://discuss.pytorch.org/u/111357)\
**Post date:** [July 24, 2020, 1:50am UTC](https://discuss.pytorch.org/t/what-does-export-cuda-visible-devices-1-really-do/90340/4 "2020-07-24T01:50:01Z")

</div>

Got it, thanks a lot!
