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