Viewing and setting of the deep learning GPU operating environment

Use nvidia-smi to query GPU information

nvidia-smi is a command line tool that can help you manage and operate the GPU device, and allows you to query and change the device status.

Enter cd C:\Program Files\NVIDIA Corporation\NVSMI in the windows command prompt, and then enter nvidia-smi

nvidia-smi has many uses. For example, the following command can list the available GPUs on the computer:

$ nvidia-smi -L
GPU 0: GeForce 940MX (UUID: GPU-1d8cce6d-84a3-fd64-e2e5-76b2489b91fd)

If there are multiple GPUs available on the computer, such as GPU 0~5, we can use the environment variable CUDA_VISIBLE_DEVICES to solve this problem at this time. 
For example:
CUDA_VISIBLE_DEVICES=1 Only the GPU numbered 1 is visible to the program, in the code gpu[0] refers to
GPU1 CUDA_VISIBLE_DEVICES=1,3,5 Only the GPU numbered 1,3,5 is visible to the program , In the code gpu[0], gpu[1], gpu[2] correspond to GPU1,3,5 respectively
CUDA_VISIBLE_DEVICES=2,0,3 Only GPUs numbered 2,0,3 are visible to the program, in the code Medium gpu[0], gpu[1], gpu[2] correspond to GPU2, 0, 3 respectively

You can set permanent environment variables or temporary environment variables.
To set permanent environment variables, you need to go to My Computer-Properties-Advanced System Settings-Environment Variables, and add variables with the same name and the same value;


Set the temporary environment variables when python is running. You can perform the following operations before initializing the code that needs to call the GPU:
import os
os.environ["CUDA_VISIBLE_DEVICES"]='0'

Execute the following code to view the temporary environment variables:
os.environ.get('CUDA_VISIBLE_DEVICES')

Guess you like

Origin blog.csdn.net/yocencyy/article/details/105012660