X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/book_gpu.git/blobdiff_plain/a9f4a14a06edf88832d058ec85346ff66bd171b4..69fa38e834150067ce61e4b3e1412f35f05149b7:/BookGPU/Chapters/chapter18/ch18.tex?ds=sidebyside diff --git a/BookGPU/Chapters/chapter18/ch18.tex b/BookGPU/Chapters/chapter18/ch18.tex index b4401c9..9c9a85a 100755 --- a/BookGPU/Chapters/chapter18/ch18.tex +++ b/BookGPU/Chapters/chapter18/ch18.tex @@ -1,8 +1,8 @@ -\chapterauthor{Raphaël Couturier}{Femto-ST Institute, University of Franche-Comte} -\chapterauthor{Christophe Guyeux}{Femto-ST Institute, University of Franche-Comte} +\chapterauthor{Raphaël Couturier}{Femto-ST Institute, University of Franche-Comt\'{e}} +\chapterauthor{Christophe Guyeux}{Femto-ST Institute, University of Franche-Comt\'{e}} -\chapter{Pseudo Random Number Generator on GPU} +\chapter{Pseudorandom Number Generator on GPU} \label{chapter18} \section{Introduction} @@ -10,7 +10,9 @@ Randomness is of importance in many fields such as scientific simulations or cryptography. ``Random numbers'' can mainly be generated either by a deterministic and reproducible algorithm called -a pseudorandom number generator (PRNG). In this paper, we focus on +a pseudorandom number generator (PRNG)\index{PRNG}, or by a physical non-deterministic +process having all the characteristics of a random noise, called a truly random number +generator (TRNG). In this chapter, we focus on reproducible generators, useful for instance in Monte-Carlo based simulators. These domains need PRNGs that are statistically irreproachable. In some fields such as in numerical simulations, @@ -31,14 +33,14 @@ to make the distinction between numbers obtained with the secure generator and a true random sequence. Or, in an equivalent formulation, he or she should not be able (in practice) to predict the next bit of the generator, having the knowledge of all the binary -digits that have been already released. ``Being able in practice'' +digits that have been already released~\cite{Goldreich}. ``Being able in practice'' refers here to the possibility to achieve this attack in polynomial time, and to the exponential growth of the difficulty of this challenge when the size of the parameters of the PRNG increases. Finally, a small part of the community working in this domain focuses on a -third requirement, that is to define chaotic generators. +third requirement, that is to define chaotic generators~\cite{kellert1994wake, Wu20051195,gleick2011chaos}. The main idea is to take benefits from a chaotic dynamical system to obtain a generator that is unpredictable, disordered, sensible to its seed, or in other word chaotic. Their desire is to map a given chaotic dynamics into a sequence that seems random @@ -50,11 +52,19 @@ Furthermore, authors of such chaotic generators often claim their PRNG as secure due to their chaos properties, but there is no obvious relation between chaos and security as it is understood in cryptography. This is why the use of chaos for PRNG still remains marginal and disputable. -Let us finish this paragraph by noticing that, in this paper, +However, we have established in previous researches that these flaws can +be circumvented by using a tool called choatic iterations. +Such investigations have led to the definition of a new +family of PRNGs that are chaotic while being fast and statistically perfect, +or cryptographically secure~\cite{bgw09:ip,bgw10:ip,bfgw11:ij,bfg12a:ip}. This family is improved and adapted for GPU +architectures in this chapter. + + +Let us finish this introduction by noticing that, in this paper, statistical perfection refers to the ability to pass the whole {\it BigCrush} battery of tests, which is widely considered as the most stringent statistical evaluation of a sequence claimed as random. -This battery can be found in the well-known TestU01 package~\cite{LEcuyerS07}. +This battery can be found in the well-known TestU01 package~\cite{LEcuyerS07}\index{TestU01}. More precisely, each time we performed a test on a PRNG, we ran it twice in order to observe if all $p-$values are inside [0.01, 0.99]. In fact, we observed that few $p-$values (less than ten) are sometimes @@ -66,8 +76,13 @@ the same test. With this approach all our PRNGs pass the {\it Chaos, for its part, refers to the well-established definition of a chaotic dynamical system defined by Devaney~\cite{Devaney}. -The remainder of this paper is organized as follows. -A COMPLETER +The remainder of this chapter is organized as follows. +Basic definitions and terminologies about both topological chaos +and chaotic iterations are provided in the next section. Various +chaotic iterations based pseudorandom number generators are then +presented in Section~\ref{sec:efficient PRNG}. They encompass +naive and improved efficient generators for CPU and for GPU. +These generators are finally experimented in Section~\ref{sec:experiments}. \section{Basic Recalls} @@ -78,13 +93,118 @@ topological chaos and chaotic iterations. We assume the reader is familiar with basic notions on topology (see for instance~\cite{Devaney}). -\subsection{Devaney's Chaotic Dynamical Systems} +\subsection{A Short Presentation of Chaos} + + +Chaos theory studies the behavior of dynamical systems that are perfectly predictable, yet appear to be wildly amorphous and without meaningful. +Chaotic systems\index{chaotic systems} are highly sensitive to initial conditions, +which is popularly referred to as the butterfly effect. +In other words, small differences in initial conditions (such as those due to rounding errors in numerical computation) yield widely diverging outcomes, +rendering long-term prediction impossible in general \cite{kellert1994wake}. This happens even though these systems are deterministic, meaning that their future behavior is fully determined by their initial conditions, with no random elements involved \cite{kellert1994wake}. That is, the deterministic nature of these systems does not make them predictable \cite{kellert1994wake,Werndl01032009}. This behavior is known as deterministic chaos, or simply chaos. It has been well-studied in mathematics and +physics, leading among other things to the well-established definition of Devaney +recalled thereafter. + + + + + +\subsection{On Devaney's Definition of Chaos}\index{chaos} +\label{sec:dev} +Consider a metric space $(\mathcal{X},d)$ and a continuous function $f:\mathcal{X}\longrightarrow \mathcal{X}$, for one-dimensional dynamical systems of the form: +\begin{equation} +x^0 \in \mathcal{X} \textrm{ and } \forall n \in \mathds{N}^*, x^n=f(x^{n-1}), +\label{Devaney} +\end{equation} +the following definition of chaotic behavior, formulated by Devaney~\cite{Devaney}, is widely accepted. + +\begin{definition} + A dynamical system of Form~(\ref{Devaney}) is said to be chaotic if the following conditions hold. +\begin{itemize} +\item Topological transitivity\index{topological transitivity}: + +\begin{equation} +\forall U,V \textrm{ open sets of } \mathcal{X},~\exists k>0, f^k(U) \cap V \neq \varnothing . +\end{equation} + +Intuitively, a topologically transitive map has points that eventually move under iteration from one arbitrarily small neighborhood to any other. Consequently, the dynamical system cannot be decomposed into two disjoint open sets that are invariant under the map. Note that if a map possesses a dense orbit, then it is clearly topologically transitive. +\item Density of periodic points in $\mathcal{X}$\index{density of periodic points}. + +Let $P=\{p\in \mathcal{X}|\exists n \in \mathds{N}^{\ast}:f^n(p)=p\}$ the set of periodic points of $f$. Then $P$ is dense in $\mathcal{X}$: + +\begin{equation} + \overline{P}=\mathcal{X} . +\end{equation} + +Density of periodic orbits means that every point in the space is approached arbitrarily closely by periodic orbits. Topologically mixing systems failing this condition may not display sensitivity to initial conditions presented below, and hence may not be chaotic. +\item Sensitive dependence on initial conditions\index{sensitive dependence on initial conditions}: + +$\exists \varepsilon>0,$ $\forall x \in \mathcal{X},$ $\forall \delta >0,$ $\exists y \in \mathcal{X},$ $\exists n \in \mathbb{N},$ $d(x,y)<\delta$ and $d\left(f^n(x),f^n(y)\right) \geqslant \varepsilon.$ + +Intuitively, a map possesses sensitive dependence on initial conditions if there exist points arbitrarily close to $x$ that eventually separate from $x$ by at least $\varepsilon$ under iteration of $f$. Not all points near $x$ need eventually separate from $x$ under iteration, but there must be at least one such point in every neighborhood of $x$. If a map possesses sensitive dependence on initial conditions, then for all practical purposes, the dynamics of the map defy numerical computation. Small errors in computation that are introduced by round-off may become magnified upon iteration. The results of numerical computation of an orbit, no matter how accurate, may bear no resemblance whatsoever with the real orbit. +\end{itemize} +\end{definition} -A COMPLETER +When $f$ is chaotic, then the system $(\mathcal{X}, f)$ is chaotic and quoting Devaney: ``it is unpredictable because of the sensitive dependence on initial conditions. It cannot be broken down or decomposed into two subsystems which do not interact because of topological transitivity. And, in the midst of this random behavior, we nevertheless have an element of regularity.'' Fundamentally different behaviors are consequently possible and occur in an unpredictable way. + + + + + +\subsection{Chaotic iterations}\index{chaotic iterations} +\label{subsection:Chaotic iterations} + +Let us now introduce an example of a dynamical systems family that has +the potentiality to become chaotic, depending on the choice of the iteration +function. This family is the basis of the PRNGs we will +develop during this chapter. + +\begin{definition} +\label{Chaotic iterations} +The set $\mathds{B}$ denoting $\{0,1\}$, let $f:\mathds{B}^{\mathsf{N}% +}\longrightarrow \mathds{B}^{\mathsf{N}}$ be an ``iteration'' function and $S$ be a +sequence of subsets of $\llbracket 1, \mathsf{N}\rrbracket$ called a chaotic strategy. Then, the so-called \emph{chaotic iterations} are defined by~\cite{Robert1986}: + +\begin{equation} +\label{eq:generalIC} +\left\{\begin{array}{l} +x^0\in \mathds{B}^{\mathsf{N}}, \\ +\forall n\in \mathds{N}^{\ast },\forall i\in \llbracket1;\mathsf{N}\rrbracket% +,x_i^n= +\left\{ +\begin{array}{ll} +x_i^{n-1} & \text{if}~ i\notin S^n \\ +f(x^{n-1})_{i} & \text{if}~ i \in S^n. +\end{array} +\right. +\end{array} +\right. +\end{equation} +\end{definition} + +In other words, at the $n^{th}$ iteration, only the cells of $S^{n}$ are +``iterated''. +Chaotic iterations generate a set of vectors; +they are defined by an initial state $x^{0}$, an iteration function $f$, and a chaotic strategy $S$~\cite{bg10:ij}. +These ``chaotic iterations'' can behave chaotically as defined by Devaney, +depending on the choice of $f$~\cite{bg10:ij}. For instance, +chaos is obtained when $f$ is the vectorial negation. +Note that, with this example of function, chaotic iterations +defined above can be rewritten as: +\begin{equation} +\label{equation Oplus} +x^0 \in \llbracket 0,2^\mathsf{N}-1\rrbracket,~\mathcal{S}^n \in \mathcal{P}\left(\llbracket 1,2^\mathsf{N}-1\rrbracket\right)^\mathds{N},~~ x^{n+1}=x^n \oplus \mathcal{S}^n, +\end{equation} +where $\mathcal{P}(X)$ stands for the set of subsets of $X$, whereas +$a\oplus b$ is the bitwise exclusive or operation between the binary +representation of the integers $a$ and $b$. Note that the term + $\mathcal{S}^n$ is directly and obviously linked to the $S^n$ of +Eq.\ref{eq:generalIC}. As recalled above, such an iterative sequence +satisfies the Devaney's definition of chaos. + \section{Toward Efficiency and Improvement for CI PRNG} \label{sec:efficient PRNG} @@ -155,7 +275,8 @@ unsigned int CIPRNG() { In Listing~\ref{algo:seqCIPRNG} a sequential version of the proposed PRNG based -on chaotic iterations is presented. The xor operator is represented by +on chaotic iterations is presented, which extends the generator family +formerly presented in~\cite{bgw09:ip,guyeux10}. The xor operator is represented by \textasciicircum. This function uses three classical 64-bits PRNGs, namely the \texttt{xorshift}, the \texttt{xor128}, and the \texttt{xorwow}~\cite{Marsaglia2003}. In the following, we call them ``xor-like @@ -309,19 +430,20 @@ system of Eq.~\ref{eq:generalIC}. That is, an iteration of the general chaotic iterations is realized between the last stored value $x$ of the thread and a strategy $t$ (obtained by a bitwise exclusive or between a value provided by a xor-like() call and two values previously obtained by two other threads). -To be certain that we are in the framework of Theorem~\ref{t:chaos des general}, +To be certain that such iterations corresponds to the chaotic one recalled at the +end of the Section~\ref{sec:dev}, we must guarantee that this dynamical system iterates on the space -$\mathcal{X} = \mathcal{P}\left(\llbracket 1, \mathsf{N} \rrbracket\right)^\mathds{N}\times\mathds{B}^\mathsf{N}$. +$\mathcal{X} =\mathds{B}^\mathsf{N} \times \mathcal{P}\left(\llbracket 1, 2^\mathsf{N} \rrbracket\right)^\mathds{N}$. The left term $x$ obviously belongs to $\mathds{B}^ \mathsf{N}$. To prevent from any flaws of chaotic properties, we must check that the right term (the last $t$), corresponding to the strategies, can possibly be equal to any -integer of $\llbracket 1, \mathsf{N} \rrbracket$. +integer of $\llbracket 1, 2^\mathsf{N} \rrbracket$. Such a result is obvious, as for the xor-like(), all the integers belonging into its interval of definition can occur at each iteration, and thus the last $t$ respects the requirement. Furthermore, it is possible to -prove by an immediate mathematical induction that, as the initial $x$ -is uniformly distributed (it is provided by a cryptographically secure PRNG), +prove by an immediate mathematical induction that, supposes that the initial $x$ +is uniformly distributed, %(it is provided by a cryptographically secure PRNG), the two other stored values shmem[o1] and shmem[o2] are uniformly distributed too, (this is the induction hypothesis), and thus the next $x$ is finally uniformly distributed. @@ -370,27 +492,9 @@ As a comparison, Listing~\ref{algo:seqCIPRNG} leads to the generation of -In Figure~\ref{fig:time_bbs_gpu} we highlight the performances of the optimized -BBS-based PRNG on GPU. On the Tesla C1060 we obtain approximately 700MSample/s -and on the GTX 280 about 670MSample/s, which is obviously slower than the -xorlike-based PRNG on GPU. However, we will show in the next sections that this -new PRNG has a strong level of security, which is necessarily paid by a speed -reduction. - -\begin{figure}[htbp] -\begin{center} - \includegraphics[scale=0.65]{Chapters/chapter18/figures/curve_time_bbs_gpu.pdf} -\end{center} -\caption{Quantity of pseudorandom numbers generated per second using the BBS-based PRNG} -\label{fig:time_bbs_gpu} -\end{figure} -All these experiments allow us to conclude that it is possible to +These experiments allow us to conclude that it is possible to generate a very large quantity of pseudorandom numbers statistically perfect with the xor-like version. -To a certain extend, it is also the case with the secure BBS-based version, the speed deflation being -explained by the fact that the former version has ``only'' -chaotic properties and statistical perfection, whereas the latter is also cryptographically secure, -as it is shown in the next sections. @@ -402,5 +506,6 @@ as it is shown in the next sections. -\putbib[Chapters/chapter18/biblio] + +\putbib[Chapters/chapter18/biblio18]