A naive tool for observing gpu status and auto set visible gpu in python code.
Go to file
2020-11-02 19:25:00 +08:00
gpuutil initial commit 2020-11-02 19:02:52 +08:00
.gitignore Initial commit 2020-11-02 18:54:03 +08:00
README.md update 2020-11-02 19:25:00 +08:00
setup.py initial commit 2020-11-02 19:02:52 +08:00

gpuutil

A naive tool for observing gpu status and auto set visible gpu in python code.

How to use

  1. install the package.
pip install https://git.zmy.pub/zmyme/gpuutil/archive/v0.0.1.tar.gz
  1. for observing gpu status, just input
python -m gpuutil <options>

where options can either be "brief" or "detail", and you will get something like

================== GPU INFO ==================
[0] Utils: 94 % | Mem: 10166/11019 MiB(853MiB free)  user1(10163MiB,pid=14018)
[1] Utils: 89 % | Mem: 6690/11019 MiB(4329MiB free)  user2(6687MiB,pid=19855)
[2] Utils: 0 % | Mem: 1/11019 MiB(11018MiB free)
[3] Utils: 0 % | Mem: 1/11019 MiB(11018MiB free)
================ PROCESS INFO ================
[14018] user1(10163 MiB) python train.py --some -args
[19855] user2(6687 MiB) python train.py --some --different --args
  1. To auto set visible gpu in your python code, just use the following python code.
from gpuutil import auto_set
auto_set(1)

the auto_setfunction is defined as follows:

# num: the number of the gpu you want to use.
# allow_nonfree: whether use non-empty gpu when there is no enough of them.
# ask: if is set to true, the script will ask for a confirmation when using non empty gpu. if false, it will use the non empty gpu directly.
# blacklist: a list of int, the gpu in this list will not be used unless you mannuly choose them.
# show: if set to true, it will show which gpu is currently using.
def auto_set(num, allow_nonfree=True, ask=True, blacklist=[], show=True):
	# some code here.

ps:

you can get more detailed via accessing gpuutil.GPUStat class, for more information, just look the code.