KB 418621 - How to check GPU detection across compute nodes using bash script

KB 418621 - How to check GPU detection across compute nodes using bash script

1. Purpose

This script automates GPU detection validation across all compute nodes in a GPU cluster.

It verifies:

  • Nodes with missing GPUs
  • Nodes that are unreachable
  • Timestamp of execution
  • Summary report generation

This eliminates the need to manually SSH into each node and run nvidia-smi.


2. When to Use

Use this script when:

  • Performing routine GPU health checks
  • Validating cluster readiness before workload scheduling
  • Troubleshooting GPU-related issues
  • Verifying hardware after maintenance or reboot
  • Investigating driver failures


3. What This Script Exactly Collects

The script gathers the following information:

  • Total nodes checked
  • GPU count per node (configurable)
  • Nodes where:
    • GPUs are missing
    • NVIDIA-SMI fails
    • SSH connection fails
  • Date and time of execution
  • Timestamped log file

Requirements

  • Linux-based login node
  • Passwordless SSH access to compute nodes
  • nvidia-smi installed on compute nodes
  • Bash shell environment

Log files are stored under:

~/gpu_logs/

4. Script

🔧 Modify the variables at the top to match your environment.
Quote

#!/bin/bash

# =========================

# CONFIGURATION VARIABLES

# =========================

START=1                  # Starting node index

END=10                   # Ending node index

BASE_HOST="compute"      # Base hostname prefix (example: compute01, compute02)

EXPECTED_GPUS=8          # Expected GPUs per node

LOGDIR="$HOME/gpu_logs"

# =========================

mkdir -p "$LOGDIR"

LOGFILE="$LOGDIR/gpu_detection_$(date +%F_%H%M).log"

TMPFILE=$(mktemp)

{

  echo "=========================================="

  echo " GPU Detection Report"

  echo " Date: $(date +%F)"

  echo " Time: $(date +%T)"

  echo "=========================================="

  echo

} > "$LOGFILE"

MISSING_NODES=0

TOTAL_NODES=0

CMD="nvidia-smi -L"

for i in $(seq $START $END); do

    NODE_NAME=$(printf "%s%02d" "$BASE_HOST" "$i")

    ((TOTAL_NODES++))

    echo "===================== $NODE_NAME ====================="

    OUTPUT=$(ssh -o ConnectTimeout=5 "$NODE_NAME" "$CMD" 2>&1)

    SSH_STATUS=$?

    if [ $SSH_STATUS -eq 255 ]; then

        echo " Node Unreachable: $NODE_NAME"

        printf "%-15s | %-20s\n" "$NODE_NAME" "Unreachable" >> "$TMPFILE"

        ((MISSING_NODES++))

        echo

        continue

    fi

    if [[ -z "$OUTPUT" || "$OUTPUT" == *"NVIDIA-SMI has failed"* ]]; then

        echo "⚠️  NVIDIA-SMI failed on $NODE_NAME — please check"

        printf "%-15s | %-20s\n" "$NODE_NAME" "NVIDIA-SMI Failed" >> "$TMPFILE"

        ((MISSING_NODES++))

        echo

        continue

    fi

    DETECTED_INDICES=$(echo "$OUTPUT" | grep -oP 'GPU \K[0-9]+')

    DETECTED_COUNT=$(echo "$DETECTED_INDICES" | wc -l)

    if [ "$DETECTED_COUNT" -lt "$EXPECTED_GPUS" ]; then

        echo "⚠️  GPU(s) missing on $NODE_NAME — please check"

        printf "%-15s | %-20s\n" "$NODE_NAME" "GPU(s) Missing" >> "$TMPFILE"

        ((MISSING_NODES++))

    else

        echo " All $EXPECTED_GPUS GPUs detected on $NODE_NAME"

    fi

    echo

done

{

  echo "Nodes Checked: $TOTAL_NODES"

  echo "Nodes with Issues: $MISSING_NODES"

  echo

  echo "---------------------------------------------"

  echo "Node Name       | Status"

  echo "---------------------------------------------"

  cat "$TMPFILE"

  echo "---------------------------------------------"

  echo

  if [ "$MISSING_NODES" -eq 0 ]; then

      echo " All nodes have all $EXPECTED_GPUS GPUs detected."

  else

      echo "⚠️  Some nodes require attention."

  fi

  echo

  echo "================================================="

  echo "Log generated on: $(date)"

  echo "================================================="

} >> "$LOGFILE"

rm -f "$TMPFILE"

echo

echo "================================================="

echo "Summary:"

echo "  Nodes with issues: $MISSING_NODES"

echo "Log saved at: $LOGFILE"

echo "================================================="


5. Procedure

Step 1 – Create Script

mkdir -p ~/gpu_logs
nano ~/gpu_logs/gpu_missing_c​​​​​heck.sh

Step 2 – Make Executable

chmod +x ~/gpu_logs/gpu_missing_check.sh

Step 3 – Execute

~/gpu_logs/gpu_missing_check.sh


6. Output

Console Output Example

===================== compute01 =====================

All 8 GPUs detected on compute01

===================== compute06 =====================

⚠️  GPU(s) missing on compute06 — please check

Log File Location

Each run generates:

~/gpu_logs/gpu_detection_YYYY-MM-DD_HHMM.log

Sample Log Summary

Nodes Checked: 10

Nodes with Issues: 2

 

Node Name       | Status

---------------------------------------------

compute06       | GPU(s) Missing

compute08       | Unreachable

---------------------------------------------

7. Scope

Run on:

  • Login or management node
  • Any Linux-based GPU cluster
  • Environments with:
    • Passwordless SSH enabled
    • NVIDIA drivers installed
    • nvidia-smi available