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

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

Trim to 12 pages: eliminate Unicode section, avx2 addition figure.

File size: 5.5 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} Bitstream addition
20at the 256-bit block size was implemented using the
21long-stream addition technique.   The AVX2 instruction set directly
22supports the \verb#hsimd<64>::mask(X)# operation using
23the \verb#_mm256_movemask_pd#  intrinsic, extracting
24the required 4-bit mask directly from the 256-bit vector.
25The \verb#hsimd<64>::spread(X)# is slightly more complex, requiring a short sequence of instructions
26to convert the computed 4-bit increment mask back
27into a vector of 4 64-bit values.
28
29We also compiled new versions of the {\tt egrep} and {\tt nrgrep} programs
30using the {\tt -march=core-avx2} flag in case the compiler is able
31to vectorize some of the code.
32
33\begin{figure}
34\begin{center}
35\begin{tikzpicture}
36\begin{axis}[
37xtick=data,
38ylabel=AVX2 Instruction Reduction,
39xticklabels={@,Date,Email,URI,Hex,StarHeight},
40tick label style={font=\tiny},
41enlarge x limits=0.15,
42%enlarge y limits={0.15, upper},
43ymin=0,
44legend style={at={(0.5,-0.15)},
45anchor=north,legend columns=-1},
46ybar,
47bar width=7pt,
48]
49\addplot
50file {data/sse2-avx2-instr-red-bitstreams.dat};
51\addplot
52file {data/sse2-avx2-instr-red-nrgrep112.dat};
53\addplot
54file {data/sse2-avx2-instr-red-gre2p.dat};
55
56\legend{bitstreams,nrgrep,gre2p,Annot}
57\end{axis}
58\end{tikzpicture}
59\end{center}
60\caption{Instruction Reduction}\label{fig:AVXInstrReduction}
61\end{figure}
62
63
64Figure \ref{fig:AVXInstrReduction} shows the reduction in instruction
65count achieved for each of the applications.   Working at a block
66size of 256 bytes at a time rather than 128 bytes at a time,
67the bitstreams implementation scaled very well with reductions in
68instruction count over a factor of two in every case except for StarHeight.   
69Although a factor
70of two would seem an outside limit, we attribute the change to
71greater instruction efficiency. 
72AVX2 instructions use a
73non destructive three-operand
74form instead of the destructive two-operand form of SSE2.
75In the two-operand form, binary instructions must always use
76one of the source registers as a destination register.   As a
77result the SSE2 object code generates many data movement operations
78that are unnecessary with the AVX2 set.
79
80As expected, there was no observable reduction in instruction
81count with the recompiled grep and nrgrep applications.
82
83
84
85\begin{figure}
86\begin{center}
87\begin{tikzpicture}
88\begin{axis}[
89xtick=data,
90ylabel=AVX2 Speedup,
91xticklabels={@,Date,Email,URI,Hex,StarHeight},
92tick label style={font=\tiny},
93enlarge x limits=0.15,
94%enlarge y limits={0.15, upper},
95ymin=0,
96legend style={at={(0.5,-0.15)},
97anchor=north,legend columns=-1},
98ybar,
99bar width=7pt,
100]
101\addplot
102file {data/sse2-avx2-speedup-bitstreams.dat};
103\addplot
104file {data/sse2-avx2-speedup-nrgrep112.dat};
105\addplot
106file {data/sse2-avx2-speedup-gre2p.dat};
107
108\legend{bitstreams,nrgrep,gre2p,Annot}
109\end{axis}
110\end{tikzpicture}
111\end{center}
112\caption{AVX Speedup}\label{fig:AVXSpeedup}
113\end{figure}
114
115As shown in Figure \ref{fig:AVXSpeedup} the reduction in
116instruction count was reflected in a significant speedup
117in the bitstreams implementation in all cases except
118StarHeight.  However, the speedup was
119considerably less than expected. 
120The bitstreams code  on AVX2 has suffered from a considerable
121reduction in instructions per cycle compared to the SSE2
122implementation, likely indicating
123that our grep implementation has become memory-bound.
124However, the performance of StarHeight deserves particular
125comment, with an actual slowdown observed.   When moving
126to 256 positions at a time, the controlling while loops may
127require more iterations than working 128 positions at a time,
128because the iteration must continue as long as there are any
129pending markers in the block.   
130Nevertheless, the overall results on our AVX2 machine were quite encouraging,
131demonstrating very good scalability of the bitwise data-parallel approach.
132Significantly, the @ regular expression is matched at 0.63 cycles/byte
133using our AVX2 implementation indicating a significant reduction
134in the overhead cost of the Parabix transform.
135
136Table \ref{Xfactors} shows the final performance results
137showing the speedup factors achieved by the Parabix/AVX2 implementation
138vs nrgrep and gre2p.  We have also added comparison with GNU grep
139(version 2.16),
140as it is well known and sometimes used as a basis for comparisons.
141\begin{table}
142\begin{center}
143\begin{tabular}{|c|c|c|c|} \hline
144\multirow{2}{*}{Expression} & \multicolumn{3}{c|}{Bitstream grep Speedup} \\ \cline{2-4}
145& vs. nrgrep & vs. gre2p & vs. GNU grep -e\\ \hline \hline
146At & 3.5X & 34X & 1.6X\\ \hline
147Date & 0.76X & 13X & 48X\\ \hline
148Email & 9.5X & 28X & 12X\\ \hline
149URIorEmail & 6.6X & 27X & 518X\\ \hline
150Hex & 8.1X & 105X & 267X\\ \hline
151StarHeight & 1.9X & 7.6X & 97X\\ \hline
152\end{tabular}
153\end{center}
154\caption{Speedups Obtained}\label{Xfactors}
155\end{table}
Note: See TracBrowser for help on using the repository browser.