Skip to content

Commit 53372ed

Browse files
authored
Merge pull request #1605 from eero-t/render-devices
Minor improvements to "render-device.sh" GPU plugin helper script
2 parents b03ac67 + 3ade6d4 commit 53372ed

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

cmd/gpu_plugin/render-device.sh

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# all distro base images. The required tools, and the packages they
2323
# reside in Debian based distros, are:
2424
# - dash: 'sh' (minimal bourne shell)
25-
# - coreutils: 'seq', 'cat', 'echo'
25+
# - coreutils: 'seq', 'cat', 'echo', 'id'
2626
# - sed: 'sed'
2727
#
2828
# But they are also provided by 'busybox' and 'toybox' tool sets.
@@ -35,6 +35,9 @@ usage ()
3535
echo "on standard output, or added to given command line. If device index"
3636
echo "N is given, provides name of Nth available (Intel GPU) render device."
3737
echo
38+
echo "With no arguments, outputs Intel GPU render devices count from sysfs,"
39+
echo "and how many of them are writable in devfs."
40+
echo
3841
echo "Usage:"
3942
echo " $name <device index>"
4043
echo " $name [device index] <media program> [other options] <GPU selection option>"
@@ -48,8 +51,29 @@ usage ()
4851
exit 1
4952
}
5053

54+
intel="0x8086"
5155
if [ $# -eq 0 ]; then
52-
usage "no arguments given"
56+
syscount=0
57+
devcount=0
58+
for i in $(seq 128 255); do
59+
devfile="/dev/dri/renderD$i"
60+
sysfile="/sys/class/drm/renderD$i/device/vendor"
61+
if [ ! -r "$sysfile" ]; then
62+
continue
63+
fi
64+
vendor=$(cat "$sysfile")
65+
if [ "$vendor" != "$intel" ]; then
66+
continue
67+
fi
68+
syscount=$((syscount+1))
69+
if [ -w "$devfile" ]; then
70+
devcount=$((devcount+1))
71+
fi
72+
done
73+
echo "$syscount Intel GPU render device(s) listed in sysfs, $devcount writable one(s) in devfs:"
74+
ls -l /dev/dri/
75+
echo "User: $(id)"
76+
exit 0
5377
fi
5478

5579
# determine required GPU index
@@ -66,21 +90,20 @@ fi
6690
visible=0
6791

6892
vendor=""
69-
intel="0x8086"
7093
# find host index "i" for Nth visible Intel GPU device
7194
for i in $(seq 128 255); do
7295
if [ -w "/dev/dri/renderD$i" ]; then
7396
vendor=$(cat "/sys/class/drm/renderD$i/device/vendor")
7497
if [ "$vendor" = "$intel" ]; then
7598
visible=$((visible+1))
76-
if [ $visible -eq $required ]; then
99+
if [ $visible -eq "$required" ]; then
77100
break
78101
fi
79102
fi
80103
fi
81104
done
82105

83-
if [ $visible -ne $required ]; then
106+
if [ $visible -ne "$required" ]; then
84107
usage "$visible Intel GPU(s) found, not $required as requested"
85108
fi
86109
device="/dev/dri/renderD$i"
@@ -91,7 +114,7 @@ if [ $# -eq 0 ]; then
91114
fi
92115

93116
if [ $# -lt 2 ]; then
94-
usage "media program and/or GPU selection option missing"
117+
usage "media program and/or its GPU selection option missing"
95118
fi
96119

97120
# run given media workload with GPU device name appended to end

0 commit comments

Comments
 (0)