重置GPU显存 Reset GPU memory after CUDA errors

*爱你&永不变心* 提交于 2019-12-05 22:38:12
nvidia-smi --gpu-reset

Although it should be unecessary to do this in anything other than exceptional circumstances, the recommended way to do this on linux hosts is to unload the nvidia driver by doing

 
1
$ rmmod nvidia 

with suitable root privileges and then reloading it with

 
1
$ modprobe nvidia

If the machine is running X11, you will need to stop this manually beforehand, and restart it afterwards. The driver intialisation processes should eliminate any prior state on the device.

This answer has been assembled from comments and posted as a community wiki to get this question off the unanswered list for the CUDA tag


check what is using your GPU memory with

 
1
sudo fuser -v /dev/nvidia*

Your output will look something like this:

 
1
                     USER        PID  ACCESS COMMAND
2
/dev/nvidia0:        root       1256  F...m  Xorg
3
                     username   2057  F...m  compiz
4
                     username   2759  F...m  chrome
5
                     username   2777  F...m  chrome
6
                     username   20450 F...m  python
7
                     username   20699 F...m  python

Then kill the PID that you no longer need on htop or with

 
1
sudo kill -9 PID.

In the example above, Pycharm was eating a lot of memory so I killed 20450 and 20699.














标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!