Home > Linux > Main text

Run jobs on GPU server


Tag: linux


查看GPU使用情况

使用命令nvidia-smi:

➜  ~ nvidia-smi
Tue May 14 09:47:51 2019
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 375.66                 Driver Version: 375.66                    |
|-------------------------------+----------------------+----------------------+
| 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 1080    Off  | 0000:02:00.0     Off |                  N/A |
| 27%   39C    P8    10W / 180W |      0MiB /  8113MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   1  GeForce GTX 1080    Off  | 0000:03:00.0     Off |                  N/A |
| 40%   60C    P2    41W / 180W |   7789MiB /  8114MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   2  GeForce GTX 1080    Off  | 0000:82:00.0     Off |                  N/A |
| 28%   42C    P8    10W / 180W |      0MiB /  8114MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   3  GeForce GTX 1080    Off  | 0000:83:00.0     Off |                  N/A |
| 30%   45C    P8    11W / 180W |      0MiB /  8114MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|    1      9091    C   python                                        7787MiB |
+-----------------------------------------------------------------------------+

指定设备运行

GPU是动态创建的,默认不指定设备时,会占用所有的设备,但是可能需求并没有这么多。通常的做法是指定端口,有两种方式:

1、命令行指定:添加CUDA_VISIBLE_DEVICES=设备号。注意:VISIBLE不要写错了,DEVICES一定记得加S,否则会指定失败。

CUDA_VISABLE_DEVICES=1 python script.py

2、脚本中指定:对于python脚本,可在脚本中指定环境参数:

if GPU_device: 
	os.environ['CUDA_VISIBLE_DEVICES'] = GPU_device


If you link this blog, please refer to this page, thanks!
Post link:https://tsinghua-gongjing.github.io/posts/GPU.html

Previous: 稀疏编码
Next: LSTM