mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-12 08:45:38 +02:00
🐜 fix(scripts): Use class codes to check for lspci GPU devices (#168)
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>
This commit is contained in:
committed by
GitHub
parent
4c33d7fe00
commit
431733a0e8
3
.github/workflows/runner.yml
vendored
3
.github/workflows/runner.yml
vendored
@@ -7,6 +7,7 @@ on:
|
|||||||
paths:
|
paths:
|
||||||
- "containers/runner.Containerfile"
|
- "containers/runner.Containerfile"
|
||||||
- "packages/server/**"
|
- "packages/server/**"
|
||||||
|
- "packages/scripts/**"
|
||||||
- ".github/workflows/runner.yml"
|
- ".github/workflows/runner.yml"
|
||||||
schedule:
|
schedule:
|
||||||
- cron: 7 0 * * 1,3,6 # Regularly to keep that build cache warm
|
- cron: 7 0 * * 1,3,6 # Regularly to keep that build cache warm
|
||||||
@@ -139,4 +140,4 @@ jobs:
|
|||||||
# name: Move cache
|
# name: Move cache
|
||||||
# run: |
|
# run: |
|
||||||
# rm -rf /tmp/.buildx-cache
|
# rm -rf /tmp/.buildx-cache
|
||||||
# mv /tmp/.buildx-cache-new /tmp/.buildx-cache
|
# mv /tmp/.buildx-cache-new /tmp/.buildx-cache
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ ENV XDG_RUNTIME_DIR=/run/user/${UID} \
|
|||||||
|
|
||||||
# Required for NVIDIA.. they want to be special like that #
|
# Required for NVIDIA.. they want to be special like that #
|
||||||
ENV NVIDIA_DRIVER_CAPABILITIES=all
|
ENV NVIDIA_DRIVER_CAPABILITIES=all
|
||||||
|
ENV NVIDIA_VISIBLE_DEVICES=all
|
||||||
|
|
||||||
# DBus run directory creation #
|
# DBus run directory creation #
|
||||||
RUN mkdir -p /run/dbus
|
RUN mkdir -p /run/dbus
|
||||||
|
|||||||
@@ -36,19 +36,16 @@ source /etc/nestri/gpu_helpers.sh
|
|||||||
|
|
||||||
get_gpu_info
|
get_gpu_info
|
||||||
|
|
||||||
# Identify vendor
|
# Check vendors in priority order
|
||||||
if [[ "${vendor_full_map[0],,}" =~ "intel" ]]; then
|
if [[ -n "${vendor_devices[nvidia]:-}" ]]; then
|
||||||
echo "Intel GPU detected, installing required packages..."
|
|
||||||
#chwd -a
|
|
||||||
pacman -Sy --noconfirm gstreamer-vaapi gst-plugin-va gst-plugin-qsv
|
|
||||||
# chwd missed a thing
|
|
||||||
pacman -Sy --noconfirm vpl-gpu-rt
|
|
||||||
elif [[ "${vendor_full_map[0],,}" =~ "amd" ]]; then
|
|
||||||
echo "AMD GPU detected, installing required packages..."
|
|
||||||
#chwd -a
|
|
||||||
pacman -Sy --noconfirm gstreamer-vaapi gst-plugin-va
|
|
||||||
elif [[ "${vendor_full_map[0],,}" =~ "nvidia" ]]; then
|
|
||||||
echo "NVIDIA GPU detected. Assuming drivers are linked"
|
echo "NVIDIA GPU detected. Assuming drivers are linked"
|
||||||
|
elif [[ -n "${vendor_devices[intel]:-}" ]]; then
|
||||||
|
echo "Intel GPU detected, installing required packages..."
|
||||||
|
pacman -Sy --noconfirm gstreamer-vaapi gst-plugin-va gst-plugin-qsv
|
||||||
|
pacman -Sy --noconfirm vpl-gpu-rt
|
||||||
|
elif [[ -n "${vendor_devices[amd]:-}" ]]; then
|
||||||
|
echo "AMD GPU detected, installing required packages..."
|
||||||
|
pacman -Sy --noconfirm gstreamer-vaapi gst-plugin-va
|
||||||
else
|
else
|
||||||
echo "Unknown GPU vendor. No additional packages will be installed"
|
echo "Unknown GPU vendor. No additional packages will be installed"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,52 +1,47 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
declare -a vendor_full_map=()
|
declare -A vendor_devices=()
|
||||||
declare -a vendor_id_map=()
|
|
||||||
declare -A vendor_index_map=()
|
|
||||||
|
|
||||||
function get_gpu_info {
|
function get_gpu_info {
|
||||||
# Initialize arrays/maps to avoid unbound variable errors
|
vendor_devices=()
|
||||||
vendor_full_map=()
|
|
||||||
vendor_id_map=()
|
|
||||||
vendor_index_map=()
|
|
||||||
|
|
||||||
# Use lspci to detect GPU info
|
local gpu_info=$(lspci -nn | grep -E '\<(0300|0302|0380)\>')
|
||||||
gpu_info=$(lspci | grep -i 'vga\|3d\|display')
|
|
||||||
|
|
||||||
# Parse each line of GPU info
|
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
# Extract vendor name and ID from lspci output
|
# Extract vendor_id from [vendor_id:device_id]
|
||||||
vendor=$(echo "$line" | awk -F: '{print $3}' | sed -E 's/^[[:space:]]+//g' | tr '[:upper:]' '[:lower:]')
|
local vendor_id=$(echo "$line" | sed -nE 's/.*\[([[:xdigit:]]{4}):[[:xdigit:]]{4}\].*/\1/p' | tr '[:upper:]' '[:lower:]')
|
||||||
id=$(echo "$line" | awk '{print $1}')
|
local id=$(echo "$line" | awk '{print $1}')
|
||||||
|
|
||||||
# Normalize vendor name
|
# Map vendor_id to known vendors
|
||||||
if [[ $vendor =~ .*nvidia.* ]]; then
|
local vendor="unknown"
|
||||||
vendor="nvidia"
|
case "$vendor_id" in
|
||||||
elif [[ $vendor =~ .*intel.* ]]; then
|
10de) vendor="nvidia" ;;
|
||||||
vendor="intel"
|
8086) vendor="intel" ;;
|
||||||
elif [[ $vendor =~ .*advanced[[:space:]]micro[[:space:]]devices.* ]]; then
|
1002 | 1022) vendor="amd" ;;
|
||||||
vendor="amd"
|
# Add other vendor IDs as needed
|
||||||
elif [[ $vendor =~ .*ati.* ]]; then
|
esac
|
||||||
vendor="amd"
|
|
||||||
else
|
|
||||||
vendor="unknown"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Add to arrays/maps if unique
|
if [[ "$vendor" != "unknown" ]]; then
|
||||||
if ! [[ "${vendor_index_map[$vendor]:-}" ]]; then
|
vendor_devices["$vendor"]+="$id "
|
||||||
vendor_index_map[$vendor]="${#vendor_full_map[@]}"
|
|
||||||
vendor_full_map+=("$vendor")
|
|
||||||
fi
|
fi
|
||||||
vendor_id_map+=("$id")
|
done <<<"$gpu_info"
|
||||||
done <<< "$gpu_info"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function debug_gpu_info {
|
function debug_gpu_info {
|
||||||
echo "Vendor Full Map: ${vendor_full_map[*]}"
|
echo "Detected GPUs:"
|
||||||
echo "Vendor ID Map: ${vendor_id_map[*]}"
|
for vendor in "${!vendor_devices[@]}"; do
|
||||||
echo "Vendor Index Map:"
|
echo " $vendor: ${vendor_devices[$vendor]}"
|
||||||
for key in "${!vendor_index_map[@]}"; do
|
|
||||||
echo " $key: ${vendor_index_map[$key]}"
|
|
||||||
done
|
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
|
||||||
Reference in New Issue
Block a user