Files
DeepInfer/scripts/nvidia_arch.sh
T
shunyadandClaude Opus 5.5 7b4322294e fix(build): stop on GPU family detection errors instead of building for sm100
build.sh tested `[ "$(nvidia_arch.sh)" = sm120 ]`, which discards the
script's exit status, so a bad DEEPINFER_NVIDIA_ARCH only surfaced in
build_vendor.sh after the long pip install. nvidia_arch.sh also mapped every
GPU that is not 12.x (and hosts without nvidia-smi) to sm100 silently, so an
SM120 build container without nvidia-smi installed the SM100 dependency set.

- build.sh runs detection as its own assignment (set -e stops before pip) and
  exports the result so build_vendor.sh builds for the same family.
- DEEPINFER_NVIDIA_ARCH is case-insensitive.
- A detected GPU of another family (e.g. compute capability 9.0) is an error
  that points at DEEPINFER_NVIDIA_ARCH; no visible GPU still builds for sm100
  (GPU-less SM100 build hosts keep working) but warns on stderr.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 22:22:15 -08:00

50 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# Prints the NVIDIA GPU family to build for: sm100 or sm120.
# DEEPINFER_NVIDIA_ARCH overrides detection (case-insensitive); without it the first visible GPU decides (the first
# CUDA_VISIBLE_DEVICES entry when it is set). A detected GPU of another family is an error; a host without nvidia-smi
# or a visible GPU builds for sm100 with a warning.
set -euo pipefail
arch="$(printf '%s' "${DEEPINFER_NVIDIA_ARCH:-}" | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]')"
if [ -z "${arch}" ]; then
capability=""
device="0"
if [ -n "${CUDA_VISIBLE_DEVICES+set}" ]; then
device="$(printf '%s' "${CUDA_VISIBLE_DEVICES%%,*}" | tr -d '[:space:]')"
fi
case "${device}" in
"" | -*) ;;
*)
if command -v nvidia-smi >/dev/null 2>&1; then
capability="$(nvidia-smi -i "${device}" --query-gpu=compute_cap --format=csv,noheader 2>/dev/null | head -n 1 | tr -d '[:space:]' || true)"
fi
;;
esac
case "${capability}" in
10.*) arch=sm100 ;;
12.*) arch=sm120 ;;
"")
echo "WARNING: no visible NVIDIA GPU detected (nvidia-smi missing or no device '${device}'); building for sm100." \
"Set DEEPINFER_NVIDIA_ARCH=sm100 or sm120 to choose explicitly." >&2
arch=sm100
;;
*)
echo "Unsupported NVIDIA GPU (compute capability ${capability}); DeepInfer builds for sm100 or sm120." \
"Set DEEPINFER_NVIDIA_ARCH to build for one of them anyway." >&2
exit 1
;;
esac
fi
case "${arch}" in
sm100|sm120) echo "${arch}" ;;
*)
echo "Unsupported DEEPINFER_NVIDIA_ARCH: '${DEEPINFER_NVIDIA_ARCH:-}' (expect sm100 or sm120)" >&2
exit 1
;;
esac