Instructions for locking GPUs on guppy machines

It is important to lock a GPU before using it. This makes sure that a GPU is used by only one user at a time. Scripts have been created for doing this.

Create sym links

Since locking/unlocking is something that you will frequently do, it useful to symlink these scripts.
ln -s ~nitish/bin/gpu_lock.py ~/
ln -s ~nitish/bin/obtain_gpu_lock_id.m ~/
ln -s ~nitish/bin/run_on_me_or_pid_quit ~/

Looking at GPU usage

To see the current status of the GPUs -
python ~/gpu_lock.py

Locking in a python program

Make sure gpu_lock.py is on your PYTHONPATH.

import gpu_lock
board = gpu_lock.obtain_lock_id()

The lock is automatically freed when the process holding the lock dies. Or you can free it explicitly -
gpu_lock.free_lock(board)
This is the preferred way of locking GPUs for python programs. Sample code here

Locking in a MATLAB program

From within MATLAB -
id = obtain_gpu_lock_id();
The lock is automatically freed when you exit MATLAB. This is the preferred way of locking GPUs for MATLAB.

Locking in a shell script

board_id=$(python ~/gpu_lock.py --id)
This returns a board id that is locked for the user.
The lock is automatically freed when the process holding the lock dies.

Manual locking

This is the least preferred way of locking GPU boards because it relies on the user manually freeing up the board. All other methods automatically free the GPU when the program using it terminates or gets killed which ensures that there are no locked but unused GPUs. Use this method only if you really want to hog a GPU.
Lock a board
python ~/gpu_lock.py --id-to-hog
This returns a board id that is locked for the user.
You MUST free the board when you are done using it -
python ~/gpu_lock.py --free <board-id>
More instructions are here. Please send any questions to guppy-users@cs