From 28efadd162ae3d48c04276da8e971155921d5812 Mon Sep 17 00:00:00 2001 From: Nunigan Date: Sun, 1 Aug 2021 22:50:04 +0200 Subject: update --- buch/papers/multiplikation/code/MM.py | 23 +++++----- buch/papers/multiplikation/code/meas_1024.pdf | Bin 17660 -> 17653 bytes buch/papers/multiplikation/code/meas_1024.txt | 10 ++--- buch/papers/multiplikation/code/meas_128.pdf | Bin 17961 -> 18120 bytes buch/papers/multiplikation/code/meas_128.txt | 10 ++--- buch/papers/multiplikation/code/meas_256.pdf | Bin 18067 -> 19428 bytes buch/papers/multiplikation/code/meas_256.txt | 10 ++--- buch/papers/multiplikation/code/meas_32.pdf | Bin 17078 -> 17964 bytes buch/papers/multiplikation/code/meas_32.txt | 10 ++--- buch/papers/multiplikation/code/meas_64.pdf | Bin 17678 -> 17747 bytes buch/papers/multiplikation/code/meas_64.txt | 10 ++--- buch/papers/multiplikation/loesungsmethoden.tex | 53 +++++++++++++++++++++++- buch/papers/multiplikation/main.tex | 22 ++++++++++ buch/papers/multiplikation/references.bib | 17 ++++++++ 14 files changed, 127 insertions(+), 38 deletions(-) (limited to 'buch') diff --git a/buch/papers/multiplikation/code/MM.py b/buch/papers/multiplikation/code/MM.py index 626b82d..352771f 100644 --- a/buch/papers/multiplikation/code/MM.py +++ b/buch/papers/multiplikation/code/MM.py @@ -174,10 +174,11 @@ def test_perfomance(n): plt.plot(n, t_mm_strassen, label='Strassen', lw=5) plt.plot(n, t_wino, label='Winograd', lw=5) plt.plot(n, t_np, label='NumPy A@B', lw=5) + plt.xscale('log', base=2) plt.legend() plt.xlabel("n") plt.ylabel("time (s)") - plt.grid(True) + plt.grid(True, which="both", ls="-") plt.tight_layout() # plt.yscale('log') plt.legend(fontsize=19) @@ -198,7 +199,7 @@ def plot(num): plt.plot(n, t_mm, label='3 For Loops', lw=5) plt.plot(n, t_mm_dc, label='Divide and Conquer', lw=5) plt.plot(n, t_mm_strassen, label='Strassen', lw=5) - # plt.plot(n, t_wino, label='Winograd', lw=5) + plt.plot(n, t_wino, label='Winograd', lw=5) plt.plot(n, t_np, label='NumPy A@B', lw=5) plt.legend() plt.xlabel("n") @@ -275,22 +276,22 @@ def plot_c_res(ave, num): # test%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if __name__ == '__main__': - plot_c_res(1, 4096) + # plot_c_res(1, 4096) # plot(8) - # n = np.logspace(1,10,10,base=2,dtype=(np.int)) + n = np.logspace(1,8,8,base=2,dtype=(np.int)) # n = np.arange(1,50,2) - A = np.random.randint(-10, 10, (5,3)) - B = np.random.randint(-10, 10, (3,5)) + # A = np.random.randint(-10, 6, (5,3)) + # B = np.random.randint(-10, 6, (3,5)) - C = winograd2(A, B) - C_test = A@B - print(C) - print(C_test) + # C = winograd2(A, B) + # C_test = A@B + # print(C) + # print(C_test) # print(np.equal(C, C_test)) - # t_np = test_perfomance(n) + t_np = test_perfomance(n) # C = strassen(A, B) # C_test = A@B diff --git a/buch/papers/multiplikation/code/meas_1024.pdf b/buch/papers/multiplikation/code/meas_1024.pdf index fd0a108..7b7a133 100644 Binary files a/buch/papers/multiplikation/code/meas_1024.pdf and b/buch/papers/multiplikation/code/meas_1024.pdf differ diff --git a/buch/papers/multiplikation/code/meas_1024.txt b/buch/papers/multiplikation/code/meas_1024.txt index c5ce619..ab507a2 100644 --- a/buch/papers/multiplikation/code/meas_1024.txt +++ b/buch/papers/multiplikation/code/meas_1024.txt @@ -1,6 +1,6 @@ 2.000000000000000000e+00 4.000000000000000000e+00 8.000000000000000000e+00 1.600000000000000000e+01 3.200000000000000000e+01 6.400000000000000000e+01 1.280000000000000000e+02 2.560000000000000000e+02 5.120000000000000000e+02 1.024000000000000000e+03 -1.502037048339843750e-05 6.628036499023437500e-05 4.780292510986328125e-04 2.713203430175781250e-03 2.115225791931152344e-02 1.758832931518554688e-01 1.338865518569946289e+00 1.009106445312500000e+01 8.192077994346618652e+01 7.835870332717895508e+02 -6.675720214843750000e-06 7.200241088867187500e-05 5.540847778320312500e-04 3.144979476928710938e-03 2.545046806335449219e-02 2.083067893981933594e-01 1.659256219863891602e+00 1.319160294532775879e+01 1.046767003536224365e+02 9.679818902015686035e+02 -1.668930053710937500e-05 1.628398895263671875e-04 7.648468017578125000e-04 4.426956176757812500e-03 2.922415733337402344e-02 1.800994873046875000e-01 1.286747694015502930e+00 9.412034273147583008e+00 6.263725924491882324e+01 4.427414393424987793e+02 -2.408027648925781250e-05 8.463859558105468750e-05 4.761219024658203125e-04 2.339839935302734375e-03 1.682758331298828125e-02 1.299476623535156250e-01 1.048770904541015625e+00 8.114667415618896484e+00 6.373566389083862305e+01 6.489995403289794922e+02 -1.573562622070312500e-05 7.152557373046875000e-06 7.152557373046875000e-06 2.074241638183593750e-05 5.388259887695312500e-05 6.365776062011718750e-05 3.257751464843750000e-03 1.396179199218750000e-03 3.274917602539062500e-03 2.186250686645507812e-02 +1.859664916992187500e-05 8.296966552734375000e-05 5.471706390380859375e-04 3.053665161132812500e-03 2.407431602478027344e-02 1.868948936462402344e-01 1.563691616058349609e+00 1.100623321533203125e+01 8.547679090499877930e+01 7.507572824954986572e+02 +8.106231689453125000e-06 9.012222290039062500e-05 7.290840148925781250e-04 4.970788955688476562e-03 2.718997001647949219e-02 2.652802467346191406e-01 1.777865171432495117e+00 1.327002429962158203e+01 1.053971357345581055e+02 8.473208103179931641e+02 +2.098083496093750000e-05 1.742839813232421875e-04 9.438991546630859375e-04 4.754066467285156250e-03 4.852557182312011719e-02 2.204136848449707031e-01 1.447179555892944336e+00 9.938656568527221680e+00 6.396102952957153320e+01 4.614939928054809570e+02 +2.789497375488281250e-05 1.049041748046875000e-04 5.528926849365234375e-04 4.555702209472656250e-03 1.871442794799804688e-02 1.530685424804687500e-01 1.194762229919433594e+00 8.298985958099365234e+00 6.836994743347167969e+01 5.373736469745635986e+02 +1.835823059082031250e-05 7.867813110351562500e-06 1.001358032226562500e-05 5.412101745605468750e-05 4.267692565917968750e-05 1.184940338134765625e-04 2.441406250000000000e-04 6.957054138183593750e-04 2.217054367065429688e-03 1.880884170532226562e-02 diff --git a/buch/papers/multiplikation/code/meas_128.pdf b/buch/papers/multiplikation/code/meas_128.pdf index ed1ec63..c54648f 100644 Binary files a/buch/papers/multiplikation/code/meas_128.pdf and b/buch/papers/multiplikation/code/meas_128.pdf differ diff --git a/buch/papers/multiplikation/code/meas_128.txt b/buch/papers/multiplikation/code/meas_128.txt index 976bbdf..f3a5beb 100644 --- a/buch/papers/multiplikation/code/meas_128.txt +++ b/buch/papers/multiplikation/code/meas_128.txt @@ -1,6 +1,6 @@ 2.000000000000000000e+00 4.000000000000000000e+00 8.000000000000000000e+00 1.600000000000000000e+01 3.200000000000000000e+01 6.400000000000000000e+01 1.280000000000000000e+02 -1.978874206542968750e-05 1.134872436523437500e-04 4.298686981201171875e-04 2.815246582031250000e-03 2.616596221923828125e-02 1.767718791961669922e-01 1.293319463729858398e+00 -6.675720214843750000e-06 1.251697540283203125e-04 4.818439483642578125e-04 3.490447998046875000e-03 2.465796470642089844e-02 2.014584541320800781e-01 1.630620479583740234e+00 -2.408027648925781250e-05 2.126693725585937500e-04 1.172780990600585938e-03 4.364490509033203125e-03 3.148293495178222656e-02 2.010228633880615234e-01 1.429297924041748047e+00 -2.932548522949218750e-05 1.466274261474609375e-04 4.270076751708984375e-04 2.837419509887695312e-03 1.723575592041015625e-02 1.308519840240478516e-01 1.015527009963989258e+00 -3.337860107421875000e-05 1.096725463867187500e-05 9.536743164062500000e-06 3.600120544433593750e-05 2.837181091308593750e-05 5.912780761718750000e-05 1.981019973754882812e-03 +1.239776611328125000e-05 5.507469177246093750e-05 3.888607025146484375e-04 2.762079238891601562e-03 2.097773551940917969e-02 1.672370433807373047e-01 1.410297393798828125e+00 +5.483627319335937500e-06 5.888938903808593750e-05 3.871917724609375000e-04 3.364324569702148438e-03 2.481031417846679688e-02 2.047052383422851562e-01 1.712310314178466797e+00 +1.358985900878906250e-05 1.189708709716796875e-04 6.430149078369140625e-04 5.586385726928710938e-03 3.101944923400878906e-02 1.874091625213623047e-01 1.327976465225219727e+00 +1.978874206542968750e-05 7.224082946777343750e-05 4.618167877197265625e-04 3.294944763183593750e-03 1.755571365356445312e-02 1.360688209533691406e-01 1.028253555297851562e+00 +1.215934753417968750e-05 5.722045898437500000e-06 2.074241638183593750e-05 4.339218139648437500e-05 2.813339233398437500e-05 5.292892456054687500e-05 1.921653747558593750e-04 diff --git a/buch/papers/multiplikation/code/meas_256.pdf b/buch/papers/multiplikation/code/meas_256.pdf index 5f049dc..4ca7102 100644 Binary files a/buch/papers/multiplikation/code/meas_256.pdf and b/buch/papers/multiplikation/code/meas_256.pdf differ diff --git a/buch/papers/multiplikation/code/meas_256.txt b/buch/papers/multiplikation/code/meas_256.txt index 15035c6..2ca4447 100644 --- a/buch/papers/multiplikation/code/meas_256.txt +++ b/buch/papers/multiplikation/code/meas_256.txt @@ -1,6 +1,6 @@ 2.000000000000000000e+00 4.000000000000000000e+00 8.000000000000000000e+00 1.600000000000000000e+01 3.200000000000000000e+01 6.400000000000000000e+01 1.280000000000000000e+02 2.560000000000000000e+02 -1.049041748046875000e-05 5.340576171875000000e-05 5.936622619628906250e-04 2.707719802856445312e-03 2.246093750000000000e-02 1.631326675415039062e-01 1.335460901260375977e+00 1.052024245262145996e+01 -4.768371582031250000e-06 5.531311035156250000e-05 8.208751678466796875e-04 3.099203109741210938e-03 2.490711212158203125e-02 2.070860862731933594e-01 1.739669799804687500e+00 1.384817218780517578e+01 -1.478195190429687500e-05 1.132488250732421875e-04 5.970001220703125000e-04 3.906726837158203125e-03 3.041696548461914062e-02 2.000186443328857422e-01 1.392681598663330078e+00 9.388872385025024414e+00 -1.716613769531250000e-05 6.866455078125000000e-05 5.314350128173828125e-04 2.688407897949218750e-03 1.695108413696289062e-02 1.297233104705810547e-01 1.087257385253906250e+00 8.699601650238037109e+00 -2.336502075195312500e-05 4.529953002929687500e-06 8.106231689453125000e-06 4.291534423828125000e-05 6.008148193359375000e-05 8.988380432128906250e-05 1.647472381591796875e-04 4.460811614990234375e-04 +1.096725463867187500e-05 5.531311035156250000e-05 3.712177276611328125e-04 2.662897109985351562e-03 2.111244201660156250e-02 1.660463809967041016e-01 1.280746459960937500e+00 1.149287748336791992e+01 +5.483627319335937500e-06 5.745887756347656250e-05 4.055500030517578125e-04 3.203868865966796875e-03 2.503871917724609375e-02 2.148163318634033203e-01 1.655935287475585938e+00 1.472915720939636230e+01 +1.335144042968750000e-05 1.153945922851562500e-04 6.134510040283203125e-04 3.850460052490234375e-03 2.817606925964355469e-02 1.827111244201660156e-01 1.277473211288452148e+00 9.337273359298706055e+00 +1.907348632812500000e-05 9.274482727050781250e-05 3.526210784912109375e-04 2.403974533081054688e-03 1.725149154663085938e-02 1.314754486083984375e-01 1.121860027313232422e+00 8.884316682815551758e+00 +3.147125244140625000e-05 6.675720214843750000e-06 4.768371582031250000e-06 7.867813110351562500e-06 2.574920654296875000e-05 5.888938903808593750e-05 2.071857452392578125e-04 6.518363952636718750e-04 diff --git a/buch/papers/multiplikation/code/meas_32.pdf b/buch/papers/multiplikation/code/meas_32.pdf index 94c3731..b926095 100644 Binary files a/buch/papers/multiplikation/code/meas_32.pdf and b/buch/papers/multiplikation/code/meas_32.pdf differ diff --git a/buch/papers/multiplikation/code/meas_32.txt b/buch/papers/multiplikation/code/meas_32.txt index afdb6d5..0fdc18d 100644 --- a/buch/papers/multiplikation/code/meas_32.txt +++ b/buch/papers/multiplikation/code/meas_32.txt @@ -1,6 +1,6 @@ 2.000000000000000000e+00 4.000000000000000000e+00 8.000000000000000000e+00 1.600000000000000000e+01 3.200000000000000000e+01 -1.215934753417968750e-05 5.459785461425781250e-05 3.700256347656250000e-04 3.249406814575195312e-03 1.996850967407226562e-02 -4.529953002929687500e-06 5.650520324707031250e-05 4.577636718750000000e-04 4.029273986816406250e-03 2.444481849670410156e-02 -1.311302185058593750e-05 1.165866851806640625e-04 6.275177001953125000e-04 4.323244094848632812e-03 2.624726295471191406e-02 -1.835823059082031250e-05 6.890296936035156250e-05 3.914833068847656250e-04 2.423048019409179688e-03 1.761770248413085938e-02 -1.263618469238281250e-05 5.006790161132812500e-06 5.960464477539062500e-06 1.144409179687500000e-05 3.600120544433593750e-05 +1.239776611328125000e-05 5.507469177246093750e-05 3.802776336669921875e-04 2.795457839965820312e-03 2.073740959167480469e-02 +5.006790161132812500e-06 5.841255187988281250e-05 3.988742828369140625e-04 3.505229949951171875e-03 2.511668205261230469e-02 +1.335144042968750000e-05 1.149177551269531250e-04 6.387233734130859375e-04 4.088878631591796875e-03 2.969408035278320312e-02 +1.955032348632812500e-05 8.058547973632812500e-05 3.998279571533203125e-04 2.514839172363281250e-03 1.842117309570312500e-02 +1.215934753417968750e-05 8.583068847656250000e-06 6.675720214843750000e-06 2.694129943847656250e-05 2.789497375488281250e-05 diff --git a/buch/papers/multiplikation/code/meas_64.pdf b/buch/papers/multiplikation/code/meas_64.pdf index 3a90949..92af29b 100644 Binary files a/buch/papers/multiplikation/code/meas_64.pdf and b/buch/papers/multiplikation/code/meas_64.pdf differ diff --git a/buch/papers/multiplikation/code/meas_64.txt b/buch/papers/multiplikation/code/meas_64.txt index ae6ff9b..b4fc7a1 100644 --- a/buch/papers/multiplikation/code/meas_64.txt +++ b/buch/papers/multiplikation/code/meas_64.txt @@ -1,6 +1,6 @@ 2.000000000000000000e+00 4.000000000000000000e+00 8.000000000000000000e+00 1.600000000000000000e+01 3.200000000000000000e+01 6.400000000000000000e+01 -1.645088195800781250e-05 7.295608520507812500e-05 3.807544708251953125e-04 2.672195434570312500e-03 2.010774612426757812e-02 1.662156581878662109e-01 -7.390975952148437500e-06 7.843971252441406250e-05 4.265308380126953125e-04 3.107070922851562500e-03 2.457642555236816406e-02 2.122807502746582031e-01 -1.931190490722656250e-05 1.568794250488281250e-04 7.593631744384765625e-04 3.937005996704101562e-03 3.596329689025878906e-02 2.131938934326171875e-01 -2.622604370117187500e-05 9.226799011230468750e-05 3.504753112792968750e-04 2.469539642333984375e-03 1.652932167053222656e-02 1.281068325042724609e-01 -1.788139343261718750e-05 7.152557373046875000e-06 6.914138793945312500e-06 1.120567321777343750e-05 2.884864807128906250e-05 6.914138793945312500e-05 +2.145767211914062500e-05 6.175041198730468750e-05 4.422664642333984375e-04 3.235816955566406250e-03 2.289748191833496094e-02 1.855163574218750000e-01 +1.025199890136718750e-05 6.341934204101562500e-05 5.202293395996093750e-04 3.566026687622070312e-03 3.026723861694335938e-02 2.312932014465332031e-01 +2.384185791015625000e-05 1.807212829589843750e-04 6.821155548095703125e-04 4.796504974365234375e-03 2.968001365661621094e-02 2.291278839111328125e-01 +3.504753112792968750e-05 1.106262207031250000e-04 4.322528839111328125e-04 2.696514129638671875e-03 2.188420295715332031e-02 1.477701663970947266e-01 +3.218650817871093750e-05 1.144409179687500000e-05 7.390975952148437500e-06 4.625320434570312500e-05 3.814697265625000000e-05 5.435943603515625000e-05 diff --git a/buch/papers/multiplikation/loesungsmethoden.tex b/buch/papers/multiplikation/loesungsmethoden.tex index 7ee0b6e..0f6aa6b 100755 --- a/buch/papers/multiplikation/loesungsmethoden.tex +++ b/buch/papers/multiplikation/loesungsmethoden.tex @@ -295,9 +295,58 @@ Die Implementation kann Algorithmus \ref{multiplikation:alg:winograd} entnommen \end{algorithmic} \end{algorithm} -\subsection{Weitere Algorithmen} +\subsection{Basic Linear Algebra Subprograms (BLAS)} + +die gebr\"uchlichen Methode f\"ur die Anwendung einer optimierten Matrizenmultiplikation ist die Verwendung einer Subrutine aus den \textit{Basic Linear Algebra Subprograms (BLAS)} \cite{multiplikation:BLAS}. +Die meisten Numerischen Bibliotheken von High-Level Skriptsprachen wie \texttt{Matlab}, \texttt{NumPy (Python)}, \texttt{GNU Octave} oder \texttt{Mathematica} ben\"utzen eine Form von \textit{BLAS}. + +\textit{BLAS} sind dabei in drei unterschiedliche Levels aufgeteilt. + +\begin{itemize} + \item Level 1 + \begin{itemize} + \item Operationen der Art: $\mathbf{y} \leftarrow \alpha \mathbf{x}+\mathbf{y}$ + \item Dieses Level hat $\mathcal{O}(n)$ karakteristik + \end{itemize} + \item Level 2 + \begin{itemize} + \item Operationen der Art: $\mathbf{y} \leftarrow \alpha \mathbf{A}\mathbf{x}+\beta \mathbf{y}$ + \item Dieses Level hat $\mathcal{O}\left(n^2\right)$ karakteristik + \end{itemize} + \item Level 3 + \begin{itemize} + \item Operationen der Art: $\mathbf{C} \leftarrow \alpha \mathbf{A}\mathbf{B}+\beta\mathbf{C}$ + \item Dieses Level hat $\mathcal{O}\left(n^3\right)$ karakteristik + \end{itemize} +\end{itemize} + +Die \textit{BLAS} sind auf die modernen Computer Prozessoren optimiert und k\"onnen dank einer ausgek\"ugelter Verwedung der Speicher Architektur zur erheblichen Leistungoprimierung f\"uhren. + + +\subsubsection{General Matrix Multiplication (GEMM)} + +Die \textit{Double-GEMM} ist in \cite{multiplikation:DGEMM} definiert als: + +\textit{DGEMM performs one of the matrix-matrix operations} +$$ + C := \alpha \cdot op( A )\cdot op( B ) + \beta \cdot C, + $$ + \textit{where op( X ) is one of} +$$ +op( X ) = X \quad \text{ or } \quad op( X ) = X^T, +$$ + \textit{alpha and beta are scalars, and A, B and C are matrices, with op( A ) + an m by k matrix, op( B ) a k by n matrix and C an m by n matrix. + } + +Die Implementaion von $\alpha\mathbf{A}\mathbf{B} + \beta \mathbf{C} = \mathbf{C}$, wobei $\alpha = 1.0$ und $\beta = 0.0$ in der \texttt{C}-Version von \textit{BLAS}, ist als +\begin{lstlisting}[style=multiplikationC] +cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, + m, n, k, 1, A, m , B, k, 0, C, m); +\end{lstlisting} +definiert. + -\textcolor{red}{TODO: BLAS} \section{Implementation} \rhead{Implementation} diff --git a/buch/papers/multiplikation/main.tex b/buch/papers/multiplikation/main.tex index 8d0a8df..fb1908e 100755 --- a/buch/papers/multiplikation/main.tex +++ b/buch/papers/multiplikation/main.tex @@ -4,6 +4,28 @@ % % (c) 2021 Hochschule Rapperswil % +\definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue +\definecolor{mylilas}{RGB}{170,55,241} +\definecolor{backcolour}{rgb}{0.95,0.95,0.92} +\lstdefinestyle{multiplikationC}{ + numbers=left, + belowcaptionskip=1\baselineskip, + breaklines=true, + frame=l, + framerule=0pt, + framesep=-1pt, + xleftmargin=1em, + language=C, + showstringspaces=false, + basicstyle=\ttfamily, + keywordstyle=\bfseries\color{green!40!black}, + commentstyle=\itshape\color{purple!40!black}, + identifierstyle=\color{blue}, + stringstyle=\color{red}, + numberstyle=\ttfamily\tiny, + backgroundcolor=\color{backcolour} +} + \chapter{Schnelle Matrizen Multiplikation\label{chapter:multiplikation}} \lhead{FMM} \begin{refsection} diff --git a/buch/papers/multiplikation/references.bib b/buch/papers/multiplikation/references.bib index 63cb976..8815386 100755 --- a/buch/papers/multiplikation/references.bib +++ b/buch/papers/multiplikation/references.bib @@ -83,3 +83,20 @@ day = {28} } +@online{multiplikation:BLAS, + title = {BLAS (Basic Linear Algebra Subprograms)}, + url = {http://www.netlib.org/blas/}, + date = {2021-08-01}, + year = {2021}, + month = {8}, + day = {01} +} + +@online{multiplikation:DGEMM, + title = {DGEMM}, + url = {http://www.netlib.org/lapack/explore-html/d1/d54/group__double__blas__level3_gaeda3cbd99c8fb834a60a6412878226e1.html#gaeda3cbd99c8fb834a60a6412878226e1}, + date = {2021-08-01}, + year = {2021}, + month = {8}, + day = {01} +} -- cgit v1.2.1