Update GPU transform for --gpus "device=UUID" style; keep --runtime=nvidia fallback

This commit is contained in:
Gmer4Lfe
2026-06-14 22:07:32 -04:00
parent 7da9018378
commit f2a1a930dd
+18 -8
View File
@@ -74,17 +74,21 @@ detect_remote_gpu() {
# Returns the path to a temp file — caller must clean it up. # Returns the path to a temp file — caller must clean it up.
# Returns the original path unchanged if the XML has no NVIDIA markers (not GPU-aware). # Returns the original path unchanged if the XML has no NVIDIA markers (not GPU-aware).
# #
# Handles both GPU config styles:
# New: --gpus "device=GPU-UUID" in ExtraParams (current approach)
# Old: --runtime=nvidia in ExtraParams + NVIDIA_VISIBLE_DEVICES Variable Config
#
# Transforms applied: # Transforms applied:
# nvidia → nvidia: replace UUID with "all" so any NVIDIA GPU is accepted # nvidia → nvidia: normalise device UUID to "all" (both styles)
# nvidia → intel/amd/dri: strip --runtime=nvidia + NVIDIA_VISIBLE_DEVICES, # nvidia → intel/dri: strip NVIDIA params, inject /dev/dri Device Config
# inject /dev/dri Device Config (+ /dev/kfd for AMD) # nvidia → amd: strip NVIDIA params, inject /dev/dri + /dev/kfd Device Configs
# nvidia → none: strip --runtime=nvidia + NVIDIA_VISIBLE_DEVICES, no device added # nvidia → none: strip NVIDIA params, no device added
# ============================================================================================== # ==============================================================================================
transform_xml_for_gpu() { transform_xml_for_gpu() {
local src_xml="$1" gpu_type="$2" local src_xml="$1" gpu_type="$2"
# Only transform GPU-aware XMLs (containers with NVIDIA config) # Detect GPU-aware XMLs — new style (--gpus "device=) or old style (--runtime=nvidia)
if ! grep -qE 'runtime=nvidia|NVIDIA_VISIBLE_DEVICES' "$src_xml" 2>/dev/null; then if ! grep -qE '--gpus[[:space:]]+"device=|--runtime=nvidia|NVIDIA_VISIBLE_DEVICES' "$src_xml" 2>/dev/null; then
echo "$src_xml" echo "$src_xml"
return 0 return 0
fi fi
@@ -94,12 +98,16 @@ transform_xml_for_gpu() {
case "$gpu_type" in case "$gpu_type" in
nvidia) nvidia)
# Same vendor — normalise UUID to "all" so any NVIDIA card is accepted # Normalise to --gpus all (new style) or NVIDIA_VISIBLE_DEVICES=all (old style)
sed 's/\(Target="NVIDIA_VISIBLE_DEVICES"[^>]*>\)[^<]*/\1all/' "$src_xml" > "$tmp_xml" sed \
-e 's/--gpus[[:space:]]*"device=[^"]*"/--gpus all/g' \
-e 's/\(Target="NVIDIA_VISIBLE_DEVICES"[^>]*>\)[^<]*/\1all/' \
"$src_xml" > "$tmp_xml"
;; ;;
intel|dri) intel|dri)
# Strip NVIDIA params, add /dev/dri device # Strip NVIDIA params, add /dev/dri device
sed \ sed \
-e 's/--gpus[[:space:]]*"device=[^"]*"[[:space:]]*//' \
-e 's/--runtime=nvidia[[:space:]]*//' \ -e 's/--runtime=nvidia[[:space:]]*//' \
-e '/Target="NVIDIA_VISIBLE_DEVICES"/d' \ -e '/Target="NVIDIA_VISIBLE_DEVICES"/d' \
"$src_xml" > "$tmp_xml" "$src_xml" > "$tmp_xml"
@@ -108,6 +116,7 @@ transform_xml_for_gpu() {
amd) amd)
# AMD needs /dev/dri for VA-API and /dev/kfd for ROCm/OpenCL # AMD needs /dev/dri for VA-API and /dev/kfd for ROCm/OpenCL
sed \ sed \
-e 's/--gpus[[:space:]]*"device=[^"]*"[[:space:]]*//' \
-e 's/--runtime=nvidia[[:space:]]*//' \ -e 's/--runtime=nvidia[[:space:]]*//' \
-e '/Target="NVIDIA_VISIBLE_DEVICES"/d' \ -e '/Target="NVIDIA_VISIBLE_DEVICES"/d' \
"$src_xml" > "$tmp_xml" "$src_xml" > "$tmp_xml"
@@ -116,6 +125,7 @@ transform_xml_for_gpu() {
none) none)
# No GPU — strip all GPU params, no device added # No GPU — strip all GPU params, no device added
sed \ sed \
-e 's/--gpus[[:space:]]*"device=[^"]*"[[:space:]]*//' \
-e 's/--runtime=nvidia[[:space:]]*//' \ -e 's/--runtime=nvidia[[:space:]]*//' \
-e '/Target="NVIDIA_VISIBLE_DEVICES"/d' \ -e '/Target="NVIDIA_VISIBLE_DEVICES"/d' \
"$src_xml" > "$tmp_xml" "$src_xml" > "$tmp_xml"