Skip to content

Instantly share code, notes, and snippets.

@jungin500
Last active September 13, 2022 11:22
Show Gist options
  • Save jungin500/cb9ea1bc0150c9da443e963a1ebba00c to your computer and use it in GitHub Desktop.
Save jungin500/cb9ea1bc0150c9da443e963a1ebba00c to your computer and use it in GitHub Desktop.
#!/bin/bash
MB_SCALE=1024
GPU_NAME=$(nvidia-smi --query-gpu=name --format=csv,noheader | head -n 1)
GPU_COUNT=$(nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)
VRAM_MB=$(nvidia-smi -q -i 0 | grep Total | head -n 1 | awk '{ print $3 }')
VRAM_GB=$((VRAM_MB / MB_SCALE))
if [ -z "$VRAM_MB" ]; then
>&2 echo "Graphics cards not detected by nvidia-smi!"
exit 1
fi
>&2 echo "GPU $GPU_NAME * $GPU_COUNT (VRAM ${VRAM_GB}GiB) detected"
echo $VRAM_GB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment