22
22
# all distro base images. The required tools, and the packages they
23
23
# reside in Debian based distros, are:
24
24
# - dash: 'sh' (minimal bourne shell)
25
- # - coreutils: 'seq', 'cat', 'echo'
25
+ # - coreutils: 'seq', 'cat', 'echo', 'id'
26
26
# - sed: 'sed'
27
27
#
28
28
# But they are also provided by 'busybox' and 'toybox' tool sets.
@@ -35,6 +35,9 @@ usage ()
35
35
echo " on standard output, or added to given command line. If device index"
36
36
echo " N is given, provides name of Nth available (Intel GPU) render device."
37
37
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
38
41
echo " Usage:"
39
42
echo " $name <device index>"
40
43
echo " $name [device index] <media program> [other options] <GPU selection option>"
@@ -48,8 +51,29 @@ usage ()
48
51
exit 1
49
52
}
50
53
54
+ intel=" 0x8086"
51
55
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
53
77
fi
54
78
55
79
# determine required GPU index
66
90
visible=0
67
91
68
92
vendor=" "
69
- intel=" 0x8086"
70
93
# find host index "i" for Nth visible Intel GPU device
71
94
for i in $( seq 128 255) ; do
72
95
if [ -w " /dev/dri/renderD$i " ]; then
73
96
vendor=$( cat " /sys/class/drm/renderD$i /device/vendor" )
74
97
if [ " $vendor " = " $intel " ]; then
75
98
visible=$(( visible+ 1 ))
76
- if [ $visible -eq $required ]; then
99
+ if [ $visible -eq " $required " ]; then
77
100
break
78
101
fi
79
102
fi
80
103
fi
81
104
done
82
105
83
- if [ $visible -ne $required ]; then
106
+ if [ $visible -ne " $required " ]; then
84
107
usage " $visible Intel GPU(s) found, not $required as requested"
85
108
fi
86
109
device=" /dev/dri/renderD$i "
@@ -91,7 +114,7 @@ if [ $# -eq 0 ]; then
91
114
fi
92
115
93
116
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"
95
118
fi
96
119
97
120
# run given media workload with GPU device name appended to end
0 commit comments