source: docs/Working/re/avx2.tex @ 3874

Last change on this file since 3874 was 3874, checked in by cameron, 5 years ago

Speedups vs. GNU grep

File size: 6.1 KB
Line 
1\section{SIMD Scalability}\label{sec:AVX2}
2
3
4Although commodity processors have provided 128-bit SIMD operations for
5more than a decade, the extension to 256-bit integer SIMD operations
6has just recently taken place with the availability of AVX2
7instructions in Intel Haswell architecture chips as of mid 2013.
8This provides an excellent opportunity to assess the scalability
9of the bitwise data-parallel approach to regular expression matching.
10
11For the most part, adapting the Parabix tool chain to the new AVX2
12instructions was straightforward.   This mostly involved regenerating
13library functions using the new AVX2 intrinsics.   There were minor
14issues in the core transposition algorithm because the doublebyte-to-byte
15pack instructions are confined to independent operations within two
16128-bit lanes. 
17
18
19\paragraph*{AVX2 256-Bit Addition}
20 \begin{figure}[tbh]
21
22\begin{center} \small
23\begin{verbatim}
24bitblock_t spread(uint64_t bits) {
25  uint64_t s = 0x0000200040008001 * bits;
26  uint64_t t = s & 0x0001000100010001;
27  return _mm256_cvtepu16_epi64(t);
28}
29\end{verbatim}
30\end{center}
31\caption{AVX2 256-bit Spread}
32\label{fig:AVX2spread}
33
34\end{figure}
35
36Bitstream addition at the 256-bit block size was implemented using the
37long-stream addition technique.   The AVX2 instruction set directly
38supports the \verb#hsimd<64>::mask(X)# operation using
39the \verb#_mm256_movemask_pd#  intrinsic, extracting
40the required 4-bit mask directly from the 256-bit vector.
41The \verb#hsimd<64>::spread(X)# is slightly more
42problematic, requiring a short sequence of instructions
43to convert the computed 4-bit increment mask back
44into a vector of 4 64-bit values.   One method is to
45use the AVX2 broadcast instruction to make 4 copies
46of the mask to be spread, followed by appropriate
47bit manipulation.   Another uses multiplication to
48first spread to 16-bit fields as shown in Figure \ref{fig:AVX2spread}.
49
50We also compiled new versions of the {\tt egrep} and {\tt nrgrep} programs
51using the {\tt -march=core-avx2} flag in case the compiler is able
52to vectorize some of the code.
53
54\begin{figure}
55\begin{center}
56\begin{tikzpicture}
57\begin{axis}[
58xtick=data,
59ylabel=AVX2 Instruction Reduction,
60xticklabels={@,Date,Email,URIorEmail,HexBytes,StarHeight},
61tick label style={font=\tiny},
62enlarge x limits=0.15,
63%enlarge y limits={0.15, upper},
64ymin=0,
65legend style={at={(0.5,-0.15)},
66anchor=north,legend columns=-1},
67ybar,
68bar width=7pt,
69]
70\addplot
71file {data/sse2-avx2-instr-red-bitstreams.dat};
72\addplot
73file {data/sse2-avx2-instr-red-nrgrep112.dat};
74\addplot
75file {data/sse2-avx2-instr-red-gre2p.dat};
76
77\legend{bitstreams,nrgrep,gre2p,Annot}
78\end{axis}
79\end{tikzpicture}
80\end{center}
81\caption{Instruction Reduction}\label{fig:AVXInstrReduction}
82\end{figure}
83
84
85Figure \ref{fig:AVXInstrReduction} shows the reduction in instruction
86count achieved for each of the applications.   Working at a block
87size of 256 bytes at a time rather than 128 bytes at a time,
88the bitstreams implementation scaled very well with reductions in
89instruction count over a factor of two in every case except for StarHeight.   
90Although a factor
91of two would seem an outside limit, we attribute the change to
92greater instruction efficiency. 
93AVX2 instructions use a
94non destructive three-operand
95form instead of the destructive two-operand form of SSE2.
96In the two-operand form, binary instructions must always use
97one of the source registers as a destination register.   As a
98result the SSE2 object code generates many data movement operations
99that are unnecessary with the AVX2 set.
100
101As expected, there was no observable reduction in instruction
102count with the recompiled grep and nrgrep applications.
103
104
105
106\begin{figure}
107\begin{center}
108\begin{tikzpicture}
109\begin{axis}[
110xtick=data,
111ylabel=AVX2 Speedup,
112xticklabels={@,Date,Email,URIorEmail,HexBytes,StarHeight},
113tick label style={font=\tiny},
114enlarge x limits=0.15,
115%enlarge y limits={0.15, upper},
116ymin=0,
117legend style={at={(0.5,-0.15)},
118anchor=north,legend columns=-1},
119ybar,
120bar width=7pt,
121]
122\addplot
123file {data/sse2-avx2-speedup-bitstreams.dat};
124\addplot
125file {data/sse2-avx2-speedup-nrgrep112.dat};
126\addplot
127file {data/sse2-avx2-speedup-gre2p.dat};
128
129\legend{bitstreams,nrgrep,gre2p,Annot}
130\end{axis}
131\end{tikzpicture}
132\end{center}
133\caption{AVX Speedup}\label{fig:AVXSpeedup}
134\end{figure}
135
136As shown in Figure \ref{fig:AVXSpeedup} the reduction in
137instruction count was reflected in a significant speedup
138in the bitstreams implementation in all cases except
139StarHeight.  However, the speedup was
140considerably less than expected. 
141The bitstreams code  on AVX2 has suffered from a considerable
142reduction in instructions per cycle compared to the SSE2
143implementation, likely indicating
144that our grep implementation has become memory-bound.
145However, the performance of StarHeight deserves particular
146comment, with an actual slowdown observed.   When moving
147to 256 positions at a time, the controlling while loops may
148require more iterations than working 128 positions at a time,
149because the iteration must continue as long as there are any
150pending markers in the block.   
151Nevertheless, the overall results on our AVX2 machine were quite encouraging,
152demonstrating very good scalability of the bitwise data-parallel approach.
153Significantly, the @ regular expression is matched at 0.63 cycles/byte
154using our AVX2 implementation indicating a significant reduction
155in the overhead cost of the Parabix transform.
156
157Table \ref{Xfactors} shows the final performance results
158showing the speedup factors achieved by the Parabix/AVX2 implementation
159vs nrgrep and gre2p.  We have also added comparison with GNU grep,
160as it is well known and sometimes used as a basis for comparisons.
161\begin{table}
162\begin{center}
163\begin{tabular}{|c|c|c|c|} \hline
164\multirow{2}{*}{Expression} & \multicolumn{3}{c|}{Bitstream grep Speedup} \\ \cline{2-4}
165& vs. nrgrep & vs. gre2p & vs. GNU grep -e\\ \hline \hline
166At & 3.5X & 34X & 1.6X\\ \hline
167Date & 0.76X & 13X & 48X\\ \hline
168Email & 9.5X & 28X & 12X\\ \hline
169URIorEmail & 6.6X & 27X & 518X\\ \hline
170HexBytes & 8.1X & 105X & 267X\\ \hline
171StarHeight & 1.9X & 7.6X & 97X\\ \hline
172\end{tabular}
173\end{center}
174\caption{Speedups Obtained}\label{Xfactors}
175\end{table}
Note: See TracBrowser for help on using the repository browser.