Seite 1 von 3

Minimale GPUCalc Library (OpenGL)

Verfasst: 10.03.2009 19:04
von DarkDragon
Hallo,

GPUCalc ist eine Bibliothek mit einfachen Funktionen um 2 Float-Datensätze auf der Grafikkarte mit einander zu verrechnen. Dabei müssen die Datensätze eine konstante Größe haben, die im Vorraus festgelegt wird.

Beispielszenario:
  • Code: "vec3 calc(int startOffset) { return getData(0, startOffset) + getData(1, startOffset); }"
  • Daten-Anzahl: 3
  • Datensatz A: 0.5, 0.6, 0.7
  • Datensatz B: 1.5, 1.6, 1.7
Dann ist das Resultat
0.5 + 1.5 = 2.0
0.6 + 1.6 = 2.2
0.7 + 1.7 = 2.4

Datensatz Resultat (Abgekürzt R): 2.0, 2.2, 2.4

Da das ganze auf OpenGL und GLSL basiert braucht ihr natürlich neue Grafikkartentreiber und eine Grafikkarte mit OpenGL ~2.0 Support (Schätze ich - ich hab jetzt nicht alles nachgeprüft).

Es ist mehr ein Experiment als ein nützliches Projekt.

Download

Hier auf meinem PC ist es schneller auf der Grafikkarte als auf dem CPU (Könnte man zwar sicher noch so optimieren, dass es auf der CPU schneller ist, aber das ist mir erstmal egal, weil es ja nur ein Experiment war), aber es gibt sicher viele Systeme, bei denen das nicht der Fall ist (Low-End Grafikkarten und AGP Nutzer evtl.) weil die Implementierung und das Beispiel nicht die/das beste ist.

Je Größer der Datensatz oder je komplexer die Formel ist, desto schneller ist es auf der Grafikkarte, allerdings ist er momentan auf wenige Daten eingeschränkt, da ich Uniform Variablen anstelle von Texturen für die Übertragung nutze.

Achja und noch ein Vorteil: Man kann dadurch eine Eval-Funktion realisieren, bei der man sicher sein kann, dass sie geht ;-) .

Hier noch eine Funktionsliste für die Formel:
http://wiki.delphigl.com/index.php/Tuto ... Funktionen

Und hier eine kleine Befehlsreferenz für die DLL:

Code: Alles auswählen

-------------------------------------------------
 InitGPUCalculations()
 
 Desc.:   Initializes everything to have access
          to the GPU
 Returns: 0 if it fails, otherwise 1.
 
-------------------------------------------------
 BindCodeGPUFloat32(Code.s)
 
 Desc.:   Creates a new shadercontext with the
          specified code.
 Returns: 0 if it fails, otherwise 1.
 
-------------------------------------------------
 CalculateDatasetGPUFloat32(*DatasetResult)
 
 Desc.:   Calculates new float values with the
          bound code and the datasets which are
          loaded into the gpu.
 Returns: 0 if it fails, otherwise 1.
 
-------------------------------------------------
 UnbindCodeGPU()
 
 Desc.:   Releases the last shadercontext, which
          was bound before.
 
-------------------------------------------------
 ReleaseGPUCalculations()
 
 Desc.:   Releases the GPU access.
 
-------------------------------------------------
 GetLastGPUCalculationsError()
 
 Desc.:   Returns the last error as pointer to a
          String.
 Returns: Pointer to a zero terminated string,
          containing the error message (or empty
          if there was no error).
 
-------------------------------------------------
 AllocateGPUDatasetMemory()
 
 Desc.:   Allocates a memory block of 64x64x3 B.
          It will ensure, that this block has
          always this size (Its important).
 Returns: Pointer to the memory block.
 
-------------------------------------------------
 ReleaseGPUDatasetMemory(*Dataset)
 
 Desc.:   Releases the memory block which was
          allocated with AllocateGPUDatasetMemory
 
-------------------------------------------------
 SetDatasetGPUFloat32(Index.l, *Dataset)
 
 Desc.:   Loads the dataset into the GPU.
          The dataset has to be allocated (with
          AllocateGPUDatasetMemory) and filled
          with data before.
 
-------------------------------------------------
ES GEHT EIGENTLICH NICHT UM GESCHWINDIGKEIT FÜR MICH!

Viel spaß damit. :)

Verfasst: 10.03.2009 21:46
von Falko
Danke, DD

Nun weiß ich, das meine Core2Duo CPU schneller als meine Gainward Bliss 8500GT PCX ist.

Mal schauen, was man damit alles anfangen kann :allright:

Gruß, Falko

Verfasst: 10.03.2009 22:16
von cxAlex
Ich bekomm so viele Fehler angezeigt das ich das "Ok" bei der Messagebox nicht mehr seh... :cry: :o .

Jetzt weis ich nicht ob meine GForce 7200 GS schneller ist als mei 3.1 GHz Quad Intel. Ich nehm mal an das die GraKa einfach zu alt ist. (Noch 1, 2 Monate warten, dann ist die GTX 260 sicher in nem annehmbaren Berreich...)

