X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/kahina_paper2.git/blobdiff_plain/867e83f7cceed45f069eddbdc5ae04562f715ddb..8cb4e1e3048615d5455cee20b809f88c4721c21d:/paper.tex diff --git a/paper.tex b/paper.tex index 49cd195..f44826f 100644 --- a/paper.tex +++ b/paper.tex @@ -328,6 +328,10 @@ \todo[color=red!10,#1]{\sffamily\textbf{LZK:} #2}\xspace} \newcommand{\RC}[2][inline]{% \todo[color=blue!10,#1]{\sffamily\textbf{RC:} #2}\xspace} +\newcommand{\KG}[2][inline]{% + \todo[color=green!10,#1]{\sffamily\textbf{KG:} #2}\xspace} +\newcommand{\AS}[2][inline]{% + \todo[color=orange!10,#1]{\sffamily\textbf{AS:} #2}\xspace} @@ -715,8 +719,8 @@ where: \begin{eqnarray} \label{Log_H1} Q(z^{k}_{i})=\exp\left( \ln (p(z^{k}_{i}))-\ln(p'(z^{k}_{i}))+\ln \left( -\sum_{i\neq j}^{n}\frac{1}{z^{k}_{i}-z^{k}_{j}}\right)\right)\\ -i=1,...,n, \nonumber +\sum_{i\neq j}^{n}\frac{1}{z^{k}_{i}-z^{k}_{j}}\right)\right) \nonumber \\ +i=1,...,n \end{eqnarray} @@ -727,41 +731,52 @@ Using the logarithm and the exponential operators, we can replace any multiplic %propose to use the logarithm and the exponential of a complex in order to compute the power at a high exponent. Using the logarithm and the exponential operators, we can replace any multiplications and divisions with additions and subtractions. Consequently, computations manipulate lower absolute values and the roots for large polynomial degrees can be looked for successfully~\cite{Karimall98}. \subsection{Ehrlich-Aberth parallel implementation on CUDA} -We introduced three paradigms of parallel programming. Our objective consists in implementing a root finding polynomial algorithm on multiple GPUs. To this end, it is primordial to know how to manage CUDA contexts of different GPUs. A direct method for controlling the various GPUs is to use as many threads or processes as GPU devices. We can choose the GPU index based on the identifier of OpenMP thread or the rank of the MPI process. Both approaches will be investigated. - - - - -Like any parallel code, a GPU parallel implementation first -requires to determine the sequential tasks and the -parallelizable parts of the sequential version of the -program/algorithm. In our case, all the operations that are easy -to execute in parallel must be made by the GPU to accelerate -the execution of the application, like the step 3 and step 4. On the other hand, all the -sequential operations and the operations that have data -dependencies between threads or recursive computations must -be executed by only one CUDA or CPU thread (step 1 and step 2). Initially, we specify the organization of parallel threads, by specifying the dimension of the grid Dimgrid, the number of blocks per grid DimBlock and the number of threads per block. - -The code is organized by what is named kernels, portions code that are run on GPU devices. For step 3, there are two kernels, the -first named \textit{save} is used to save vector $Z^{K-1}$ and the seconde one is named -\textit{update} and is used to update the $Z^{K}$ vector. For step 4, a kernel -tests the convergence of the method. In order to -compute the function H, we have two possibilities: either to use -the Jacobi mode, or the Gauss-Seidel mode of iterating which uses the -most recent computed roots. It is well known that the Gauss- -Seidel mode converges more quickly. So, we used the Gauss-Seidel mode of iteration. To -parallelize the code, we created kernels and many functions to -be executed on the GPU for all the operations dealing with the +%We introduced three paradigms of parallel programming. + +Our objective consists in implementing a root finding polynomial +algorithm on multiple GPUs. To this end, it is primordial to know how +to manage CUDA contexts of different GPUs. A direct method for +controlling the various GPUs is to use as many threads or processes as +GPU devices. We can choose the GPU index based on the identifier of +OpenMP thread or the rank of the MPI process. Both approaches will be +investigated. + + + + +Like any parallel code, a GPU parallel implementation first requires +to determine the sequential tasks and the parallelizable parts of the +sequential version of the program/algorithm. In our case, all the +operations that are easy to execute in parallel must be made by the +GPU to accelerate the execution of the application, like the step 3 +and step 4. On the other hand, all the sequential operations and the +operations that have data dependencies between threads or recursive +computations must be executed by only one CUDA or CPU thread (step 1 +and step 2). Initially, we specify the organization of parallel +threads, by specifying the dimension of the grid Dimgrid, the number +of blocks per grid DimBlock and the number of threads per block. + +The code is organized kernels which are part of code that are run on +GPU devices. For step 3, there are two kernels, the first named +\textit{save} is used to save vector $Z^{K-1}$ and the second one is +named \textit{update} and is used to update the $Z^{K}$ vector. For +step 4, a kernel tests the convergence of the method. In order to +compute the function H, we have two possibilities: either to use the +Jacobi mode, or the Gauss-Seidel mode of iterating which uses the most +recent computed roots. It is well known that the Gauss-Seidel mode +converges more quickly. So, we use Gauss-Seidel iterations. To +parallelize the code, we create kernels and many functions to be +executed on the GPU for all the operations dealing with the computation on complex numbers and the evaluation of the -polynomials. As said previously, we managed both functions -of evaluation of a polynomial: the normal method, based on -the method of Horner and the method based on the logarithm -of the polynomial. All these methods were rather long to -implement, as the development of corresponding kernels with -CUDA is longer than on a CPU host. This comes in particular -from the fact that it is very difficult to debug CUDA running -threads like threads on a CPU host. In the following paragraph -Algorithm~\ref{alg1-cuda} shows the GPU parallel implementation of Ehrlich-Aberth method. +polynomials. As said previously, we manage both functions of +evaluation: the normal method, based on the method of +Horner and the method based on the logarithm of the polynomial. All +these methods were rather long to implement, as the development of +corresponding kernels with CUDA is longer than on a CPU host. This +comes in particular from the fact that it is very difficult to debug +CUDA running threads like threads on a CPU host. In the following +paragraph Algorithm~\ref{alg1-cuda} shows the GPU parallel +implementation of Ehrlich-Aberth method. \begin{enumerate} \begin{algorithm}[htpb] @@ -794,13 +809,36 @@ Algorithm~\ref{alg1-cuda} shows the GPU parallel implementation of Ehrlich-Abert \end{enumerate} ~\\ - +\RC{Au final, on laisse ce code, on l'explique, si c'est kahina qui + rajoute l'explication, il faut absolument ajouter \KG{dfsdfsd}, car + l'anglais sera à relire et je ne veux pas tout relire... } \section{The EA algorithm on Multiple GPUs} \label{sec4} \subsection{M-GPU : an OpenMP-CUDA approach} -Our OpenMP-CUDA implementation of EA algorithm is based on the hybrid OpenMP and CUDA programming model. It works as follows. -Based on the metadata, a shared memory is used to make data evenly shared among OpenMP threads. The shared data are the solution vector $Z$, the polynomial to solve $P$, and the error vector $\Delta z$. Let (T\_omp) the number of OpenMP threads be equal to the number of GPUs, each OpenMP thread binds to one GPU, and controls a part of the shared memory, that is a part of the vector Z , that is $(n/num\_gpu)$ roots where $n$ is the polynomial's degree and $num\_gpu$ the total number of available GPUs. Each OpenMP thread copies its data from host memory to GPU’s device memory. Then every GPU will have a grid of computation organized according to the device performance and the size of data on which it runs the computation kernels. %In principle a grid is set by two parameter DimGrid, the number of block per grid, DimBloc: the number of threads per block. The following schema shows the architecture of (CUDA,OpenMP). +Our OpenMP-CUDA implementation of EA algorithm is based on the hybrid +OpenMP and CUDA programming model. All the data +are shared with OpenMP amoung all the OpenMP threads. The shared data +are the solution vector $Z$, the polynomial to solve $P$, and the +error vector $\Delta z$. The number of OpenMP threads is equal to the +number of GPUs, each OpenMP thread binds to one GPU, and it controls a +part of the shared memory. More precisely each OpenMP thread owns of +the vector Z, that is $(n/num\_gpu)$ roots where $n$ is the +polynomial's degree and $num\_gpu$ the total number of available +GPUs. Then all GPUs will have a grid of computation organized +according to the device performance and the size of data on which it +runs the computation kernels. + +To compute one iteration of the EA method each GPU performs the +followings steps. First roots are shared with OpenMP. Each thread +starts by copying all the previous roots inside its GPU. Then each GPU +will compute an iteration of the EA method on its own roots. For that +all the other roots are used. At the end of an iteration, the updated +roots are copied from the GPU to the CPU. The convergence is checked +on the new roots. Finally each CPU will update its own roots in the +shared memory arrays containing all the roots. + +%In principle a grid is set by two parameter DimGrid, the number of block per grid, DimBloc: the number of threads per block. The following schema shows the architecture of (CUDA,OpenMP). %\begin{figure}[htbp] %\centering @@ -810,44 +848,63 @@ Based on the metadata, a shared memory is used to make data evenly shared among %\end{figure} %Each thread OpenMP compute the kernels on GPUs,than after each iteration they copy out the data from GPU memory to CPU shared memory. The kernels are re-runs is up to the roots converge sufficiently. Here are below the corresponding algorithm: -$num\_gpus$ OpenMP threads are created using \verb=omp_set_num_threads();=function (step $3$, Algorithm \ref{alg2-cuda-openmp}), the shared memory is created using \verb=#pragma omp parallel shared()= OpenMP function (line $5$, Algorithm\ref{alg2-cuda-openmp}), then each OpenMP thread allocates memory and copies initial data from CPU memory to GPU global memory, executes the kernels on GPU, but computes only his portion of roots indicated with variable \textit{index} initialized in (line 5, Algorithm \ref{alg2-cuda-openmp}), used as input data in the $kernel\_update$ (line 10, Algorithm \ref{alg2-cuda-openmp}). After each iteration, all OpenMP threads synchronize using \verb=#pragma omp barrier;= to gather all the correct values of $\Delta z$, thus allowing the computation the maximum stop condition on vector $\Delta z$ (line 12, Algorithm \ref{alg2-cuda-openmp}). Finally, threads copy the results from GPU memories to CPU memory. The OpenMP threads execute kernels until the roots sufficiently converge. -\begin{enumerate} -\begin{algorithm}[htpb] -\label{alg2-cuda-openmp} -%\LinesNumbered -\caption{CUDA-OpenMP Algorithm to find roots with the Ehrlich-Aberth method} - -\KwIn{$Z^{0}$ (Initial root's vector), $\varepsilon$ (Error tolerance - threshold), P (Polynomial to solve), Pu (Derivative of P), $n$ (Polynomial degree), $\Delta z$ ( Vector of errors for stop condition), $num_gpus$ (number of OpenMP threads/ Number of GPUs), $Size$ (number of roots)} - -\KwOut {$Z$ ( Root's vector), $ZPrec$ (Previous root's vector)} - -\BlankLine - -\item Initialization of P\; -\item Initialization of Pu\; -\item Initialization of the solution vector $Z^{0}$\; -\verb=omp_set_num_threads(num_gpus);= -\verb=#pragma omp parallel shared(Z,$\Delta$ z,P);= -\verb=cudaGetDevice(gpu_id);= -\item Allocate and copy initial data from CPU memory to the GPU global memories\; -\item index= $Size/num\_gpus$\; -\item k=0\; -\While {$error > \epsilon$}{ -\item Let $\Delta z=0$\; -\item $ kernel\_save(ZPrec,Z)$\; -\item k=k+1\; -\item $ kernel\_update(Z,P,Pu,index)$\; -\item $kernel\_testConverge(\Delta z[gpu\_id],Z,ZPrec)$\; -%\verb=#pragma omp barrier;= -\item error= Max($\Delta z$)\; -} - -\item Copy results from GPU memories to CPU memory\; -\end{algorithm} -\end{enumerate} -~\\ - +%% \RC{Surement à virer ou réécrire pour etre compris sans algo} +%% $num\_gpus$ OpenMP threads are created using +%% \verb=omp_set_num_threads();=function (step $3$, Algorithm +%% \ref{alg2-cuda-openmp}), the shared memory is created using +%% \verb=#pragma omp parallel shared()= OpenMP function (line $5$, +%% Algorithm\ref{alg2-cuda-openmp}), then each OpenMP thread allocates +%% memory and copies initial data from CPU memory to GPU global memory, +%% executes the kernels on GPU, but computes only his portion of roots +%% indicated with variable \textit{index} initialized in (line 5, +%% Algorithm \ref{alg2-cuda-openmp}), used as input data in the +%% $kernel\_update$ (line 10, Algorithm \ref{alg2-cuda-openmp}). After +%% each iteration, all OpenMP threads synchronize using +%% \verb=#pragma omp barrier;= to gather all the correct values of +%% $\Delta z$, thus allowing the computation the maximum stop condition +%% on vector $\Delta z$ (line 12, Algorithm +%% \ref{alg2-cuda-openmp}). Finally, threads copy the results from GPU +%% memories to CPU memory. The OpenMP threads execute kernels until the +%% roots sufficiently converge. + + +%% \begin{enumerate} +%% \begin{algorithm}[htpb] +%% \label{alg2-cuda-openmp} +%% %\LinesNumbered +%% \caption{CUDA-OpenMP Algorithm to find roots with the Ehrlich-Aberth method} + +%% \KwIn{$Z^{0}$ (Initial root's vector), $\varepsilon$ (Error tolerance +%% threshold), P (Polynomial to solve), Pu (Derivative of P), $n$ (Polynomial degree), $\Delta z$ ( Vector of errors for stop condition), $num_gpus$ (number of OpenMP threads/ Number of GPUs), $Size$ (number of roots)} + +%% \KwOut {$Z$ ( Root's vector), $ZPrec$ (Previous root's vector)} + +%% \BlankLine + +%% \item Initialization of P\; +%% \item Initialization of Pu\; +%% \item Initialization of the solution vector $Z^{0}$\; +%% \verb=omp_set_num_threads(num_gpus);= +%% \verb=#pragma omp parallel shared(Z,$\Delta$ z,P);= +%% \verb=cudaGetDevice(gpu_id);= +%% \item Allocate and copy initial data from CPU memory to the GPU global memories\; +%% \item index= $Size/num\_gpus$\; +%% \item k=0\; +%% \While {$error > \epsilon$}{ +%% \item Let $\Delta z=0$\; +%% \item $ kernel\_save(ZPrec,Z)$\; +%% \item k=k+1\; +%% \item $ kernel\_update(Z,P,Pu,index)$\; +%% \item $kernel\_testConverge(\Delta z[gpu\_id],Z,ZPrec)$\; +%% %\verb=#pragma omp barrier;= +%% \item error= Max($\Delta z$)\; +%% } + +%% \item Copy results from GPU memories to CPU memory\; +%% \end{algorithm} +%% \end{enumerate} +%% ~\\ +%% \RC{C'est encore pire ici, on ne voit pas les comm CPU <-> GPU } \subsection{Multi-GPU : an MPI-CUDA approach} @@ -861,38 +918,40 @@ Our parallel implementation of EA to find root of polynomials using a CUDA-MPI a Since a GPU works only on data already allocated in its memory, all local input data, $Z_{k}$, $ZPrec$ and $\Delta z_{k}$, must be transferred from CPU memories to the corresponding GPU memories. Afterwards, the same EA algorithm (Algorithm \ref{alg1-cuda}) is run by all processes but on different polynomial subset of roots $ p(x)_{k}=\sum_{i=1}^{n} a_{i}x^{i}, k=1,...,p$. Each MPI process executes the loop \verb=(While(...)...do)= containing the CUDA kernels but each MPI process computes only its own portion of the roots according to the rule ``''owner computes``''. The local range of roots is indicated with the \textit{index} variable initialized at (line 5, Algorithm \ref{alg2-cuda-mpi}), and passed as an input variable to $kernel\_update$ (line 10, Algorithm \ref{alg2-cuda-mpi}). After each iteration, MPI processes synchronize (\verb=MPI_Allreduce= function) by a reduction on $\Delta z_{k}$ in order to compute the maximum error related to the stop condition. Finally, processes copy the values of new computed roots from GPU memories to CPU memories, then communicate their results to other processes with \verb=MPI_Alltoall= broadcast. If the stop condition is not verified ($error > \epsilon$) then processes stay withing the loop \verb= while(...)...do= until all the roots sufficiently converge. -\begin{enumerate} -\begin{algorithm}[htpb] -\label{alg2-cuda-mpi} -%\LinesNumbered -\caption{CUDA-MPI Algorithm to find roots with the Ehrlich-Aberth method} - -\KwIn{$Z^{0}$ (Initial root's vector), $\varepsilon$ (Error tolerance - threshold), P (Polynomial to solve), Pu (Derivative of P), $n$ (Polynomial degrees), $\Delta z$ ( error of stop condition), $num_gpus$ (number of MPI processes/ number of GPUs), Size (number of roots)} - -\KwOut {$Z$ (Solution root's vector), $ZPrec$ (Previous solution root's vector)} - -\BlankLine -\item Initialization of P\; -\item Initialization of Pu\; -\item Initialization of the solution vector $Z^{0}$\; -\item Allocate and copy initial data from CPU memories to GPU global memories\; -\item $index= Size/num_gpus$\; -\item k=0\; -\While {$error > \epsilon$}{ -\item Let $\Delta z=0$\; -\item $kernel\_save(ZPrec,Z)$\; -\item k=k+1\; -\item $kernel\_update(Z,P,Pu,index)$\; -\item $kernel\_testConverge(\Delta z,Z,ZPrec)$\; -\item ComputeMaxError($\Delta z$,error)\; -\item Copy results from GPU memories to CPU memories\; -\item Send $Z[id]$ to all processes\; -\item Receive $Z[j]$ from every other process j\; -} -\end{algorithm} -\end{enumerate} -~\\ +%% \begin{enumerate} +%% \begin{algorithm}[htpb] +%% \label{alg2-cuda-mpi} +%% %\LinesNumbered +%% \caption{CUDA-MPI Algorithm to find roots with the Ehrlich-Aberth method} + +%% \KwIn{$Z^{0}$ (Initial root's vector), $\varepsilon$ (Error tolerance +%% threshold), P (Polynomial to solve), Pu (Derivative of P), $n$ (Polynomial degrees), $\Delta z$ ( error of stop condition), $num_gpus$ (number of MPI processes/ number of GPUs), Size (number of roots)} + +%% \KwOut {$Z$ (Solution root's vector), $ZPrec$ (Previous solution root's vector)} + +%% \BlankLine +%% \item Initialization of P\; +%% \item Initialization of Pu\; +%% \item Initialization of the solution vector $Z^{0}$\; +%% \item Allocate and copy initial data from CPU memories to GPU global memories\; +%% \item $index= Size/num_gpus$\; +%% \item k=0\; +%% \While {$error > \epsilon$}{ +%% \item Let $\Delta z=0$\; +%% \item $kernel\_save(ZPrec,Z)$\; +%% \item k=k+1\; +%% \item $kernel\_update(Z,P,Pu,index)$\; +%% \item $kernel\_testConverge(\Delta z,Z,ZPrec)$\; +%% \item ComputeMaxError($\Delta z$,error)\; +%% \item Copy results from GPU memories to CPU memories\; +%% \item Send $Z[id]$ to all processes\; +%% \item Receive $Z[j]$ from every other process j\; +%% } +%% \end{algorithm} +%% \end{enumerate} +%% ~\\ + +%% \RC{ENCORE ENCORE PIRE} \section{Experiments} \label{sec5}