From 9bcd0ed4401a806584bdd5f94b8f3db1ad7cf49f Mon Sep 17 00:00:00 2001 From: LeoBorcherding Date: Tue, 5 May 2026 21:27:10 -0700 Subject: [PATCH] fix(install): harden AMD ROCm GPU detection for multi-GPU and env-filtered setups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous rocminfo awk pattern could miss discrete GPUs on machines where HIP_VISIBLE_DEVICES/ROCR_VISIBLE_DEVICES is used to mask an integrated GPU — the env vars filter rocminfo output but may not propagate into the install script subprocess, causing detection to fail entirely. Two changes: - Tighten rocminfo pattern from /gfx[0-9]/ && !/gfx000/ to /gfx[1-9][0-9]/ — simpler and correctly excludes the CPU agent (gfx000) without a negative lookahead - Add sysfs KFD topology fallback: reads /sys/class/kfd/kfd/topology/nodes/*/gpu_id which is a kernel-level view unaffected by HIP_VISIBLE_DEVICES or ROCR_VISIBLE_DEVICES Fixes detection failure reported in Discord by Chains (gfx1201 + iGPU machine where env var exclusion of the iGPU caused rocminfo to return no usable device). --- install.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 9046a9bdf6..305e45917f 100755 --- a/install.sh +++ b/install.sh @@ -1478,15 +1478,21 @@ _find_no_torch_runtime() { # ── AMD ROCm GPU detection helper ── # Returns 0 (true) if an actual AMD GPU is present, 1 (false) otherwise. -# Checks rocminfo for gfx[1-9]* (excludes gfx000 CPU agent) and -# amd-smi list for GPU data rows (excludes header-only output). +# Checks rocminfo for gfx[1-9][0-9]+ (excludes gfx000 CPU agent), +# amd-smi list for GPU data rows, and falls back to sysfs KFD topology +# which is env-var-independent (works even when HIP_VISIBLE_DEVICES or +# ROCR_VISIBLE_DEVICES hides devices from rocminfo/amd-smi). _has_amd_rocm_gpu() { if command -v rocminfo >/dev/null 2>&1 && \ - rocminfo 2>/dev/null | awk '/Name:[[:space:]]*gfx[0-9]/ && !/Name:[[:space:]]*gfx000/{found=1} END{exit !found}'; then + rocminfo 2>/dev/null | awk '/Name:[[:space:]]*gfx[1-9][0-9]/{found=1} END{exit !found}'; then return 0 elif command -v amd-smi >/dev/null 2>&1 && \ amd-smi list 2>/dev/null | awk '/^GPU[[:space:]]*[:\[][[:space:]]*[0-9]/{ found=1 } END{ exit !found }'; then return 0 + elif [ -e /dev/kfd ] && \ + awk '/gpu_id/{ if ($2+0 > 0) found=1 } END{ exit !found }' \ + /sys/class/kfd/kfd/topology/nodes/*/gpu_id 2>/dev/null; then + return 0 fi return 1 }