Verfasst: 10.03.2009 23:07
von milan1612
Time needed for GPU Calculation (30000 times): 1641ms
Dataset A: 0.00 0.10 0.20 0.30 0.40 0.50 [...]
Dataset B: 0.00 0.10 0.10 0.10 0.10 0.10 [...]
------------------------------------------------------

Dataset R: 0.00 0.00 0.02 0.05 0.10 0.18 [...]


Time needed for CPU Calculation (30000 times): 1531ms
Dataset A: 0.00 0.10 0.20 0.30 0.40 0.50 [...]
Dataset B: 0.00 0.10 0.10 0.10 0.10 0.10 [...]
------------------------------------------------------

Dataset R: 0.00 0.00 0.02 0.05 0.10 0.18 [...]
Ich hab nen Core2Duo 8400 auf 3600 MHz und ne GTX 260 (216 Shader Units)...

Verfasst: 10.03.2009 23:21
von X0r
Also Milans Werte finde ich mal ziemlich unrealistisch. Ne GTX 260 hat in solchen Sachen bei weitem mehr Power als ne 8400.

Verfasst: 10.03.2009 23:25
von Blackskyliner
Gut erkannt, nicht aber, wenn ein Bug diverse Vorteile verhindert ;)
Und ich denke mal dass er damit andeuten wollte, dass da warscheinlich ein Bug sein _könnte_.

Verfasst: 11.03.2009 01:50
von KeyKon
Was heißt Bug^^
Nur weil es nich die komplette Geschwindigkeit ausnutzen kann isses ja kein Bug solange es funktioniert...

Verfasst: 11.03.2009 08:55
von Froggerprogger
Ich vermute mal, dass eben nur 1 einzelner Shader den Kernel ausführt, da bleiben noch 215 IDLE.
Wer GPU-Computing auf der Grafikkarte machen möchte ohne sich sonderlich um Shaderprogrammierung kümmern zu wollen, sollte sich mal CUDA von NVIDIA ansehen: http://www.nvidia.de/object/cuda_what_is_de.html

Damit habe ich mittlerweile schon einiges gemacht, und je nach Problemstellung (z.B. Matrixmultiplikation zwei sehr großer oder sehr vieler kleiner Matrizen) ist die GPU *wesentlich* schneller - solange die Aufgabe sinnvoll auf alle Shadereinheiten verteilt wird und auch sonst diverse weitere Optimierungen beachtet werden.

Verfasst: 11.03.2009 10:05
von DarkDragon
Wie ich schon sagte, je komplexer die Formel und je mehr Daten es gibt, desto schneller. Hier sind nur kleine Datensätze (aufgrund der Tatsache, dass ich die Daten per Uniform-Array rüberlade und nicht als Textur). Und desshalb ist es nur geringfügig schneller.

Wie schon gesagt, es ist nur ein Experiment, wie man sowas machen könnte und heißt nicht, dass es einen Geschwindigkeitsvorteil bringen soll.

@cxAlex: Copy'n'Paste (Strg + C, Strg + V) hilft ;-) . Und ich glaube du solltest den Grafikkartentreiber updaten.

@Froggerprogger: Ja, CUDA hab ich auch mal angeschaut, nur mich stört die Tatsache, dass das nicht mit ATI Karten läuft und somit nur die hälfte aller Nutzer erreichen könnte. Damit hat man allerdings auch mehr Möglichkeiten. Mit GLSL kann man leider nur einen Shader zu einem Zeitpunkt ausführen (Vielleicht hat sich das mit OpenGL 3.0 geändert, müsste ich nachschauen - ich glaube allerdings nicht, weil ich da nur von Umstrukturierung hinsichtlich Includes etc. gelesen habe).

@XOr: Doch die Werte stimmen. Ich habs ja nicht auf Performance abgesehen gehabt, aber wenn ich ja schon dabei war hab ich eine Zeitmessung halt eingebaut.

Da gibts noch massig Optimierungsmöglichkeiten, die ich aber aus Motivationsgründen nicht weiter implementieren will.

Meine Werte (XFX GeForce 8600 GT vs. Intel Q6600):

Code: Alles auswählen

Time needed for GPU Calculation (30000 times): 1922ms
Dataset A: 0.00 0.10 0.20 0.30 0.40 0.50 [...]
Dataset B: 0.00 0.10 0.10 0.10 0.10 0.10 [...]
--------------------------------------------------------------------------------

Dataset R: 0.00 0.00 0.02 0.05 0.10 0.18 [...]


Time needed for CPU Calculation (30000 times): 2641ms
Dataset A: 0.00 0.10 0.20 0.30 0.40 0.50 [...]
Dataset B: 0.00 0.10 0.10 0.10 0.10 0.10 [...]
--------------------------------------------------------------------------------

Dataset R: 0.00 0.00 0.02 0.05 0.10 0.18 [...]

Press any key to exit.

Verfasst: 11.03.2009 17:37
von cxAlex
@DD: Treiber ist auf dem aktuellsten Stand. Hier der Fehlertext:
gpuCalc hat geschrieben:Linker error:

Fragment info
-------------
0(7) : warning C7011: implicit cast from "int" to "float"
0(7) : warning C7011: implicit cast from "float" to "int"
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
0(8) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable