-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathget_platforms.inc
390 lines (366 loc) · 11.5 KB
/
get_platforms.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<?php
ini_set('display_errors', 'stdout');
error_reporting(E_ALL);
// The platforms for a given project are stored in a JSON file platforms/URL.
// It's a list of 'extended platform names': strings of the form
// <platform>
// or
// <platform>[<planclass>]
// convert extended platform name to human-readable string
//
function friendly_name($p) {
$x = explode('[', $p);
$pc = "";
if (sizeof($x) > 1) {
$p = $x[0];
$pc = substr($x[1], 0, -1);
}
if (strstr($p, "fubar")) return null;
if ($p == 'x86_64-unknown-linux-gnu') return null;
$q = $p;
switch ($p) {
case 'i686-pc-linux-gnu': $q = 'Linux/x86'; break;
case 'windows_intelx86': $q = 'Windows'; break;
case 'x86_64-pc-linux-gnu': $q = 'Linux/x64'; break;
case 'i686-apple-darwin': $q = 'Mac OS X'; break;
case 'x86_64-apple-darwin': $q = 'Mac OS X 64-bit'; break;
case 'powerpc-apple-darwin': $q = 'Mac OS X (PowerPC)'; break;
case 'sparc-sun-solaris2.7': $q = 'SPARC Solaris 2.7'; break;
case 'sparc-sun-solaris': $q = 'SPARC Solaris'; break;
case 'powerpc64-unknown-linux-gnu': $q = 'Linux/PowerPC64'; break;
case 'windows_x86_64': $q = 'Windows/x64'; break;
case 'powerpc64-ps3-linux-gnu': $q = 'Playstation3/Linux'; break;
case 'i386-portbld-freebsd': $q = 'FreeBSD/x86'; break;
case 'windows_amd64': $q = 'Windows/Opteron'; break;
case 'x86_64-pc-solaris': $q = 'Solaris/x64'; break;
case 'windows_intelx86_64': $q = 'Windows/x64'; break;
case 'arm-android-linux-gnu': $q = 'Android/ARM'; break;
case 'arm-android': $q = 'Android/ARM'; break;
case 'arm-unknown-linux-gnu': $q = 'Linux/ARM'; break;
case 'aarch64-unknown-linux-gnu': $q = 'Linux on ARM64'; break;
case 'x86_64-pc-freebsd': $q = 'FreeBSD/x86'; break;
case 'arm-unknown-linux-gnueabihf': $q = 'Linux on ARM (e.g., Raspberry Pi)'; break;
}
if (strlen($pc)) {
if (strstr($pc, 'cuda')) $q .= " (NVIDIA GPU)";
else if (strstr($pc, 'nvidia')) $q .= " (NVIDIA GPU)";
else if (strstr($pc, 'ati')) $q .= " (AMD/ATI GPU)";
else if (strstr($pc, 'amd')) $q .= " (AMD/ATI GPU)";
else if (strstr($pc, 'intel_gpu')) $q .= " (Intel GPU)";
else if (strstr($pc, 'apple_gpu')) $q .= " (Apple GPU)";
if (strstr($pc, 'mt')) $q .= " (multicore)";
if (strstr($pc, 'vbox32')) $q .= " (VirtualBox 32-bit)";
else if (strstr($pc, 'vbox64')) $q .= " (VirtualBox 64-bit)";
else if (strstr($pc, 'docker')) $q .= " (Docker)";
}
return $q;
}
// return an array of bools for the supported platforms,
// GPU types, and virtualization types
//
function get_platform_icon_flags($platforms) {
$x = new StdClass;
$x->windows = false;
$x->mac = false;
$x->linux = false;
$x->android = false;
$x->freebsd = false;
$x->rasp_pi = false;
$x->nvidia_gpu = false;
$x->amd_gpu = false;
$x->intel_gpu = false;
$x->apple_gpu = false;
$x->vbox = false;
$x->docker = false;
foreach ($platforms as $plat) {
$p = $plat;
$y = explode('[', $plat);
$pc = "";
if (sizeof($y) > 1) {
$p = $y[0];
$pc = substr($y[1], 0, -1);
}
if (strstr($p, "windows")) $x->windows = true;
else if (strstr($p, "darwin")) $x->mac = true;
else if (strstr($p, "android")) $x->android = true;
else if (strstr($p, "freebsd")) $x->freebsd = true;
else if (strstr($p, "arm-unknown-linux-gnueabihf")) $x->rasp_pi = true;
else if (strstr($p, "armv5")) $x->rasp_pi = true;
else if (strstr($p, "aarch64")) $x->rasp_pi = true;
else if (strstr($p, "armv6")) $x->rasp_pi = true;
else if (strstr($p, "linux")) $x->linux = true;
// must follow android, rasp_pi options
if (strstr($pc, "ati")) $x->amd_gpu = true;
else if (strstr($pc, "amd")) $x->amd_gpu = true;
else if (strstr($pc, "cuda")) $x->nvidia_gpu = true;
else if (strstr($pc, "nvidia")) $x->nvidia_gpu = true;
else if (strstr($pc, "intel_gpu")) $x->intel_gpu = true;
else if (strstr($pc, "apple_gpu")) $x->apple_gpu = true;
if (strstr($pc, "vbox")) $x->vbox = true;
else if (strstr($pc, "docker")) $x->docker = true;
}
return $x;
}
function icon_image($fname, $title, $background=false) {
return sprintf(
'<img hspace=%d %s vspace=%d height=%d src=images/%s title="%s">%s',
5, // horiz pad
$background?'style="background-color:white;"':'',
4, // vert pad
40, // height
$fname,
$title,
"\n"
);
}
function platform_icons($f) {
$x = "";
$ht = 40;
$hs = 5;
$vs = 4;
if ($f->windows) {
$x .= icon_image('windows_logo.png', 'Supports Microsoft Windows');
}
if ($f->mac) {
$x .= icon_image('macos_logo.png', 'Supports Mac OS');
}
if ($f->linux) {
$x .= icon_image('linux_logo.png', 'Supports Linux on Intel');
}
if ($f->android) {
$x .= icon_image('android_logo.png', 'Supports Android');
}
if ($f->freebsd) {
$x .= icon_image('freebsd_logo.png', 'Supports FreeBSD');
}
if ($f->rasp_pi) {
$x .= icon_image('linux_arm.png', 'Supports Linux on ARM');
$x .= icon_image('raspberrypi_logo.png', 'Supports Raspberry Pi');
}
if ($f->nvidia_gpu) {
$x .= icon_image('nvidia_logo.png', 'Supports NVIDIA GPUs', true);
}
if ($f->amd_gpu) {
$x .= icon_image('AMD_logo.png', 'Supports AMD GPUs', true);
}
if ($f->intel_gpu) {
$x .= icon_image('intel_logo.png', 'Supports Intel GPUs');
}
if ($f->apple_gpu) {
$x .= icon_image('metal_logo.png', 'Supports Apple GPUs');
}
if ($f->vbox) {
$x .= icon_image('virtualbox_logo.png', 'Supports VirtualBox');
}
if ($f->docker) {
$x .= icon_image('docker_logo.png', 'Supports Docker');
}
return $x;
}
function canonical_plan_class($pc) {
if (strstr($pc, "atiOpenCL")) return "opencl_ati";
if (strstr($pc, "nvidiaOpenCL")) return "opencl_nvidia";
if (strstr($pc, "intelOpenCL")) return "opencl_intel_gpu";
return $pc;
}
// some specific cases where we know the project doesn't have jobs
//
function valid($url, $plat) {
if (strstr($url, "gpugrid.net")) {
if (strstr($plat, "android")) return false;
if (strstr($plat, "vbox")) return false;
} else if (strstr($url, "csgrid")) {
if (strstr($plat, "android")) return false;
}
return true;
}
// get platforms from get_project_config.php (preferred method)
//
// format is either
//
// <project_config>
// <platforms>
// <platform>windows_intelx86</platform>
// ...
//
// or
//
// <project_config>
// <platforms>
// <platform>
// <platform_name>windows_intelx86</platform_name>
// <user_friendly_name>Windows</user_friendly_name>
// [<plan_class>xxx</plan_class>]
// </platform>
// ...
//
function get_platforms($url) {
if (strstr($url, "radioactive")) return null;
$url .= 'get_project_config.php';
$x = @file_get_contents($url);
if (!$x) {
//echo "no file $url";
return null;
}
libxml_use_internal_errors(true);
$x = trim($x);
$s = simplexml_load_string($x);
if (!$s) {
//echo "XML parse error";
return null;
}
if (!array_key_exists('platforms', $s)) {
return null;
}
$p = $s->platforms;
//print_r($p);
//echo "---\n";
//foreach ($p->children() as $x) {
// echo $x;
//}
if (!array_key_exists('platform', $p)) {
return null;
}
if (sizeof($p->platform) == 0) {
return null;
}
$list = array();
if (array_key_exists(0, $p->platform[0])) {
foreach ($p->children() as $r) {
$list[] = (string)$r;
}
} else {
foreach ($p->platform as $r) {
$plat = (string)$r->platform_name;
if (array_key_exists('plan_class', $r)) {
$pc = canonical_plan_class((string)$r->plan_class);
if ($pc) {
$plat .= "[".$pc."]";
}
}
if (valid($url, $plat)) {
$list[] = $plat;
}
}
}
return array_values(array_unique($list));
}
// get platforms from app.php?xml=1
// Deprecated, but needed for old projects like mindmodeling
//
function get_platforms2($url) {
$url .= 'apps.php?xml=1';
$x = @file_get_contents($url);
if (!$x) {
//echo "no file $url\n";
return null;
}
libxml_use_internal_errors(true);
$s = simplexml_load_string($x);
$list = array();
foreach($s->application as $a) {
foreach ($a->version as $v) {
if (!array_key_exists('platform_short', $v)) continue;
$p = $v->platform_short[0];
$pc = "";
if (array_key_exists('plan_class', $v)) {
$pc = (string)$v->plan_class;
$pc = canonical_plan_class($pc);
}
if (strlen($pc)) {
$p = $p.'['.$pc.']';
}
$list[] = (string)$p;
}
}
return array_values(array_unique($list));
}
// convert an array of platform names into a comma-separated
// list of human-readable names
//
function make_friendly_string($l, $comma) {
if (!count($l)) return "Unknown";
$fn = array();
foreach($l as $p) {
$p = friendly_name($p);
if (!$p) continue;
$fn[] = $p;
}
$fn = array_unique($fn);
natcasesort($fn);
$x = "";
$first = true;
foreach($fn as $p) {
if ($first) {
$x .= "$p";
$first = false;
} else {
if ($comma) {
$x .= ", $p";
} else {
$x .= "<br>$p";
}
}
}
return $x;
}
// return platforms as an array of platform names
//
function get_platforms_cached($url) {
$u = urlencode($url);
$fname = "/home/boincadm/boinc-site/platforms/$u";
$t = @filemtime($fname);
if (strstr($url, "gpugrid") || ($t && $t > time() - 604800)) {
return json_decode(file_get_contents($fname));
}
$l = get_platforms($url);
echo "got $url";
if (!$l) {
$l = get_platforms2($url);
}
if ($l) {
file_put_contents($fname, json_encode($l));
} else {
if (file_exists($fname)) {
touch($fname);
} else {
$l[] = "Unknown";
file_put_contents($fname, json_encode($l));
}
}
return $l;
}
// return platforms as a human-readable string
//
function get_platforms_string($url, $comma=true) {
$l = get_platforms_cached($url);
return make_friendly_string($l, $comma);
}
function get_platform_icons($url) {
$platforms = get_platforms_cached($url);
$flags = get_platform_icon_flags($platforms);
return platform_icons($flags);
}
//$u = "http://www.worldcommunitygrid.org/";
//$u = "http://asteroidsathome.net/boinc/";
//$u = "http://setiathome.berkeley.edu/";
//$u = "http://aqua.dwavesys.com/";
//$u = "http://lhcathome2.cern.ch/test4theory";
//$u = "http://www.rnaworld.de/rnaworld/";
//$u = "http://boinc.gorlaeus.net/";
//$u = "https://www.ramanujamachine.com/";
//$x = get_platforms_cached($u);
//print_r($x);
//$x = get_platforms2($u);
//print_r($x);
//echo json_encode($x);
//echo get_platforms_string($u);
// Mediawiki extension to show a project's platforms.
// Doesn't seem to work anymore.
//
function wfPlatforms() {
global $wgParser;
$wgParser->setHook( "platforms", "get_platforms_string" );
}
$wgExtensionFunctions[] = "wfPlatforms";
?>