Fixed the Cuda detection and fallback logic

On systems where CUDA_VERSION=12.4 the script was incorrectly labeling it as 12.6 by default
This commit is contained in:
2026-01-22 11:54:36 -05:00
parent b41b7d7420
commit 32e40d3a7f

View File

@@ -88,21 +88,24 @@ fi
DETECTED_CUDA="$(nvidia-smi | grep 'CUDA Version' | sed 's/.*CUDA Version: *\([0-9.]*\).*/\1/')"
log "Detected CUDA capability: ${DETECTED_CUDA}"
choose_cuda() {
for v in "${SUPPORTED_CUDA[@]}"; do
if [[ "$DETECTED_CUDA" == "$v"* ]]; then
echo "$v"
return
fi
done
choose_cuda() {
# Pick highest supported version <= detected CUDA capability
for v in $(printf '%s\n' "${SUPPORTED_CUDA[@]}" | sort -rV); do
if [ "$(printf '%s\n%s\n' "$v" "$DETECTED_CUDA" | sort -V | head -n1)" = "$v" ]; then
echo "$v"
return
fi
done
echo ""
}
# fallback: highest <= detected
for v in $(printf '%s\n' "${SUPPORTED_CUDA[@]}" | sort -rV); do
if [[ "$(printf '%s\n%s\n' "$v" "$DETECTED_CUDA" | sort -V | head -n1)" == "$v" ]]; then
echo "$v"
return
fi
done
if [ -z "$CUDA_VERSION" ]; then
warn "Could not auto-match CUDA version, defaulting to highest supported"
CUDA_VERSION="$(printf '%s\n' "${SUPPORTED_CUDA[@]}" | sort -V | tail -n1)"
else
log "Selected CUDA image version: ${CUDA_VERSION}"
fi
echo ""
}