A quick access to nvidia gpu information
Project description
# gpuinfo
I implement some functions that can help users to obtain nvidia gpu information.
To use gpuinfo, you need to be able to run 'ps' and 'nvidia-smi' in your terminal.
# Install with pip
```
pip install gpuinfo
```
I only tested on linux system with python3.
https://pypi.org/project/gpuinfo/
# Usage
```python
from gpuinfo import GPUInfo
```
GPUInfo has the following functions:
check_empty()
check_empty()
return a list containing all GPU ids that no process is using currently.
get_info()
pid_list,percent,memory,gpu_used=get_info()
return a dict and three lists. pid_list has pids as keys and gpu ids as values, showing which gpu the process is using
get_user(pid)
get_user(pid)
Input a pid number , return its creator by linux command ps
gpu_usage()
gpu_usage()
return two lists. The first list contains usage percent of every GPU. The second list contains the memory used of every GPU. The information is obtained by command 'nvidia-smi'
# Example
```python
from gpuinfo import GPUInfo
available_device=GPUInfo.check_empty()
#available_device就是一个含有所有没有任务的gpu编号的列表
percent,memory=GPUInfo.gpu_usage()
#获得所有gpu的使用百分比和显存占用量
min_percent=percent.index(min([percent[i] for i in available_device]))
#未被使用的gpu里percent最小的
min_memory=memory.index(min([memory[i] for i in available_device]))
#未被使用的gpu里显存占用量最少的
#如果你使用pytorch
torch.cuda.set_device(min_percent) 或者(min_memory)
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
gpuinfo-1.0.0a2.tar.gz
(5.1 kB
view hashes)
Built Distribution
Close
Hashes for gpuinfo-1.0.0a2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93f84a13f4d91bb392b32a24e41db9c5bdf1c072d5ae1c694f7e74277e5532c3 |
|
MD5 | 993ed5c3f0db78f79031eff4f7070ec0 |
|
BLAKE2b-256 | 1016a541cf2da21d5f48e46d3ad42b678df0022d300500958b7bd2b53747c93a |