Giter VIP home page Giter VIP logo

gpu_mon's Introduction

gpu_mon

Python script which monitors gpu access and manages external programs when GPU is idle

Blog post on medium.com

How

Every N seconds it checks /dev/nvidiaX device file for other processes accessing them (using fuser tool). According to this, it treats gpu card as idle or busy. If GPU becomes idle, gpu_mon starts external program, which will be stopped when device file will be accessed by other process.

Additionally, it can monitor PTY sessions to check that there are active users logged in and stop it's processes to avoid influence with somebody's work.

Why

  1. Monitoring and reporting of gpu usage
  2. Mining on idle hardware.

Requirements and limitations

Written on python3. Developed and tested under linux (ubuntu and debian) with NVidia cards. Don't have external libraries requirements except standard library.

To see all processes from all users, script need either run as root or fuser tool need to have suid bit.

Running

  1. create configuration file in ~/.config/gpu_mon.conf from provided template in conf dir
  2. run ./gpu_mon.py

Configuration

Basic configuration file looks like this and mostly self-explaining:

[defaults]
; how frequently perform GPU and tty checks
interval_seconds=10

; configuration of GPUs to monitor for external program access. It could be several such sections with 'gpu-' prefix
[gpu-all]
; list of comma-separated gpu indices or ALL to handle all available gpus
gpus=ALL
; comma-separated list of programs which can access gpu and should be ignored
ignore_programs=nvidia-smi

; program which will be started on gpu during idle time
[process-all]
dir=/tmp
cmd=miner-run
; list of gpu indices or ALL to handle all available gpus
gpus=ALL
; log for processes. If not specified, show on console, if specified to file, data will be appended
log=/dev/null

; configuration of tty monitoring if enabled and user is active and not in whitelist, all processes will be stopped
[tty]
enabled=True
whitelist=user1,user2
; how long user should be inactive in tty to be ignored by checker
idle_seconds=300

Above configuration will check all /dev/nvidiaN device files for open every 10 seconds and if nobody uses them (nvidia-smi command is ignored), start command miner-run, which should occupy all GPUs. If some program (like TF or pytorch) will open any of GPUs, miner will be terminated.

It's possible to fine-tune individual GPU access, which allows you to preempt miners or individual GPUs. In this example, we define per-gpu miner process which gets started with proper CUDA_VISIBLE_DEVICE variable set:

[defaults]
; how frequently perform GPU and tty checks
interval_seconds=10

; configuration of GPUs to monitor for external program access. It could be several such sections with 'gpu-' prefix
[gpu-all]
; list of comma-separated gpu indices or ALL to handle all available gpus
gpus=ALL
; comma-separated list of programs which can access gpu and should be ignored
ignore_programs=nvidia-smi

; program which will be started on gpu during idle time
[process-0]
dir=/tmp
cmd=miner-run
; list of gpu indices or ALL to handle all available gpus
gpus=0
; log for processes. If not specified, show on console, if specified to file, data will be appended
log=/dev/null

; program which will be started on gpu during idle time
[process-1]
dir=/tmp
cmd=miner-run  
; list of gpu indices or ALL to handle all available gpus
gpus=1
; log for processes. If not specified, show on console, if specified to file, data will be appended
log=/dev/null

; configuration of tty monitoring if enabled and user is active and not in whitelist, all processes will be stopped
[tty]
enabled=True
whitelist=user1,user2
; how long user should be inactive in tty to be ignored by checker
idle_seconds=300

Donations

If you find this useful and want to support developer, please consider donation.

  • BTC: 1FvhCby4UNtHmm2DFzzFRvfDL64uLSt4CN
  • BCC: 18cpNK3LmH7mbYkvUyDo6TSji4zGraCsu
  • ZEC: t1WMErz3JZZwkK1NLVadoi9ydgFHZhPHrWo
  • KMD: R9uk6UARL1vbyoGuP8NQNf8JvTxyRA1Xt1
  • Paypal: https://www.paypal.me/shmuma

gpu_mon's People

Contributors

shmuma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gpu_mon's Issues

INFO ProcessTracker Process for GPU 0 is terminated

Hi,

I use https://github.com/tpruvot/ccminer to mine.
If I set config:

[process-all]  
dir=/home
cmd=/home/ccminer xxxxxx
gpus=all
log=/dev/null

all work well.

But if I want to mine on certain GPU like

[process-0]  
dir=/home
cmd=/home/ccminer xxxxxx -d 0
gpus=0
log=/dev/null

I will get INFO ProcessTracker Process for GPU 0 is terminated, where the command -d is the ID
of GPU(default all).

Do you know what the matter is?

Thanks.

TypeError: argument of type 'NoneType' is not iterable

Hello Shmuma, any idea how i can resolve this error :

Traceback (most recent call last):
File "./python", line 37, in
proc_tracker.check(gpus, processes, active_users)
File "/home/mysystem/.config/python/gpu_mon/proc.py", line 128, in check
proc_conf = self.conf.process_config(gpu_id)
File "/home/mysystem/.config/python/gpu_mon/config.py", line 124, in process_config
if gpu_id in c.gpu_indices:
TypeError: argument of type 'NoneType' is not iterable

? Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.