Skip to content

Instantly share code, notes, and snippets.

@ai2ys
Last active April 29, 2022 08:58
Show Gist options
  • Save ai2ys/b3fde4b2777a05fb9d8e13aee9ee6783 to your computer and use it in GitHub Desktop.
Save ai2ys/b3fde4b2777a05fb9d8e13aee9ee6783 to your computer and use it in GitHub Desktop.
Examples for nvidia-smi

Using nvidia-smi

Commands on local system

Running nvidia-smi every n seconds

nvidia-smi -l <n seconds>

Retrieving GPU index and name

nvidia-smi --query-gpu=index,gpu_name --format=csv
# output will look like:
# ----------------------
# index, name
# 0, NVIDIA <name of GPU #0>
# 1, NVIDIA <name of GPU #1>
# ...

Using nvidia-smi with Docker containers supporting CUDA

# using all GPUs
docker run --rm --gpus all nvidia/cuda:11.0-base nvidia-smi

# using a specified number of GPUs, here 2
docker run --rm --gpus 2 nvidia/cuda:11.0-base nvidia-smi

# using the device index, here index=1
docker run --rm --gpus "device=1" nvidia/cuda:11.0-base nvidia-smi
# using the device index, here passing multiple device indices index=1,2
docker run --rm --gpus "device=1,2" nvidia/cuda:11.0-base nvidia-smi

List GPU UUIDs

nvidia-smi --list-gpus

Control you GPUs

https://www.microway.com/hpc-tech-tips/nvidia-smi_control-your-gpus/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment