Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gpu-reserve

Soft GPU reservation for a shared machine: a tiny process holds a CUDA context so nvidia-smi and nvtop show a name like DONT_USE_GPU0 owned by your host user.

This is a social signal, not a lock. Other users can still start CUDA jobs on the same card.

Image and container names are prefixed with your login ($(id -un)):

  • image: $USER/gpu-reserve:local
  • container: $USER.gpu-reserve-0

Requirements

  • Docker with the NVIDIA Container Toolkit
  • Host GPU access as a normal user (no sudo)

The marker runs as --user $(id -u):$(id -g). --restart unless-stopped keeps it alive after SSH disconnect and Docker daemon restart.

Usage

./run.sh 0          # reserve GPU 0
./run.sh 0 1        # several GPUs
./run.sh status
./run.sh stop 0
./run.sh stop       # all of your markers
./run.sh build      # rebuild the image

Check:

nvidia-smi
nvtop

You should see DONT_USE_GPU0 (or …GPU1, …) under your username. Memory is typically a few hundred MiB because of the CUDA context, not just the 1 MiB allocation.

nvidia-smi showing DONT_USE_GPU0

nvtop showing DONT_USE_GPU0

How it works

nvidia-smi / nvtop list only processes with an open CUDA context. The displayed name comes from /proc/<pid>/cmdline (argv[0]), not from a free-form string. Kernel comm is also limited to 15 characters.

The C binary (reserve_gpu.c) calls cudaMalloc and sleeps. entrypoint.sh copies it to a PATH directory named DONT_USE_GPU<N> and execs that name with no extra arguments, so the process list shows exactly that. Ubuntu's /bin/sh is dash and does not support exec -a.

--pid=host is required so the host's nvidia-smi can resolve the process name from /proc. The container can see host PIDs.

reserve_gpu.py is a Python fallback kept in the tree. The image does not use it.

Environment

Variable Default Meaning
RESERVE_COMM DONT_USE_GPU<N> Process name, max 15 characters
RESERVE_BYTES 1048576 Device allocation in bytes
RESERVE_NICK $(id -un) Prefix for image and container names
RESERVE_IMAGE $nick/gpu-reserve:local Image tag
RESERVE_COMM=GPU0_ASK_ME ./run.sh 0

Root shell in the same container (the marker stays on your UID):

docker exec -u 0 -it "$USER.gpu-reserve-0" bash

About

Soft GPU reservation: a tiny CUDA process visible in nvidia-smi and nvtop

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages