Lineare Algebra Softwareprojekt: Anwendung von Algorithmen Sebastian Kürten, Philipp Borgers SoSe 2010
Status ● Matrixmultiplikation: ● Eingabegröße: quadratisch, vielfaches der Blockgröße ● Beliebige Eingabegrößen ● Gaussalgorithmus: ● Obere Dreiecksform ● Determinante ● Beliebige Eingabegrößen ● Jordan (Eliminierung rückwärts) ● Eigenwerte
Einteilung in Blöcke
Zugriff auf Blöcke ==== CPU ==== A,B,C // Matrizen N // Größe der Matrizen BLOCK = 32// Größe eines Blocks numBlocks(N / BLOCK, N / BLOCK) numThreads(32, 8) kernel >>(A,B,C) === Kernel ==== __shared__ rows[32*32] __shared__ cols[32*32] __shared__ temp[32*32] initialisiere temp zu 0 #sumatrices = N / BLOCK for s = 1,...,#submatrices: load submatrix of A to rows load submatrix of B to cols temp += rows * cols; write temp to C
Submatrix 32x32 Einträge
4 Schritte im Thread-Block 32x8 Threads
Zugriff auf die Bänke
Problematische Eingaben günstig ungünstig
Problematische Eingaben günstig ungünstig for s = 1,...,#submatrices: load submatrix of A to rows load submatrix of B to cols temp += rows * cols; write temp to C
Lineare Gleichungssysteme Problem: ● Eliminierung des i-ten Werts in der k-ten Zeile hängt von der Eliminierung der vorangehenden i-1, i-2,... Werte ab. ● Algorithmus somit inhärent sequentiell. Lösungsansatz: ● Ändern der Operationsreihenfolge, sodass möglichst viele Operation parallel erfolgen können.
Iterationsschritte b{ n
Kernelaufrufe
Matrixmultiplikation
LGS - Stabilität ● Gaussalgorithmus besitzt ungünstige Stabilitätseigenschaften ● Lösungsansätze: ● Restklassenkörper ● Pivotisierung
Determinante ● Determinante durch Gaussverfahren ermitteln. ● Bei einer Dreiecksmatrix das Produkt der Hauptdiagonale ● Problem: Zeilentausch -> Vorzeichenwechsel der Determinante ● Lösung: Zeilentausch merken
TODO ● Beschränkung auf vielfache der Blockgröße aufheben ● Berechnungen auf nicht quadratischen Matrizen ● Gauss-Jordan-Elimierung
==================================================================================================== Problem size: 512 x 512 ==================================================================================================== matrix multiplication on CPU CPU time: s matrix multiplication on GPU GPU time: s Checksum: Integrity test: SUCCESS Ratio(GPU:CPU): 1 : ==================================================================================================== Problem size: 1024 x 1024 ==================================================================================================== matrix multiplication on CPU CPU time: s matrix multiplication on GPU GPU time: s Checksum: Integrity test: SUCCESS Ratio(GPU:CPU): 1 : ==================================================================================================== Problem size: 2048 x 2048 ==================================================================================================== matrix multiplication on CPU CPU time: s matrix multiplication on GPU GPU time: s Checksum: Integrity test: SUCCESS Ratio(GPU:CPU): 1 : ==================================================================================================== Matrix Multiplikation
==================================================================================================== Problem size: 256 ==================================================================================================== CPU Determinante: 1 time spent in kernels: #swaps: 21 CUDA Determinante: 1 Time(CPU:CUDA): : ==================================================================================================== Problem size: 512 ==================================================================================================== CPU Determinante: 0 time spent in kernels: #swaps: 41 CUDA Determinante: 0 Time(CPU:CUDA): : ==================================================================================================== Problem size: 1024 ==================================================================================================== CPU Determinante: 6 time spent in kernels: #swaps: 85 CUDA Determinante: 6 Time(CPU:CUDA): : ==================================================================================================== Problem size: 2048 ==================================================================================================== CPU Determinante: 9 time spent in kernels: #swaps: 167 CUDA Determinante: 9 Time(CPU:CUDA): : ==================================================================================================== Obere Dreiecksform