add downsides slide
[libreriscv.git] / simple_v_extension / simple_v_chennai_2018.tex
1 \documentclass[slidestop]{beamer}
2 \usepackage{beamerthemesplit}
3 \usepackage{graphics}
4 \usepackage{pstricks}
5
6 \title{Simple-V RISC-V Extension for Vectorisation and SIMD}
7 \author{Luke Kenneth Casson Leighton}
8
9
10 \begin{document}
11
12 \frame{
13 \begin{center}
14 \huge{Simple-V RISC-V Extension for Vectors and SIMD}\\
15 \vspace{32pt}
16 \Large{Flexible Vectorisation}\\
17 \Large{(aka not so Simple-V?)}\\
18 \vspace{24pt}
19 \Large{[proposed for] Chennai 9th RISC-V Workshop}\\
20 \vspace{24pt}
21 \large{\today}
22 \end{center}
23 }
24
25
26 \frame{\frametitle{Credits and Acknowledgements}
27
28 \begin{itemize}
29 \item The Designers of RISC-V\vspace{15pt}
30 \item The RVV Working Group and contributors\vspace{15pt}
31 \item Allen Baum, Jacob Bachmeyer, Xan Phung, Chuanhua Chang,\\
32 Guy Lemurieux, Jonathan Neuschafer, Roger Brussee,
33 and others\vspace{15pt}
34 \item ISA-Dev Group Members\vspace{10pt}
35 \end{itemize}
36 }
37
38
39 \frame{\frametitle{Quick refresher on SIMD}
40
41 \begin{itemize}
42 \item SIMD very easy to implement (and very seductive)\vspace{10pt}
43 \item Parallelism is in the ALU\vspace{10pt}
44 \item Zero-to-Negligeable impact for rest of core\vspace{10pt}
45 \end{itemize}
46 Where SIMD Goes Wrong:\vspace{10pt}
47 \begin{itemize}
48 \item See "SIMD instructions considered harmful"
49 https://www.sigarch.org/simd-instructions-considered-harmful
50 \item Corner-cases alone are extremely complex.\\
51 Hardware is easy, but software is hell.
52 \item O($N^{6}$) ISA opcode proliferation!\\
53 opcode, elwidth, veclen, src1-src2-dest hi/lo
54 \end{itemize}
55 }
56
57 \frame{\frametitle{Quick refresher on RVV}
58
59 \begin{itemize}
60 \item Extremely powerful (extensible to 256 registers)\vspace{10pt}
61 \item Supports polymorphism, several datatypes (inc. FP16)\vspace{10pt}
62 \item Requires a separate Register File (32 w/ext to 256)\vspace{10pt}
63 \item Implemented as a separate pipeline (no impact on scalar)\vspace{10pt}
64 \end{itemize}
65 However...\vspace{10pt}
66 \begin{itemize}
67 \item 98 percent opcode duplication with rest of RV (CLIP)
68 \item Extending RVV requires customisation not just of h/w:\\
69 gcc and s/w also need customisation (and maintenance)
70 \end{itemize}
71 }
72
73
74 \frame{\frametitle{The Simon Sinek lowdown (Why, How, What)}
75
76 \begin{itemize}
77 \item Why?
78 Implementors need flexibility in vectorisation to optimise for
79 area or performance depending on the scope:
80 embedded DSP, Mobile GPU's, Server CPU's and more.\vspace{4pt}\\
81 Compilers also need flexibility in vectorisation to optimise for cost
82 of pipeline setup, amount of state to context switch
83 and software portability\vspace{4pt}
84 \item How?
85 By implicitly marking INT/FP regs as "Vectorised",\\
86 SV expresses how existing instructions should act
87 on [contiguous] blocks of registers, in parallel.\vspace{4pt}
88 \item What?
89 Simple-V is an "API" that implicitly extends
90 existing (scalar) instructions with explicit parallelisation.
91 \end{itemize}
92 }
93
94
95 \frame{\frametitle{What's the value of SV? Why adopt it even in non-V?}
96
97 \begin{itemize}
98 \item memcpy becomes much smaller (higher bang-per-buck)\vspace{10pt}
99 \item context-switch (LOAD/STORE multiple): 1-2 instructions\vspace{10pt}
100 \item Compressed instrs further reduces I-cache (etc.)\vspace{10pt}
101 \item greatly-reduced I-cache load (and less reads)\vspace{10pt}
102 \end{itemize}
103 Note:\vspace{10pt}
104 \begin{itemize}
105 \item It's not just about Vectors: it's about instruction effectiveness
106 \item Anything implementor is not interested in HW-optimising,\\
107 let it fall through to exceptions (implement as a trap).
108 \end{itemize}
109 }
110
111
112 \frame{\frametitle{How does Simple-V relate to RVV?}
113
114 \begin{itemize}
115 \item RVV very heavy-duty (excellent for supercomputing)\vspace{10pt}
116 \item Simple-V abstracts parallelism (based on best of RVV)\vspace{10pt}
117 \item Graded levels: hardware, hybrid or traps (fit impl. need)\vspace{10pt}
118 \item Even Compressed instructions become vectorised\vspace{10pt}
119 \end{itemize}
120 What Simple-V is not:\vspace{10pt}
121 \begin{itemize}
122 \item A full supercomputer-level Vector Proposal
123 \item A replacement for RVV (SV is designed to be over-ridden\\
124 by - or augmented to become, or just be replaced by - RVV)
125 \end{itemize}
126 }
127
128
129 \frame{\frametitle{How is Parallelism abstracted in Simple-V?}
130
131 \begin{itemize}
132 \item Register "typing" turns any op into an implicit Vector op\vspace{10pt}
133 \item Primarily at the Instruction issue phase (except SIMD)\\
134 Note: it's ok to pass predication through to ALU (like SIMD)
135 \item Standard (and future, and custom) opcodes now parallel\vspace{10pt}
136 \end{itemize}
137 Notes:\vspace{6pt}
138 \begin{itemize}
139 \item All LOAD/STORE (inc. Compressed, Int/FP versions)
140 \item All ALU ops (soft / hybrid / full HW, on per-op basis)
141 \item All branches become predication targets (C.FNE added)
142 \item C.MV of particular interest (s/v, v/v, v/s)
143 \end{itemize}
144 }
145
146
147 \frame{\frametitle{Implementation Options}
148
149 \begin{itemize}
150 \item Absolute minimum: Exceptions (if CSRs indicate "V", trap)
151 \item Hardware loop, single-instruction issue\\
152 (Do / Don't send through predication to ALU)
153 \item Hardware loop, parallel (multi-instruction) issue\\
154 (Do / Don't send through predication to ALU)
155 \item Hardware loop, full parallel ALU (not recommended)
156 \end{itemize}
157 Notes:\vspace{6pt}
158 \begin{itemize}
159 \item 4 (or more?) options above may be deployed on per-op basis
160 \item SIMD always sends predication bits through to ALU
161 \item Minimum MVL MUST be sufficient to cover regfile LD/ST
162 \item Instr. FIFO may repeatedly split off N scalar ops at a time
163 \end{itemize}
164 }
165 % Instr. FIFO may need its own slide. Basically, the vectorised op
166 % gets pushed into the FIFO, where it is then "processed". Processing
167 % will remove the first set of ops from its vector numbering (taking
168 % predication into account) and shoving them **BACK** into the FIFO,
169 % but MODIFYING the remaining "vectorised" op, subtracting the now
170 % scalar ops from it.
171
172 \frame{\frametitle{How are SIMD Instructions Vectorised?}
173
174 \begin{itemize}
175 \item SIMD ALU(s) primarily unchanged\vspace{10pt}
176 \item Predication is added to each SIMD element (NO ZEROING!)\vspace{10pt}
177 \item End of Vector enables predication (NO ZEROING!)\vspace{10pt}
178 \end{itemize}
179 Considerations:\vspace{10pt}
180 \begin{itemize}
181 \item Many SIMD ALUs possible (parallel execution)\vspace{10pt}
182 \item Very long SIMD ALUs could waste die area (short vectors)\vspace{10pt}
183 \item Implementor free to choose (API remains the same)\vspace{10pt}
184 \end{itemize}
185 }
186 % With multiple SIMD ALUs at for example 32-bit wide they can be used
187 % to either issue 64-bit or 128-bit or 256-bit wide SIMD operations
188 % or they can be used to cover several operations on totally different
189 % vectors / registers.
190
191 \frame{\frametitle{What's the deal / juice / score?}
192
193 \begin{itemize}
194 \item Standard Register File(s) overloaded with CSR "vector span"\\
195 (see pseudocode slides for examples)
196 \item Element width and type concepts remain same as RVV\\
197 (CSRs are used to "interpret" elements in registers)
198 \item CSRs are key-value tables (overlaps allowed)\vspace{10pt}
199 \end{itemize}
200 Key differences from RVV:\vspace{10pt}
201 \begin{itemize}
202 \item Predication in INT regs as a BIT field (max VL=XLEN)
203 \item Minimum VL must be Num Regs - 1 (all regs single LD/ST)
204 \item SV may condense sparse Vecs: RVV lets ALU do predication
205 \item NO ZEROING: non-predicated elements are skipped
206 \end{itemize}
207 }
208
209
210 \begin{frame}[fragile]
211 \frametitle{ADD pseudocode (or trap, or actual hardware loop)}
212
213 \begin{semiverbatim}
214 function op_add(rd, rs1, rs2, predr) # add not VADD!
215  int i, id=0, irs1=0, irs2=0;
216  for (i = 0; i < VL; i++)
217   if (ireg[predr] & 1<<i) # predication uses intregs
218    ireg[rd+id] <= ireg[rs1+irs1] + ireg[rs2+irs2];
219 if (reg_is_vectorised[rd]) \{ id += 1; \}
220 if (reg_is_vectorised[rs1]) \{ irs1 += 1; \}
221 if (reg_is_vectorised[rs2]) \{ irs2 += 1; \}
222 \end{semiverbatim}
223
224 \begin{itemize}
225 \item SIMD slightly more complex (case above is elwidth = default)
226 \item Scalar-scalar and scalar-vector and vector-vector now all in one
227 \item OoO may choose to push ADDs into instr. queue (v. busy!)
228 \end{itemize}
229 \end{frame}
230
231 % yes it really *is* ADD not VADD. that's the entire point of
232 % this proposal, that *standard* operations are overloaded to
233 % become vectorised-on-demand
234
235
236 \begin{frame}[fragile]
237 \frametitle{Predication-Branch (or trap, or actual hardware loop)}
238
239 \begin{semiverbatim}
240 s1 = reg_is_vectorised(src1);
241 s2 = reg_is_vectorised(src2);
242 if (!s2 && !s1) goto branch;
243 for (int i = 0; i < VL; ++i)
244 if cmp(s1 ? reg[src1+i] : reg[src1],
245 s2 ? reg[src2+i] : reg[src2])
246 preg[rs3] |= 1 << i;
247 \end{semiverbatim}
248
249 \begin{itemize}
250 \item SIMD slightly more complex (case above is elwidth = default)
251 \item If s1 and s2 both scalars, Standard branch occurs
252 \item Predication stored in integer regfile as a bitfield
253 \item Scalar-vector and vector-vector supported
254 \end{itemize}
255 \end{frame}
256
257 \begin{frame}[fragile]
258 \frametitle{VLD/VLD.S/VLD.X (or trap, or actual hardware loop)}
259
260 \begin{semiverbatim}
261 if (unit-strided) stride = elsize;
262 else stride = areg[as2]; // constant-strided
263 for (int i = 0; i < VL; ++i)
264 if (preg_enabled[rd] && ([!]preg[rd] & 1<<i))
265 for (int j = 0; j < seglen+1; j++)
266 if (reg_is_vectorised[rs2]) offs = vreg[rs2][i]
267 else offs = i*(seglen+1)*stride;
268 vreg[rd+j][i] = mem[sreg[base] + offs + j*stride]
269 \end{semiverbatim}
270
271 \begin{itemize}
272 \item Again: elwidth != default slightly more complex
273 \item rs2 vectorised taken to implicitly indicate VLD.X
274 \end{itemize}
275 \end{frame}
276
277
278 \frame{\frametitle{Why are overlaps allowed in Regfiles?}
279
280 \begin{itemize}
281 \item Same register(s) can have multiple "interpretations"\vspace{6pt}
282 \item xBitManip plus SIMD plus xBitManip = Hi/Lo bitops\vspace{6pt}
283 \item (32-bit GREV plus 4x8-bit SIMD plus 32-bit GREV)\vspace{6pt}
284 \item RGB 565 (video): BEXTW plus 4x8-bit SIMD plus BDEPW\vspace{6pt}
285 \item Same register(s) can be offset (no need for VSLIDE)\vspace{6pt}
286 \end{itemize}
287 Note:\vspace{10pt}
288 \begin{itemize}
289 \item xBitManip reduces O($N^{6}$) SIMD down to O($N^{3}$)
290 \item Hi-Performance: Macro-op fusion (more pipeline stages?)
291 \end{itemize}
292 }
293
294
295 \frame{\frametitle{Why no Zeroing (place zeros in non-predicated elements)?}
296
297 \begin{itemize}
298 \item Zeroing is an implementation optimisation favouring OoO\vspace{8pt}
299 \item Simple implementations may skip non-predicated operations\vspace{8pt}
300 \item Simple implementations explicitly have to destroy data\vspace{8pt}
301 \item Complex implementations may use reg-renames to save power\\
302 Zeroing on predication chains makes optimisation harder
303 \end{itemize}
304 Considerations:\vspace{10pt}
305 \begin{itemize}
306 \item Complex not really impacted, Simple impacted a LOT
307 \item Overlapping "Vectors" may issue overlapping ops
308 \item Please don't use Vectors for "security" (use Sec-Ext)
309 \end{itemize}
310 }
311 % with overlapping "vectors" - bearing in mind that "vectors" are
312 % just a remap onto the standard register file, if the top bits of
313 % predication are zero, and there happens to be a second vector
314 % that uses some of the same register file that happens to be
315 % predicated out, the second vector op may be issued *at the same time*
316 % if there are available parallel ALUs to do so.
317
318
319 \frame{\frametitle{Predication key-value CSR store}
320
321 \begin{itemize}
322 \item key is int regfile number or FP regfile number (1 bit)\vspace{6pt}
323 \item register to be predicated if referred to (5 bits, key)\vspace{6pt}
324 \item register to store actual predication in (5 bits, value)\vspace{6pt}
325 \item predication is inverted (1 bit)\vspace{6pt}
326 \item non-predicated elements are to be zero'd (1 bit)\vspace{6pt}
327 \end{itemize}
328 Notes:\vspace{10pt}
329 \begin{itemize}
330 \item Table should be expanded out for high-speed implementations
331 \item Multiple "keys" (and values) theoretically permitted
332 \item RVV rules about deleting higher-indexed CSRs followed
333 \end{itemize}
334 }
335
336
337 \frame{\frametitle{Register key-value CSR store}
338
339 \begin{itemize}
340 \item key is int regfile number or FP regfile number (1 bit)\vspace{6pt}
341 \item treated as vector if referred to in op (5 bits, key)\vspace{6pt}
342 \item starting register to actually be used (5 bits, value)\vspace{6pt}
343 \item element bitwidth: default/8/16/32/64/rsvd (3 bits)\vspace{6pt}
344 \item element type: still under consideration\vspace{6pt}
345 \end{itemize}
346 Notes:\vspace{10pt}
347 \begin{itemize}
348 \item Same notes apply (previous slide) as for predication CSR table
349 \item Level of indirection has implications for pipeline latency
350 \end{itemize}
351 }
352
353
354 \frame{\frametitle{C.MV extremely flexible!}
355
356 \begin{itemize}
357 \item scalar-to-vector (w/no pred): VSPLAT
358 \item scalar-to-vector (w/dest-pred): Sparse VSPLAT
359 \item scalar-to-vector (w/single dest-pred): VINSERT
360 \item vector-to-scalar (w/src-pred): VEXTRACT
361 \item vector-to-vector (w/no pred): Vector Copy
362 \item vector-to-vector (w/src xor dest pred): Sparse Vector Copy
363 \item vector-to-vector (w/src and dest pred): Vector Gather/Scatter
364 \end{itemize}
365 \vspace{8pt}
366 Notes:\vspace{10pt}
367 \begin{itemize}
368 \item Really powerful!
369 \item Any other options?
370 \end{itemize}
371 }
372
373
374 \frame{\frametitle{Opcodes, compared to RVV}
375
376 \begin{itemize}
377 \item All integer and FP opcodes all removed (no CLIP!)\vspace{8pt}
378 \item VMPOP, VFIRST etc. all removed (use xBitManip)\vspace{8pt}
379 \item VSLIDE removed (use regfile overlaps)\vspace{8pt}
380 \item C.MV covers VEXTRACT VINSERT and VSPLAT (and more)\vspace{8pt}
381 \item VSETVL, VGETVL, VSELECT stay\vspace{8pt}
382 \item Issue: VCLIP is not in RV* (add with custom ext?)\vspace{8pt}
383 \item Vector (or scalar-vector) use C.MV (MV is a pseudo-op)\vspace{8pt}
384 \item VMERGE: twin predicated C.MVs (one inverted. macro-op'd)\vspace{8pt}
385 \end{itemize}
386 }
387
388
389 \frame{\frametitle{Under consideration}
390
391 \begin{itemize}
392 \item Is C.FNE actually needed? Should it be added if it is?
393 \item Element type implies polymorphism. Should it be in SV?
394 \item Should use of registers be allowed to "wrap" (x30 x31 x1 x2)?
395 \item Is detection of all-scalar ops ok (without slowing pipeline)?
396 \item Can VSELECT be removed? (it's really complex)
397 \item Can CLIP be done as a CSR (mode, like elwidth)
398 \item SIMD saturation (etc.) also set as a mode?
399 \item C.MV src predication no different from dest predication\\
400 What to do? Make one have different meaning?
401 \item 8/16-bit ops is it worthwhile adding a "start offset"? \\
402 (a bit like misaligned addressing... for registers)\\
403 or just use predication to skip start?
404 \end{itemize}
405 }
406
407
408 \frame{\frametitle{What's the downside(s) of SV?}
409 \begin{itemize}
410 \item EVERY register operation is inherently parallelised\\
411 (scalar ops are just vectors of length 1)
412 \item An extra pipeline phase is pretty much essential\\
413 for fast low-latency implementations
414 \item Assuming an instruction FIFO, N ops could be taken off\\
415 of a parallel op per cycle (avoids filling entire FIFO;\\
416 also is less work per cycle: lower complexity / latency)
417 \item With zeroing off, skipping non-predicated elements is hard:\\
418 it is however an optimisation (and could be skipped).
419 \end{itemize}
420 }
421
422
423 \frame{\frametitle{Is this OK (low latency)? Detect scalar-ops (only)}
424 \begin{center}
425 \includegraphics[height=2.5in]{scalardetect.png}\\
426 {\bf \red Detect when all registers are scalar for a given op}
427 \end{center}
428 }
429
430
431 \frame{\frametitle{TODO (break into separate slides)}
432
433 \begin{itemize}
434 \item Then explain why this proposal is a good way to \\
435 abstract parallelism\\
436 (hopefully also explaining how \\
437 a good compiler can make clever use of this increase parallelism\\
438 Then explain how this can be implemented (at instruction\\
439 issue time???) with\\
440 implementation options, and what these "cost".\\
441 Finally give examples that show simple usage that compares\\
442 C code\\
443 RVIC\\
444 RVV\\
445 RVICXsimplev
446 \end{itemize}
447 }
448
449
450 \frame{\frametitle{Summary}
451
452 \begin{itemize}
453 \item Designed for flexibility (graded levels of complexity)\vspace{6pt}
454 \item Huge range of implementor freedom\vspace{6pt}
455 \item Fits RISC-V ethos: achieve more with less\vspace{6pt}
456 \item Reduces SIMD ISA proliferation by 3-4 orders of magnitude \\
457 (without SIMD downsides or sacrificing speed trade-off)\vspace{6pt}
458 \item Covers 98\% of RVV, allows RVV to fit "on top"\vspace{6pt}
459 \item Not designed for supercomputing (that's RVV), designed for
460 in between: DSPs, RV32E, Embedded 3D GPUs etc.\vspace{6pt}
461 \item Not specifically designed for Vectorisation: designed to\\
462 reduce code size (increase efficiency, just
463 like Compressed)\vspace{6pt}
464 \end{itemize}
465 }
466
467
468 \frame{\frametitle{slide}
469
470 \begin{itemize}
471 \item \vspace{10pt}
472 \end{itemize}
473 Considerations:\vspace{10pt}
474 \begin{itemize}
475 \item \vspace{10pt}
476 \end{itemize}
477 }
478
479
480 \frame{
481 \begin{center}
482 {\Huge \red The end\vspace{20pt}\\
483 Thank you}
484 \end{center}
485 }
486
487
488 \end{document}