Minimale GPUCalc Library (OpenGL)

Anwendungen, Tools, Userlibs und anderes nützliches.
DarkDragon
Beiträge: 6291
Registriert: 29.08.2004 08:37
Computerausstattung: Hoffentlich bald keine mehr
Kontaktdaten:

Minimale GPUCalc Library (OpenGL)

Beitrag 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. :)
Zuletzt geändert von DarkDragon am 12.03.2009 17:14, insgesamt 4-mal geändert.
Angenommen es gäbe einen Algorithmus mit imaginärer Laufzeit O(i * n), dann gilt O((i * n)^2) = O(-1 * n^2) d.h. wenn man diesen Algorithmus verschachtelt ist er fertig, bevor er angefangen hat.
Benutzeravatar
Falko
Admin
Beiträge: 3535
Registriert: 29.08.2004 11:27
Computerausstattung: PC: MSI-Z590-GC; 32GB-DDR4, ICore9; 2TB M2 + 2x3TB-SATA2 HDD; Intel ICore9 @ 3600MHZ (Win11 Pro. 64-Bit),
Acer Aspire E15 (Win11 Home X64). Purebasic LTS 6.11b1
HP255G8 Notebook @AMD Ryzen 5 5500U with Radeon Graphics 2.10 GHz 3.4GHz, 32GB_RAM, 3TB_SSD (Win11 Pro 64-Bit)
Kontaktdaten:

Beitrag 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
Zuletzt geändert von Falko am 10.03.2009 22:25, insgesamt 1-mal geändert.
Bild
Win11 Pro 64-Bit, PB_6.11b1
Benutzeravatar
cxAlex
Beiträge: 2111
Registriert: 26.06.2008 10:42

Beitrag 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...)
Projekte: IO.pbi, vcpu
Pausierte Projekte: Easy Network Manager, µC Emulator
Aufgegebene Projekte: ECluster

Bild

PB 5.1 x64/x86; OS: Win7 x64/Ubuntu 10.x x86
Benutzeravatar
milan1612
Beiträge: 810
Registriert: 15.04.2007 17:58

Beitrag 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)...
Bin nur noch sehr selten hier, bitte nur noch per PN kontaktieren
Benutzeravatar
X0r
Beiträge: 2770
Registriert: 15.03.2007 21:47
Kontaktdaten:

Beitrag von X0r »

Also Milans Werte finde ich mal ziemlich unrealistisch. Ne GTX 260 hat in solchen Sachen bei weitem mehr Power als ne 8400.
Benutzeravatar
Blackskyliner
Beiträge: 532
Registriert: 28.07.2005 00:54
Wohnort: /home/Blackskyliner/

Beitrag 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_.
Keine meiner Antworten ist endgültig, es kann passieren, dass ich den so eben geposteten Beitrag noch mehrmals ändere, um Doppelposts zu umgehen.
_________________
Purebasic Windows 7 x64 & Linux (Ubuntu 10.04LTS) 4.50[x64|x86] Nutzer
_________________
Projekte: YAED - Yet another Event Dispatcher
Benutzeravatar
KeyKon
Beiträge: 1412
Registriert: 10.09.2004 20:51
Computerausstattung: Laptop: i5 2,8 Ghz, 16GB DDR3 RAM, GeForce 555GT 2GB VRAM
PC: i7 4,3 Ghz, 32GB DDR3 RAM, GeForce 680 GTX 4GB VRAM
Win10 x64 Home/Prof
PB 5.30 (64bit)
Wohnort: Ansbach
Kontaktdaten:

Beitrag von KeyKon »

Was heißt Bug^^
Nur weil es nich die komplette Geschwindigkeit ausnutzen kann isses ja kein Bug solange es funktioniert...
(\/) (°,,,°) (\/)
Benutzeravatar
Froggerprogger
Badmin
Beiträge: 855
Registriert: 08.09.2004 20:02

Beitrag 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.
!UD2
DarkDragon
Beiträge: 6291
Registriert: 29.08.2004 08:37
Computerausstattung: Hoffentlich bald keine mehr
Kontaktdaten:

Beitrag 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.
Angenommen es gäbe einen Algorithmus mit imaginärer Laufzeit O(i * n), dann gilt O((i * n)^2) = O(-1 * n^2) d.h. wenn man diesen Algorithmus verschachtelt ist er fertig, bevor er angefangen hat.
Benutzeravatar
cxAlex
Beiträge: 2111
Registriert: 26.06.2008 10:42

Beitrag 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
Projekte: IO.pbi, vcpu
Pausierte Projekte: Easy Network Manager, µC Emulator
Aufgegebene Projekte: ECluster

Bild

PB 5.1 x64/x86; OS: Win7 x64/Ubuntu 10.x x86
Antworten