mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-12 16:55:37 +02:00
Fixes gpu_helpers returning "Non-VGA" devices as GPUs. I was curious about DeepSeek's so I tried it's hand with this as my head isn't quite up-to-speed yet 😅 But yeah it seems less error-prone than previous naive string-approach. --------- Co-authored-by: DatCaptainHorse <DatCaptainHorse@users.noreply.github.com> Co-authored-by: Wanjohi <elviswanjohi47@gmail.com> Co-authored-by: Wanjohi <71614375+wanjohiryan@users.noreply.github.com>
47 lines
1.2 KiB
Bash
47 lines
1.2 KiB
Bash
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
declare -A vendor_devices=()
|
|
|
|
function get_gpu_info {
|
|
vendor_devices=()
|
|
|
|
local gpu_info=$(lspci -nn | grep -E '\<(0300|0302|0380)\>')
|
|
|
|
while IFS= read -r line; do
|
|
# Extract vendor_id from [vendor_id:device_id]
|
|
local vendor_id=$(echo "$line" | sed -nE 's/.*\[([[:xdigit:]]{4}):[[:xdigit:]]{4}\].*/\1/p' | tr '[:upper:]' '[:lower:]')
|
|
local id=$(echo "$line" | awk '{print $1}')
|
|
|
|
# Map vendor_id to known vendors
|
|
local vendor="unknown"
|
|
case "$vendor_id" in
|
|
10de) vendor="nvidia" ;;
|
|
8086) vendor="intel" ;;
|
|
1002 | 1022) vendor="amd" ;;
|
|
# Add other vendor IDs as needed
|
|
esac
|
|
|
|
if [[ "$vendor" != "unknown" ]]; then
|
|
vendor_devices["$vendor"]+="$id "
|
|
fi
|
|
done <<<"$gpu_info"
|
|
}
|
|
|
|
function debug_gpu_info {
|
|
echo "Detected GPUs:"
|
|
for vendor in "${!vendor_devices[@]}"; do
|
|
echo " $vendor: ${vendor_devices[$vendor]}"
|
|
done
|
|
}
|
|
|
|
# # Usage example:
|
|
# get_gpu_info
|
|
# debug_gpu_info
|
|
|
|
# # Access NVIDIA GPUs specifically
|
|
# if [[ -n "${vendor_devices[nvidia]:-}" ]]; then
|
|
# echo "NVIDIA GPUs detected: ${vendor_devices[nvidia]}"
|
|
# else
|
|
# echo "No NVIDIA GPUs found"
|
|
# fi |