WebCL - Paralleles Rechnen im Web

 Tutorial
  0: Vorbereitung
  1: Detektor
  2: Platformen und Geräte
  3: Vektoraddition


 Kontakt
 webcl[ät)peter-strohm.de

2 Lokale WebCL Devices ermitteln

>>>> Direkt zum Beispiel <<<<

Da WebCL auf verschiedenen Systemen verwendet werden kann, muss eine WebCL Anwendung ermitteln können, welche WebCL-fähigen Geräte("Devices") in dem lokalen System vorhanden und einsatzbereit sind.

Basis ist in jedem Fall eine OpenCL-Platform auf dem Zielsystem. Dies kann zurzeit (10/2011) z.B.

- das Intel OpenCL SDK
- ein aktuelle nVidia Geforce-Treiber mit CUDA/OpenCL-Support
oder für
- AMD/ATI-Systeme das zugehörige SDK
sein

Jeder Platform können ein oder mehrere (Hardware-)Devices für OpenCL zur Verfügung stehen (z.B. ein AMD Multicore Prozessor UND eine ATI Grafikkarte).

Für komplexere WebCL-Anwendungen kann die Entscheidung wichtig sein, auf welchem Device die Berechnungen ausgeführt werden. Für dieses Beispiel soll es genügen, die im lokalen System vorhandenen Platformen und zugehörigen Devices aufzulisten.
Voraussetzung ist weiterhin das Nokia WebCL-Plugin für Firefox 7.

1<!DOCTYPE html>
2<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
3  <head>
4    <title>WebCL Beispiel 2</title>
5    <script type="text/javascript" id="listWebCLDevices">
6     "use strict";
7        /*global window */ // tells jslint that 'window' is defined!
8
9        function listWebCLDevices() {
10         var
11             outputstring,
12                output,
13                platforms,
14                currentPlatform,
15                platformName,
16                currentPlatformDevices,
17                i, j;
18            outputstring = "";
19            output = window.document.getElementById("output");
20            try {
21                if (window.WebCL === undefined) {
22                    window.alert("Dein System unterst�tzt WebCL nicht. Siehe <a href=\"www.peter-strohm.de/webcl/index.php\">Peters WebCL Seite<\/a>");
23                    return false;
24                }
25
26                // 1. : Die Liste der lokal verf�gbaren WebCL _Platformen_ wird abgerufen.
27                // (jeder Platform k�nnen mehrere Devices zugeordnet sein.
28                platforms = window.WebCL.getPlatformIDs();
29                outputstring += platforms.length + " WebCL Platform(en) gefunden. <br><br>";
30                for (i = 0; i < platforms.length; i = i + 1) {
31                    currentPlatform = platforms[i];
32                    platformName = currentPlatform.getPlatformInfo(window.WebCL.CL_PLATFORM_NAME);
33                    currentPlatformDevices = currentPlatform.getDeviceIDs(window.WebCL.CL_DEVICE_TYPE_ALL);
34                    outputstring += "[" + i + "] \"<b>" + platformName + "<\/b>\"<br>";
35                    outputstring += "<div style='padding-left:2em;'>";
36                    outputstring += "<b>Hersteller:<\/b> " + currentPlatform.getPlatformInfo(window.WebCL.CL_PLATFORM_VENDOR) + "<br \/>";
37                    outputstring += "<b>Version:<\/b> " + currentPlatform.getPlatformInfo(window.WebCL.CL_PLATFORM_VERSION) + "<br \/> ";
38                    for (j = 0; j < currentPlatformDevices.length; j = j + 1) {
39                        outputstring += "[" + j + "] \"<b>" + currentPlatformDevices[j].getDeviceInfo(window.WebCL.CL_DEVICE_NAME) + "<\/b>\"<br \/>";
40                    }
41                    outputstring += "<\/div><br \/>";
42                }
43                output.innerHTML = outputstring + "<br \/>";
44            } catch (e) {
45                output.innerHTML = outputstring + "<br \/>";
46                output.innerHTML += "<b>Error:<\/b> <pre style='color:red;'>" + e.toString() + "<\/pre>";
47                throw e;
48            }
49        }
50        window.onload = function () {
51            listWebCLDevices();
52        };
53
54    </script>
55  </head>
56  <body>
57    <h2>lokale WebCL-Devices (Beispiel 2)</h2>
58    <div id="output">
59    </div>
60    <br />
61    <i>This example is closely based on the <a href="webcl.nokiaresearch.com/tutorials/tutorial2.html">Nokia WebCL Tutorial</a>.</i>
62  </body>
63</html>

Kommentieren:

Name
Email Die Emailadresse wird nicht veröffentlicht und nicht weitergegeben
Kommentar

>> Startseite <<   ^ Seitenanfang ^    
Fehler? Kommentare? webcl ([ät)] peter-strohm Punkt de