Debian Codegraph @

bin/mymcpu

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 #
3 # mymcpu: Print the codename the current gpu
4 # mygpu: Print a gpu value
5 # myarchgpu: Print arch-gpu value
6 #
7
8 PROGVERSION=X.Y-Z
9
10 # Copyright (c) 2020-2022 Advanced Micro Devices, Inc. All rights reserved.
11 # [MITx11 License]
12
13 # Permission is hereby granted, free of charge, to any person obtaining a copy
14 # of this software and associated documentation files (the "Software"), to deal
15 # in the Software without restriction, including without limitation the rights
16 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 # copies of the Software, and to permit persons to whom the Software is
18 # furnished to do so, subject to the following conditions:
19 #
20 # The above copyright notice and this permission notice shall be included in
21 # all copies or substantial portions of the Software.
22 #
23 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 # THE SOFTWARE.
30
31 function usagescip-shell shell shell-project 0.0.0 usage().(){
32 /bin/catscip-shell filesystem . . `/bin/cat`. 2>&1 <<"EOF"
33
34 mymcpu: Print out a codename for the gpu of the current system.
35
36 mygpu: Print out the real gpu name for the current system .
37 mygpu will only print values accepted by cuda clang in
38 the clang argument --cuda-gpu-arch
39 myarchgpu: Print out the real gpu name for the current system
40 with the arch prefix. e.g. nvptx-sm_70
41
42 Usage: myarchgpu
43
44 Options without values:
45 -h Print this help message
46 -d If GPU is unknown, return this default device
47 -version Print the version of mymcpu and mygpu
48
49 Copyright (c) 2020-2022 ADVANCED MICRO DEVICES, INC.
50
51 EOF
52 exit 1
53 }
54
55 function versionscip-shell shell shell-project 0.0.0 version().(){
56 echoscip-shell system . . echo. $PROGVERSION
57 exit 0
58 }
59
60 function getdnamescip-shell shell shell-project 0.0.0 getdname().(){
61 local __DIRN=`dirnamescip-shell system . . dirname. "$1"`
62 if [scip-shell system . . `[`. "$__DIRN" = "." ] ; then
63 __DIRN=$PWD;
64 else
65 if [scip-shell system . . `[`. ${__DIRN:0:1} != "/scip-shell filesystem . . `/`." ] ; then
66 if [scip-shell system . . `[`. ${__DIRN:0:2} == ".." ] ; then
67 __DIRN=`dirnamescip-shell system . . dirname. $PWD`/${__DIRN:3}
68 else
69 if [scip-shell system . . `[`. ${__DIRN:0:1} = "." ] ; then
70 __DIRN=$PWD/${__DIRN:2}
71 else
72 __DIRN=$PWD/$__DIRN
73 fi
74 fi
75 fi
76 fi
77 echoscip-shell system . . echo. $__DIRN
78 }
79
80 function getarchscip-shell shell shell-project 0.0.0 getarch().(){
81 if [scip-shell system . . `[`. "${1:0:3}" == "sm_" ] ; then
82 echoscip-shell system . . echo. "nvptx"
83 else
84 echoscip-shell system . . echo. "amdgcn"
85 fi
86 }
87
88 function code2gpuscip-shell shell shell-project 0.0.0 code2gpu().(){
89 case "$1" in
90 "tahiti") gpuname="gfx600"
91 ;;
92 "gfx600") gpuname="gfx600"
93 ;;
94 "oland") gpuname="gfx601"
95 ;;
96 "gfx601") gpuname="gfx601"
97 ;;
98 "gfx700") gpuname="gfx700"
99 ;;
100 "kaveri") gpuname="gfx700"
101 ;;
102 "gfx701") gpuname="gfx701"
103 ;;
104 "hawaii") gpuname="gfx701"
105 ;;
106 "gfx703") gpuname="gfx703"
107 ;;
108 "kabini") gpuname="gfx703"
109 ;;
110 "gfx801") gpuname="gfx801"
111 ;;
112 "carrizo") gpuname="gfx801"
113 ;;
114 "gfx802") gpuname="gfx802"
115 ;;
116 "tonga") gpuname="gfx802"
117 ;;
118 "gfx803") gpuname="gfx803"
119 ;;
120 "fiji") gpuname="gfx803"
121 ;;
122 "vega") gpuname="gfx900"
123 ;;
124 "RavenRidge") gpuname="gfx902"
125 ;;
126 "vega20") gpuname="gfx906"
127 ;;
128 "NRAXJ") gpuname="gfx908"
129 ;;
130 "NRAXJ2") gpuname="gfx90a"
131 ;;
132 "navi12") gpuname="gfx1011"
133 ;;
134 "navi21") gpuname="gfx1030"
135 ;;
136 "n3a") gpuname="gfx1101"
137 ;;
138 "sm_30") gpuname="sm_30"
139 ;;
140 "k4000") gpuname="sm_30"
141 ;;
142 "k40c") gpuname="sm_35"
143 ;;
144 "k4200") gpuname="sm_30"
145 ;;
146 "gtx960m") gpuname="sm_50"
147 ;;
148 "gtx980") gpuname="sm_35"
149 ;;
150 "gtx1050") gpuname="sm_61"
151 ;;
152 "gtx1060") gpuname="sm_61"
153 ;;
154 "gtx1080") gpuname="sm_61"
155 ;;
156 "gt730") gpuname="sm_35"
157 ;;
158 "p100") gpuname="sm_60"
159 ;;
160 "gv100") gpuname="sm_70"
161 ;;
162 "v100") gpuname="sm_70"
163 ;;
164 "") gpuname="sm_35"
165 ;;
166 *) gpuname=$unknown_value
167 ;;
168 esac
169 echoscip-shell system . . echo. $gpuname
170 }
171
172 function getmycodenamescip-shell shell shell-project 0.0.0 getmycodename().()
173 {
174 thisdir=$(getdnamescip-shell shell shell-project 0.0.0 getdname(). $0)
175 if [scip-shell system . . `[`. -L "$thisdir/mymcpu" ] ; then
176 linkfile=`readlinkscip-shell system . . readlink. "$thisdir/mymcpu"`
177 if [scip-shell system . . `[`. "${linkfile%%/*}" == ".." ] ; then
178 linkfile=$thisdir/$linkfile
179 fi
180 thisdir=$(getdnamescip-shell shell shell-project 0.0.0 getdname(). $linkfile)
181 fi
182 GPUTABLE_FILE=${GPUTABLE_FILE:-$thisdir/gputable.txt}
183 local _found=0
184 if [scip-shell system . . `[`. -f $GPUTABLE_FILE ] ; then
185 # Look for amd cards first
186 for sysfsname in `findscip-shell system . . find. -L /sys/bus/pci/devicesscip-shell filesystem . . `/sys/bus/pci/devices`. -maxdepth 2 -name uevent | xargsscip-shell system . . xargs. grep -l -E 'DRIVER=amdgpu'` ; do
187 gpuid=`catscip-shell system . . cat. $sysfsname | grepscip-shell system . . grep. 'PCI_ID=' | cutscip-shell system . . cut. -d"=" -f2 | trscip-shell system . . tr. '[:upper:]' '[:lower:]'`
188 if [scip-shell system . . `[`. $_found == 0 ] ; then
189 #fixme what happens if multiple gpus, will gpuid be multiple lines?
190 entry=`grepscip-shell system . . grep. -m1 "^$gpuid" $GPUTABLE_FILE`
191 if [scip-shell system . . `[`. $? == 0 ] ; then
192 codename=`echoscip-shell system . . echo. $entry | awkscip-shell system . . awk. '{print $4}'`
193 _found=1
194 fi
195 fi
196 done
197 if [scip-shell system . . `[`. $_found == 0 ] ; then
198 for sysfsname in `findscip-shell system . . find. -L /sys/bus/pci/devicesscip-shell filesystem . . `/sys/bus/pci/devices`. -maxdepth 2 -name uevent | xargsscip-shell system . . xargs. grep -l -E 'DRIVER=nvidia'` ; do
199 gpuid=`catscip-shell system . . cat. $sysfsname | grepscip-shell system . . grep. 'PCI_ID=' | cutscip-shell system . . cut. -d"=" -f2 | trscip-shell system . . tr. '[:upper:]' '[:lower:]'`
200 if [scip-shell system . . `[`. $_found == 0 ] ; then
201 #fixme what happens if multiple gpus, will gpuid be multiple lines?
202 entry=`grepscip-shell system . . grep. -m1 "^$gpuid" $GPUTABLE_FILE`
203 if [scip-shell system . . `[`. $? == 0 ] ; then
204 codename=`echoscip-shell system . . echo. $entry | awkscip-shell system . . awk. '{print $4}'`
205 _found=1
206 fi
207 fi
208 done
209 fi
210 fi
211 if [scip-shell system . . `[`. $_found == 1 ] ; then
212 echoscip-shell system . . echo. $codename
213 else
214 echoscip-shell system . . echo. "unknown"
215 # for debugging unknown codenames, return gpuid here
216 # echo "$gpuid"
217 fi
218 }
219
220 # =========== Main code for mymcpu and mygpu starts here ==========
221 TYPERUN=${0##*\/}
222 MODE=
223
224 unknown_value="unknown"
225 # process args
226 while [scip-shell system . . `[`. $# -gt 0 ] ; do
227 case "$1" in
228 -n) MODE=num; shift ;;
229 -h) usagescip-shell shell shell-project 0.0.0 usage(). ;;
230 -d) unknown_value=$2; shift ;;
231 -help) usagescip-shell shell shell-project 0.0.0 usage(). ;;
232 --help) usagescip-shell shell shell-project 0.0.0 usage(). ;;
233 -version) versionscip-shell shell shell-project 0.0.0 version(). ;;
234 --version) versionscip-shell shell shell-project 0.0.0 version(). ;;
235 --) shift ; break;;
236 *) break;echoscip-shell system . . echo. $1 ignored;
237 esac
238 shift
239 done
240
241 rc=0
242 if [scip-shell system . . `[`. "$TYPERUN" == "mygpu" ] ; then
243 codename=$(getmycodenamescip-shell shell shell-project 0.0.0 getmycodename().)
244 gpuname=$(code2gpuscip-shell shell shell-project 0.0.0 code2gpu(). $codename)
245 [scip-shell system . . `[`. "$gpuname" == "unknown" ] && rc=1
246 if [scip-shell system . . `[`. -z "$MODE" ]; then
247 echoscip-shell system . . echo. $gpuname
248 else
249 echoscip-shell system . . echo. `echoscip-shell system . . echo. $gpuname | sedscip-shell system . . sed. 's/gfx//' | sedscip-shell system . . sed. 's/sm_//'`
250 fi
251 elif [scip-shell system . . `[`. "$TYPERUN" == "myarchgpu" ] ; then
252 codename=$(getmycodenamescip-shell shell shell-project 0.0.0 getmycodename().)
253 gpuname=$(code2gpuscip-shell shell shell-project 0.0.0 code2gpu(). $codename)
254 if [scip-shell system . . `[`. "$gpuname" == "unknown" ] ; then
255 rc=1
256 echoscip-shell system . . echo. unknown-unknown
257 else
258 archname=$(getarchscip-shell shell shell-project 0.0.0 getarch(). $gpuname)
259 echoscip-shell system . . echo. $archname-$gpuname
260 fi
261 else
262 # This is mymcpu so print the codename
263 codename=$(getmycodenamescip-shell shell shell-project 0.0.0 getmycodename().)
264 [scip-shell system . . `[`. "$codename" == "unknown" ] && rc=1
265 echoscip-shell system . . echo. $codename
266 fi
267
268 exit $rc