#!/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