Automatic commit of irc logs
[ipdf/documents.git] / LiteratureNotes.tex
1 \documentclass[8pt]{extreport}
2 \input{template}
3 \begin{document}
4
5
6 \pagestyle{fancy}
7 \fancyhead{}
8 \fancyfoot{}
9
10 \fancyhead[LO, L]{}
11 \fancyfoot[CO, C]{\thepage}
12
13 \begin{center}
14         B.Eng. Final Year Project \par
15         {\bf \Large Literature Notes} \par
16         Sam Moore, David Gow \\
17         Faculty of Engineering, Computing and Mathematics, University of Western Australia \\
18         March 2014
19 \end{center}
20
21 \tableofcontents
22
23 \chapter{Literature Summaries}
24
25 \section{Postscript Language Reference Manual  \cite{plrm}}
26
27 Adobe's official reference manual for PostScript.
28
29 It is big.
30
31 \begin{itemize}
32         \item First version was published BEFORE the IEEE standard and used smaller floats than binary32
33         \item Now uses binary32 floats.
34 \end{itemize}
35
36 \section{Portable Document Format Reference Manual  \cite{pdfref17}}
37
38 Adobe's official reference for PDF.
39
40 It is also big.
41
42 \begin{itemize}
43         \item Early versions did not use IEEE binary32 but 16-16 exponent/mantissa encodings (Why?)
44         \item Current standard is restricted to binary32
45         \item It specifically says PDF creators must use at most binary32 because higher precision is not supported by Adobe Reader.
46 \end{itemize}
47
48 \section{IEEE Standard for Floating-Point Arithmetic \cite{ieee2008-754}}
49
50 The IEEE (revised) 754 standard.
51
52 It is also big.
53
54 Successes:
55 \begin{itemize}
56         \item Has been adopted by CPUs
57         \item Standardised floats for programmers --- accomplishes goal of allowing non-numerical experts to write reasonably sophisticated platform independent programs that may perform complex numerical operations
58 \end{itemize}
59
60 Failures:
61 \begin{itemize}
62         \item Adoption by GPUs slower\cite{hillesland2004paranoia}
63         \item It specifies the maximum errors for operations using IEEE types but nothing about internal representations
64         \item Many hardware devices (GPUs and CPUs) use non-IEEE representations internally and simply truncate/round the result
65         \begin{itemize}
66                 \item This isn't so much of a problem when the device uses additional bits but it is misleading when GPUs use less than binary32 and act as if they are using binary32 from the programmer's perspective.
67                 \item Devices using {\bf less} bits internally aren't IEEE compliant
68         \end{itemize}
69         \item Thus the same program compiled and run on different architectures may give completely different results\cite{HFP}
70         \begin{itemize}
71                 \item The ultimate goal of allowing people to write numerical programs in total ignorance of the hardware is not entirely realised
72         \end{itemize}
73         \item This is the sort of thing that makes people want to use a virtual machine, and thus Java
74         \begin{itemize}
75                 \item Objectively I probably shouldn't say that using Java is in itself a failure
76         \end{itemize}
77         \item Standards such as PostScript and PDF were slow to adopt IEEE representations
78         \item The OpenVG standard accepts IEEE binary32 in the API but specifically states that hardware may use less than this\cite{rice2008openvg}
79 \end{itemize}
80
81
82
83 \pagebreak
84
85 \section{Portable Document Format (PDF) --- Finally...  \cite{cheng2002portable}}
86
87 This is not spectacularly useful, is basically an advertisement for Adobe software.
88
89 {\bf Intro}
90 \begin{itemize}
91         \item Visual communications has been revolutionised by computing
92         \item BUT there have always been problems in exchanging formats
93         \item Filetypes like text, rich text, IGES, DXF, TIFF, JPEG, GIFF solve problems for particular types of files only
94         \item PDF solves everything for everyone; can include text, images, animation, sound, etc
95 \end{itemize}
96 {\bf PDF Features}
97 \begin{itemize}
98         \item Raster Image Process (RIP) --- For printing (presumably also displaying on screen)
99         \item Originally needed to convert to PS then RIP, with PS 3 can now RIP directly.
100         \item Reduced filesize due to compression
101         \item Four major applications - Stoy 1999\cite{stoy1999}
102                 \begin{enumerate}
103                         \item Download files from internet
104                         \item Files on CDs
105                         \item Files for outputing to printers
106                         \item Conventional [commercial scale?] printing
107                 \end{enumerate}
108         \item List of various (Adobe) PDF related software
109         \begin{itemize}
110                 \item Includes software for PS that converts to/from PDF 
111                 \item So PS was obviously pretty popular before PDF
112         \end{itemize}
113         \item Can Optimize for screen/printer [not clear how]
114         \item Can compress for size
115 \end{itemize}
116
117 \pagebreak
118 \section{Pixels or Perish  \cite{hayes2012pixels}}
119
120 ``The art of scientific illustration will have to adapt to the new age of online publishing''
121 And therefore, JavaScript libraries ($\text{D}^3$) are the future.
122
123 The point is that we need to change from thinking about documents as paper to thinking of them as pixels.
124 This kind of makes it related to our paper, because it is the same way we are justifying our project. It does mention precision, but doesn't say we need to get more of it.
125
126 I get the feeling from this that Web based documents are a whole bunch of completely different design philosophies hacked together
127 with JavaScript.
128
129 This paper uses Metaphors a lot. I never met a phor that didn't over extend itself.
130
131
132 {\bf Intro}
133 \begin{itemize}
134         \item Drawings/Pictures are ornaments in science but they are not just ornamental
135         \item Processes have changed a lot; eg: photographic plates $\to$ digital images
136         \item ``we are about to turn the page --- if not close the book --- on yet another chapter in publishing history.'' (HO HO HO)
137         \item It would be cool to have animated figures in documents (eg: Population pyramid; changes with time); not just as ``supplements''
138         \item In the beginning, there was PostScript, 1970s and 1980s, John Warnock and Charles Geschke, Adobe Systems
139         \item PS is a language for vector graphics; objects are constructed from geometric primitives rather than a discrete array of pixels
140         \item PS is a complete programming language; an image is also a program; can exploit this to control how images are created based on data (eg: Faces)
141         \item PDF is ``flattened'' PS. No longer programable. Aspires to be ``virtual paper''.
142         \item But why are we using such powerful computing machines just to emulate sheets paper? (the author asks)
143 \end{itemize}
144
145 {\bf Web based Documents}
146 \begin{itemize}
147         \item HTML, CSS, JavaScript - The Axis of Web Documents
148         \begin{itemize}
149                 \item HTML - Defines document structure
150                 \item CSS - Defines presentation of elements in document
151                 \item JavaScript - Encodes actions, allows dynamic content (change the HTML/CSS)
152         \end{itemize}
153         \item \texttt{<canvas>} will let you draw anything (So in principle don't even need all of HTML/CSS)
154         \begin{itemize}
155                 \item Not device independent
156                 \item ``Coordinates can be specified with precision finer than pixel resolution'' {\bf (TODO: Investigate this?)}
157                 \item JavaScript operators to draw things on canvas are very similar to the PostScript model
158         \end{itemize}
159         \item SVG --- Same structure (Document Object Model (DOM)) as HTML
160         \begin{itemize}
161                 \item ``Noun language''
162                 \item Nouns define lines/curves etc, rather than paragraphs/lists
163                 \item Also borrows things from PostScript (eg: line caps and joints)
164                 \item IS device independent, ``very high precision'' {\bf (TODO: Investigate)}
165                 \item JavaScript can be used to interact with SVG too
166         \end{itemize}
167         \item $\text{D}^{3}$ (Data Driven Documents) - A JavaScript library
168         \begin{itemize}
169                 \item Idea is to create or modify elements of a DOM document using supplied data
170                 \item \url{https://github.com/mbostock/d3/wiki}
171         \end{itemize}
172         \item We are in a new Golden Age of data visualisation
173         \item Why do we still use PDFs?
174         \begin{itemize}
175                 \item PDFs are ``owned'' by the author/reader; you download it, store it, you can print it, etc
176                 \item HTML documents are normally on websites. They are not self contained. They often rely on remote content from other websites (annoying to download the whole document).
177         \end{itemize}
178         \item {\bf Conclusion} Someone should open up PDF to accept things like $\text{D}^{3}$ and other graphics formats (links nicely with \cite{barnes2013embedding})
179         \item Also, Harry Potter reference
180
181 \end{itemize}
182
183 \section{Embedding and Publishing Interactive, 3D Figures in PDF Files  \cite{barnes2013embedding}}
184
185 \begin{itemize}
186         \item Linkes well with \cite{hayes2012pixels}; I heard you liked figures so I put a figure in your PDF
187         \item Title pretty much summarises it; similar to \cite{hayes2012pixels} except these guys actually did something practical
188 \end{itemize}
189
190 \section{27 Bits are not enough for 8 digit accuracy  \cite{goldberg1967twentyseven}}
191
192 Proves with maths, that rounding errors mean that you need at least $q$ bits for $p$ decimal digits. $10^p < 2^{q-1}$
193
194 \begin{itemize}
195         \item Eg: For 8 decimal digits, since $10^8 < 2^{27}$ would expect to be able to represent with 27 binary digits
196         \item But: Integer part requires digits bits (regardless of fixed or floating point represenetation)
197         \item Trade-off between precision and range
198         \begin{itemize}
199                 \item 9000000.0 $\to$ 9999999.9 needs 24 digits for the integer part $2^{23} = 83886008$
200         \end{itemize}
201         \item Floating point zero = smallest possible machine exponent
202         \item Floating point representation:
203         \begin{align*}
204                 y &= 0.y_1 y_2 \text{...} y_q \times 2^{n}
205         \end{align*}
206         \item Can eliminate a bit by considering whether $n = -e$ for $-e$ the smallest machine exponent (???)
207         \begin{itemize}
208                 \item Get very small numbers with the same precision    
209                 \item Get large numbers with the extra bit of precision
210         \end{itemize}
211 \end{itemize}
212
213 \section{What every computer scientist should know about floating-point arithmetic  \cite{goldberg1991whatevery}}
214
215 \begin{itemize}
216         \item Book: \emph{Floating Point Computation} by Pat Sterbenz (out of print... in 1991)
217     \item IEEE floating point standard becoming popular (introduced in 1987, this is 1991)
218     \begin{itemize}
219                 \item As well as structure, defines the algorithms for addition, multiplication, division and square root
220                 \item Makes things portable because results of operations are the same on all machines (following the standard)
221                 \item Alternatives to floating point: Floating slasi and Signed Logarithm (TODO: Look at these, although they will probably not be useful)
222
223         \end{itemize}
224         \item Base $\beta$ and precision $p$ (number of digits to represent with) - powers of the base can be represented exactly.
225         \item Largest and smallest exponents $e_{min}$ and $e_{max}$
226         \item Need bits for exponent and fraction, plus one for sign
227         \item ``Floating point number'' is one that can be represented exactly.
228         \item Representations are not unique! $0.01 \times 10^1 = 1.00 \times 10^{-1}$ Leading digit of one $\implies$ ``normalised''
229         \item Requiring the representation to be normalised makes it unique, {\bf but means it is impossible to represent zero}.
230         \begin{itemize}
231                 \item Represent zero as $1 \times \beta^{e_{min}-1}$ - requires extra bit in the exponent
232         \end{itemize}
233         \item {\bf Rounding Error}
234         \begin{itemize}
235                 \item ``Units in the last place'' eg: 0.0314159 compared to 0.0314 has ulp error of 0.159
236                 \item If calculation is the nearest floating point number to the result, it will still be as much as 1/2 ulp in error
237                 \item Relative error corresponding to 1/2 ulp can vary by a factor of $\beta$ ``wobble''. Written in terms of $\epsilon$
238                 \item Maths $\implies$ {\bf Relative error is always bounded by $\epsilon = (\beta/2)\beta^{-p}$}
239                 \item Fixed relative error $\implies$ ulp can vary by a factor of $\beta$ . Vice versa
240                 \item Larger $\beta \implies$ larger errors
241         \end{itemize}
242         \item {\bf Guard Digits}
243         \begin{itemize}
244                 \item In subtraction: Could compute exact difference and then round; this is expensive
245                 \item Keep fixed number of digits but shift operand right; discard precision. Lead to relative error up to $\beta - 1$
246                 \item Guard digit: Add extra digits before truncating. Leads to relative error of less than $2\epsilon$. This also applies to addition
247         \end{itemize}
248         \item {\bf Catastrophic Cancellation} - Operands are subject to rounding errors - multiplication
249         \item {\bf Benign Cancellation} - Subtractions. Error $< 2\epsilon$
250         \item Rearrange formula to avoid catastrophic cancellation
251         \item Historical interest only - speculation on why IBM used $\beta = 16$ for the system/370 - increased range? Avoids shifting
252         \item Precision: IEEE defines extended precision (a lower bound only)
253         \item Discussion of the IEEE standard for operations (TODO: Go over in more detail)
254         \item NaN allow continuing with underflow and Infinity with overflow
255         \item ``Incidentally, some people think that the solution to such anomalies is never to compare floating-point numbers for equality but instead to consider them equal if they are within some error bound E. This is hardly a cure all, because it raises as many questions as it answers.'' - On equality of floating point numbers
256
257 \end{itemize}
258
259
260 %%%%
261 % David's Stuff
262 %%%%
263 \section{Compositing Digital Images  \cite{porter1984compositing}}
264
265
266
267 Perter and Duff's classic paper "Compositing Digital Images" lays the
268 foundation for digital compositing today. By providing an "alpha channel,"
269 images of arbitrary shapes â€” and images with soft edges or sub-pixel coverage
270 information â€” can be overlayed digitally, allowing separate objects to be
271 rasterized separately without a loss in quality.
272
273 Pixels in digital images are usually represented as 3-tuples containing
274 (red component, green component, blue component). Nominally these values are in
275 the [0-1] range. In the Porter-Duff paper, pixels are stored as $(R,G,B,\alpha)$
276 4-tuples, where alpha is the fractional coverage of each pixel. If the image
277 only covers half of a given pixel, for example, its alpha value would be 0.5.
278
279 To improve compositing performance, albeit at a possible loss of precision in
280 some implementations, the red, green and blue channels are premultiplied by the
281 alpha channel. This also simplifies the resulting arithmetic by having the
282 colour channels and alpha channels use the same compositing equations.
283
284 Several binary compositing operations are defined:
285 \begin{itemize}
286 \item over
287 \item in
288 \item out
289 \item atop
290 \item xor
291 \item plus
292 \end{itemize}
293
294 The paper further provides some additional operations for implementing fades and
295 dissolves, as well as for changing the opacity of individual elements in a
296 scene.
297
298 The method outlined in this paper is still the standard system for compositing
299 and is implemented almost exactly by modern graphics APIs such as \texttt{OpenGL}. It is
300 all but guaranteed that this is the method we will be using for compositing
301 document elements in our project.
302
303
304
305 \section{Bresenham's Algorithm: Algorithm for computer control of a digital plotter  \cite{bresenham1965algorithm}}
306 Bresenham's line drawing algorithm is a fast, high quality line rasterization
307 algorithm which is still the basis for most (aliased) line drawing today. The
308 paper, while originally written to describe how to control a particular plotter,
309 is uniquely suited to rasterizing lines for display on a pixel grid.
310
311 Lines drawn with Bresenham's algorithm must begin and end at integer pixel
312 coordinates, though one can round or truncate the fractional part. In order to
313 avoid multiplication or division in the algorithm's inner loop, 
314
315 The algorithm works by scanning along the long axis of the line, moving along
316 the short axis when the error along that axis exceeds 0.5px. Because error
317 accumulates linearly, this can be achieved by simply adding the per-pixel
318 error (equal to (short axis/long axis)) until it exceeds 0.5, then incrementing
319 the position along the short axis and subtracting 1 from the error accumulator.
320
321 As this requires nothing but addition, it is very fast, particularly on the
322 older CPUs used in Bresenham's time. Modern graphics systems will often use Wu's
323 line-drawing algorithm instead, as it produces antialiased lines, taking
324 sub-pixel coverage into account. Bresenham himself extended this algorithm to
325 produce Bresenham's circle algorithm. The principles behind the algorithm have
326 also been used to rasterize other shapes, including B\'{e}zier curves.
327
328 \section{Quad Trees: A Data Structure for Retrieval on Composite Keys  \cite{finkel1974quad}}
329
330 This paper introduces the ``quadtree'' spatial data structure. The quadtree structure is
331 a search tree in which every node has four children representing the north-east, north-west,
332 south-east and south-west quadrants of its space.
333
334 \section{Xr: Cross-device Rendering for Vector Graphics  \cite{worth2003xr}}
335
336 Xr (now known as Cairo) is an implementation of the PDF v1.4 rendering model,
337 independent of the PDF or PostScript file formats, and is now widely used
338 as a rendering API. In this paper, Worth and Packard describe the PDF v1.4 rendering
339 model, and their PostScript-derived API for it.
340
341 The PDF v1.4 rendering model is based on the original PostScript model, based around
342 a set of \emph{paths} (and other objects, such as raster images) each made up of lines
343 and B\'{e}zier curves, which are transformed by the ``Current Transformation Matrix.''
344 Paths can be \emph{filled} in a number of ways, allowing for different handling of self-intersecting
345 paths, or can have their outlines \emph{stroked}.
346 Furthermore, paths can be painted with RGB colours and/or patterns derived from either
347 previously rendered objects or external raster images.
348 PDF v1.4 extends this to provide, amongst other features, support for layering paths and
349 objects using Porter-Duff compositing\cite{porter1984compositing}, giving each painted path
350 the option of having an $\alpha$ value and a choice of any of the Porter-Duff compositing
351 methods.
352
353 The Cairo library approximates the rendering of some objects (particularly curved objects
354 such as splines) with a set of polygons. An \texttt{XrSetTolerance} function allows the user
355 of the library to set an upper bound on the approximation error in fractions of device pixels,
356 providing a trade-off between rendering quality and performance. The library developers found
357 that setting the tolerance to greater than $0.1$ device pixels resulted in errors visible to the
358 user.
359
360 \section{Glitz: Hardware Accelerated Image Compositing using OpenGL  \cite{nilsson2004glitz}}
361
362 This paper describes the implementation of an \texttt{OpenGL} based rendering backend for
363 the \texttt{Cairo} library. 
364
365 The paper describes how OpenGL's Porter-Duff compositing is easily suited to the Cairo/PDF v1.4
366 rendering model. Similarly, traditional OpenGL (pre-version 3.0 core) support a matrix stack
367 of the same form as Cairo.
368
369 The ``Glitz'' backend will emulate support for tiled, non-power-of-two patterns/textures if
370 the hardware does not support it.
371
372 Glitz can render both triangles and trapezoids (which are formed from pairs of triangles).
373 However, it cannot guarantee that the rasterization is pixel-precise, as OpenGL does not proveide
374 this consistently.
375
376 Glitz also supports multi-sample anti-aliasing, convolution filters for raster image reads (implemented
377 with shaders).
378
379 Performance was much improved over the software rasterization and over XRender accellerated rendering
380 on all except nVidia hardware. However, nVidia's XRender implementation did slow down significantly when
381 some transformations were applied.
382
383 In \cite{kilgard2012gpu}, Kilgard mentions that Glitz has been abandoned. He describes it as ''GPU assisted'' rather than GPU accelerated, since it used the XRender (??) extension.
384
385 %% Sam again
386
387 \section{Boost Multiprecision Library}
388
389 \begin{itemize}
390         \item ``The Multiprecision Library provides integer, rational and floating-point types in C++ that have more range and precision than C++'s ordinary built-in types.''
391         \item Specify number of digits for precision as a template argument.
392         \item Precision is fixed... {\bf possible approach to project:} Use \verb/boost::mpf_float<N>/ and increase \verb/N/ as more precision is required?
393 \end{itemize}
394
395
396 % Some hardware related sounding stuff...
397
398 \section{A CMOS Floating Point Unit  \cite{kelley1997acmos}}
399
400 The paper describes the implentation of a FPU for PowerPC using a particular Hewlett Packard process (HP14B 0.5$\mu$m, 3M, 3.3V).
401 It implements a ``subset of the most commonly used double precision floating point instructions''. The unimplemented operations are compiled for the CPU.
402
403 The paper gives a description of the architecture and design methods.
404 This appears to be an entry to a student design competition.
405
406 Standard is IEEE 754, but the multiplier tree is a 64-bit tree instead of a 54 bit tree.
407 `` The primary reason for implementing a larger tree is for future additions of SIMD [Single Instruction Multiple Data (?)] instructions similar to Intel's MMX and Sun's VIS instructions''.
408
409 HSPICE simulations used to determine transistor sizing.
410
411 Paper has a block diagram that sort of vaguely makes sense to me.
412 The rest requires more background knowledge.
413
414 \section{Simply FPU\cite{filiatreault2003simply}}
415
416 This is a webpage at one degree of seperation from wikipedia.
417
418 It talks about FPU internals, but mostly focuses on the instruction sets.
419 It includes FPU assembly code examples (!)
420
421 It is probably not that useful, I don't think we'll end up writing FPU assembly?
422
423 FPU's typically have 80 bit registers so they can support REAL4, REAL8 and REAL10 (single, double, extended precision).
424
425 Note: Presumably this is referring to the x86 80 bit floats that David was talking about?
426
427
428 \section{Floating Point Package User's Guide  \cite{bishop2008floating}}
429
430 This is a technical report describing floating point VHDL packages \url{http://www.vhdl.org/fphdl/vhdl.html}
431
432 In theory I know VHDL (cough) so I am interested in looking at this further to see how FPU hardware works.
433 It might be getting a bit sidetracked from the ``document formats'' scope though.
434
435 The report does talk briefly about the IEEE standard and normalised / denormalised numbers as well.
436
437 See also: Java Optimized Processor\cite{jop} (it has a VHDL implementation of a FPU).
438
439 \section{Low-Cost Microarchitectural Support for Improved Floating-Point Accuracy\cite{dieter2007lowcost}}
440
441 Mentions how GPUs offer very good floating point performance but only for single precision floats. (NOTE: This statement seems to contradict \cite{hillesland2004paranoia}.
442
443 Has a diagram of a Floating Point adder.
444
445 Talks about some magical technique called "Native-pair Arithmetic" that somehow makes 32-bit floating point accuracy ``competitive'' with 64-bit floating point numbers.
446
447 \section{Accurate Floating Point Arithmetic through Hardware Error-Free Transformations  \cite{kadric2013accurate}}
448
449 From the abstract: ``This paper presents a hardware approach to performing ac-
450 curate floating point addition and multiplication using the idea of error-
451 free transformations. Specialized iterative algorithms are implemented
452 for computing arbitrarily accurate sums and dot products.''
453
454 The references for this look useful.
455
456 It also mentions VHDL.
457
458 So whenever hardware papers come up, VHDL gets involved...
459 I guess it's time to try and work out how to use the Opensource VHDL implementations.
460
461 This is about reduction of error in hardware operations rather than the precision or range of floats.
462 But it is probably still relevant.
463
464 This has the Fast2Sum algorithm but for the love of god I cannot see how you can compute anything other than $a + b = 0 \forall a,b$ using the algorithm as written in their paper. It references Dekker\cite{dekker1971afloating} and Kahn; will look at them instead.
465
466 \section{Floating Point Unit from JOP  \cite{jop}}
467
468 This is a 32 bit floating point unit developed for JOP in VHDL.
469 I have been able to successfully compile it and the test program using GHDL\cite{ghdl}. 
470
471 Whilst there are constants (eg: \verb/FP_WIDTH = 32, EXP_WIDTH = 8, FRAC_WIDTH = 23/) defined, the actual implementation mostly uses magic numbers, so 
472 some investigation is needed into what, for example, the "52" bits used in the sqrt units are for.
473
474 \section{GHDL  \cite{ghdl}}
475
476 GHDL is an open source GPL licensed VHDL compiler written in Ada. It had packages in debian up until wheezy when it was removed. However the sourceforge site still provides a \shell{deb} file for wheezy.
477
478 This reference explains how to use the \shell{ghdl} compiler, but not the VHDL language itself.
479
480 GHDL is capable of compiling a ``testbench'' - essentially an executable which simulates the design and ensures it meets test conditions.
481 A common technique is using a text file to provide the inputs/outputs of the test. The testbench executable can be supplied an argument to save a \shell{vcd} file which can be viewed in \shell{gtkwave} to see timing diagrams.
482
483 Sam has successfully compiled the VHDL design for an FPU in JOP\cite{jop} into a ``testbench'' executable which uses standard i/o instead of a regular file.
484 Using unix domain sockets we can execute the FPU as a child process and communicate with it from our document viewing test software. This means we can potentially simulate alternate hardware designs for FPUs and witness the effect they will have on precision in the document viewer.
485
486 Using \shell{ghdl} the testbench can also be linked as part a C/C++ program and run using a function; however there is still no way to communicate with it other than forking a child process and using a unix domain socket anyway. Also, compiling the VHDL FPU as part of our document viewer would clutter the code repository and probably be highly unportable. The VHDL FPU has been given a seperate repository.
487
488 \section{On the design of fast IEEE floating-point adders  \cite{seidel2001onthe}}
489
490 This paper gives an overview of the ``Naive'' floating point addition/subtraction algorithm and gives several optimisation techniques:
491
492 TODO: Actually understand these...
493
494 \begin{itemize}
495         \item Use parallel paths (based on exponent)
496         \item Unification of significand result ranges
497         \item Reduction of IEEE rounding modes
498         \item Sign-magnitude computation of a difference
499         \item Compound Addition
500         \item Approximate counting of leading zeroes
501         \item Pre-computation of post-normalization shift
502 \end{itemize}
503
504 They then give an implementation that uses these optimisation techniques including very scary looking block diagrams.
505
506 They simulated the FPU. Does not mention what simulation method was used directly, but cites another paper (TODO: Look at this. I bet it was VHDL).
507
508 The paper concludes by summarising the optimisation techniques used by various adders in production (in 2001).
509
510 This paper does not specifically mention the precision of the operations, but may be useful because a faster adder design might mean you can increase the precision.
511
512 \section{Re: round32 ( round64 ( X ) ) ?= round32 ( X )  \cite{beebe2011round32}}
513
514 I included this just for the quote by Nelson H. F. Beebe:
515
516 ``It is too late now to repair the mistakes of the past that are present
517 in millions of installed systems, but it is good to know that careful
518 research before designing hardware can be helpful.''
519
520 This is in regards to the problem of double rounding. It provides a reference for a paper that discusses a rounding mode that eliminates the problem, and a software implementation.
521
522 It shows that the IEEE standard can be fallible!
523
524 Not sure how to work this into our literature review though.
525
526 % Back to software
527 \section{Basic Issues in Floating Point Arithmetic and Error Analysis  \cite{demmel1996basic}}
528
529 These are lecture notes from U.C Berkelye CS267 in 1996.
530
531
532 \section{Charles Babbage  \cite{dodge_babbage, nature1871babbage}}
533
534 Tributes to Charles Babbage. Might be interesting for historical background. Don't mention anything about floating point numbers though.
535
536 \section{GPU Floating-Point Paranoia  \cite{hillesland2004paranoia}}
537
538 This paper discusses floating point representations on GPUs. They have reproduced the program \emph{Paranoia} by William Kahan for characterising floating point behaviour of computers (pre IEEE) for GPUs.
539
540
541 There are a few remarks about GPU vendors not being very open about what they do or do not do with 
542
543
544 Unfortunately we only have the extended abstract, but a pretty good summary of the paper (written by the authors) is at: \url{www.cs.unc.edu/~ibr/projects/paranoia/}
545
546 From the abstract:
547
548 ``... [GPUs are often similar to IEEE] However, we have found
549 that GPUs do not adhere to IEEE standards for floating-point op-
550 erations, nor do they give the information necessary to establish
551 bounds on error for these operations ... ''
552
553 and ``...Our goal is to determine the error bounds on floating-point op-
554 eration results for quickly evolving graphics systems. We have cre-
555 ated a tool to measure the error for four basic floating-point opera-
556 tions: addition, subtraction, multiplication and division.''
557
558 The implementation is only for windows and uses glut and glew and things.
559 Implement our own version?
560
561 \section{A floating-point technique for extending the available precision  \cite{dekker1971afloating}}
562
563 This is Dekker's formalisation of the Fast2Sum algorithm originally implemented by Kahn.
564
565 \begin{align*}
566         z &= \text{RN}(x + y) \\
567         w &= \text{RN}(z - x) \\
568         zz &= \text{RN}(y - w) \\
569         \implies z + zz &= x + y
570 \end{align*}
571
572 There is a version for multiplication.
573
574 I'm still not quite sure when this is useful. I haven't been able to find an example for $x$ and $y$ where $x + y \neq \text{Fast2Sum}(x, y)$.
575
576 \section{Handbook of Floating-Point Arithmetic \cite{HFP}}
577
578 This book is amazingly useful and pretty much says everything there is to know about Floating Point numbers.
579 It is much easier to read than Goldberg or Priest's papers.
580
581 I'm going to start working through it and compile their test programs.
582
583 \subsection{A sequence that seems to converge to a wrong limit  - pgs 9-10, \cite{HFP}}
584
585 \begin{align*}
586         u_n &= \left\{ \begin{array}{c} u_0 = 2 \\ u_1 = -4 \\ u_n = 111 - \frac{1130}{u_{n-1}} + \frac{3000}{u_{n-1}u_{n-2}}\end{array}\right.
587 \end{align*}
588
589 The limit of the series should be $6$ but when calculated with IEEE floats it is actually $100$
590 The authors show that the limit is actually $100$ for different starting values, and the error in floating point arithmetic causes the series to go to that limit instead.
591
592 \begin{figure}[H]
593         \centering
594         \includegraphics[width=0.8\textwidth]{figures/handbook1-1.pdf}
595         \caption{Output of Program 1.1 from \emph{Handbook of Floating-Point Arithmetic}\cite{HFP} for various IEEE types}
596         \label{HFP-1-1}
597 \end{figure}
598
599 \subsection{Mr Gullible and the Chaotic Bank Society pgs 10-11 \cite{HFP}}
600
601 This is an example of a sequence involving $e$. Since $e$ cannot be represented exactly with FP, even though the sequence should go to $0$ for $a_0 = e - 1$, the representation of $a_0 \neq e - 1$ so the sequence goes to $\pm \infty$.
602
603 To eliminate these types of problems we'd need an \emph{exact} representation of all real numbers.
604 For \emph{any} FP representation, regardless of precision (a finite number of digits) there will be numbers that can't be represented exactly hence you could find a similar sequence that would explode.
605
606 IE: The more precise the representation, the slower things go wrong, but they still go wrong, {\bf even with errorless operations}.
607
608
609 \subsection{Rump's example pg 12 \cite {HFP}}
610
611 This is an example where the calculation of a function $f(a,b)$ is not only totally wrong, it gives completely different results depending on the CPU. Despite the CPU conforming to IEEE.
612
613 \section{Scalable Vector Graphics (SVG) 1.1 (Second Edition) \cite{svg2011-1.1}}
614
615 Scalable Vector Graphics (SVG) is a XML language for describing two dimensional graphics. This document is \url{http://www.w3.org/TR/2011/REC-SVG11-20110816/}, the latest version of the standard at the time of writing.
616
617 \subsubsection{Three types of object}
618 \begin{enumerate}
619         \item Vector graphics shapes (paths)
620         \item Images (embedded bitmaps)
621         \item Text
622 \end{enumerate}
623
624 \subsubsection{Rendering Model and Precision}
625
626 SVG uses the ``painter's model''. Paint is applied to regions of the page in an order, covering the paint below it according to rules for alpha blending.
627
628 ``Implementations of SVG are expected to behave as though they implement a rendering (or imaging) model cor-
629 responding to the one described in this chapter. A real implementation is not required to implement the model in
630 this way, but the result on any device supported by the implementation shall match that described by this model.''
631
632 SVG uses {\bf single precision floats}. Unlike PDF and PostScript, the standard specifies this as a {\bf minimum} range from \verb/-3.4e+38F/ to \verb/+3.4e+38F/
633
634 ``It is recommended that higher precision floating point storage and computation be performed on operations
635 such as coordinate system transformations to provide the best possible precision and to prevent round-off errors.''
636
637 There is also a ``High Quality SVG Viewers'' requirement to use at least {\bf double} precision floats.
638
639 \section{OpenVG Specification 1.1 \cite{rice2008openvg}}
640 ``OpenVG is an application programming interface (API) for hardware-accelerated two-
641 dimensional vector and raster graphics developed under the auspices of the Khronos
642 Group \url{www.khronos.org}.''
643
644 Specifically, provides the same drawing functionality required by a high-performance SVG document viewer (SVG Tiny 1.2)
645 TODO: Look at that $\neq$ SVG 1.1
646
647 It is designed to be similar to OpenGL.
648
649 \subsubsection{Precision}
650 ``All floating-point values are specified in standard IEEE 754 format. However,
651 implementations may clamp extremely large or small values to a restricted
652 range, and internal processing may be performed with lesser precision. At least
653 16 bits of mantissa, 6 bits of exponent, and a sign bit must be present, allowing
654 values from $\pm 2^{-30}$ to $\pm2^{31}$ to be represented with a fractional precision of at least 1
655 in $2^{16}$.''
656
657 IEEE but with a non standard number of bits.
658
659 Presumably the decreased precision is for increased efficiency the standard states that example applications are for ebooks.
660
661
662 \section{Document Object Model --- pugixml 1.4 manual \cite{pugixmlDOM}}
663
664 Pugixml is a C++ library for parsing XML documents\cite{kapoulkine2014pugixml}. XML is based on the Document Object Model (DOM); this is explained pretty well by the pugixml manual.
665
666 The document is the root node of the tree. Each child node has a type. These may
667 \begin{itemize}
668         \item Have attributes
669         \item Have child nodes of their own
670         \item Contain data 
671 \end{itemize}
672
673 In the case of HTML/SVG an XML parser within the browser/viewer creates the DOM tree from the XML (plain text) and then interprets that tree to produce the objects that will be rendered.
674
675 Example of XML $\to$ DOM tree given at\cite{pugixmlDOM}.
676 Example of XML parsing using pugixml is in \shell{code/src/tests/xml.cpp}
677
678
679 \begin{figure}[H]
680         \centering
681 \begin{minted}{xml}
682 <?xml version="1.0"?>
683 <mesh name="mesh_root">
684     <!-- here is a mesh node -->
685     some text
686     <![CDATA[someothertext]]>
687     some more text
688     <node attr1="value1" attr2="value2" />
689     <node attr1="value2">
690         <innernode/>
691     </node>
692 </mesh>
693 <?include somedata?>
694 \end{minted}
695
696         \includegraphics[width=0.6\textwidth]{references/pugixmlDOM-dom_tree.png}
697         \caption{Tree representation of the above listing \cite{pugixmlDOM}}
698 \end{figure}
699
700 \section{An Algorithm For Shading of Regions on Vector Display Devices \cite{brassel1979analgorithm}}
701
702 All modern display devices are raster based and therefore this paper is mainly of historical interest. It provides some references for shading on a raster display.
703
704 The algorithm described will shade an arbitrary simply-connected polygon using one or two sets of parallel lines.
705
706 The ``traditional'' method is:
707 \begin{enumerate}
708         \item Start with a $N$ vertex polygon, rotate coords by the shading angle
709         \item Determine a bounding rectangle
710         \item For $M$ equally spaced parallel lines, compute the intersections with the boundaries of the polygon
711         \item Rotate coordinates back
712         \item Render the $M$ lines
713 \end{enumerate}
714
715 This is pretty much exactly how an artist would shade a pencil drawing. It is $O(M\times N)$.
716
717 The algorithm in this paper does:
718 \begin{enumerate}
719         \item Rotate polygon coords by shading angle
720         \item Subdivide the polygon into trapezoids (special case triangle)
721         \item Shade the trapezoids independently
722         \item Rotate it all back
723 \end{enumerate}
724 It is more complicated than it seems. The subdivision requires a sort to be performed on the vertices of the polygon based on their rotated $x$ and $y$ coordinates.
725
726 \section{An Algorithm For Filling Regions on Graphics Display Devices \cite{lane1983analgorithm}}
727
728 This gives an algorithm for for polygons (which may have ``holes'').
729 It requires the ability to ``subtract'' fill from a region; this is (as far as I can tell) difficult for vector graphics devices but simple on raster graphics devices, so the paper claims it is oriented to the raster graphics devices.
730
731 If the polygon is defined by $(x_i, y_i)$ then this algorithm iterates from $i = 2$ and alternates between filling and erasing the triangles $[(x_i, y_i), (x_{i+1}, y_{i+1}), (x_1, y_1)]$. It requires no sorting of the points.
732
733 The paper provides a proof that the algorithm is correct and is ``optimal in the number of pixel updates required for convex polygons''.
734 In the conclusion it is noted that trapezoids could be used from a fixed line and edge of the polygon, but this is not pixel optimal.
735
736 This paper doesn't have a very high citation count but it is cited by the NVIDIA article \cite{kilgard2012gpu}.
737 Apparently someone else adapted this algorithm for use with the stencil buffer.
738
739 \section{GPU-accelerated path rendering \cite{kilgard2012gpu, kilgard300programming}}
740
741 Vector graphics on the GPU; an NVIDIA extension. \cite{kilgard300programming} is the API.
742
743 Motivations:
744 \begin{itemize}
745         \item The focus has been on 3D acceleration in GPUs; most path rendering is done by the CPU.
746         \item Touch devices allow the screen to be transformed rapidly; CPU rastering of the path becomes inefficient
747         \begin{itemize}
748                 \item The source of the ugly pixelated effects on a smartphone when scaling?
749         \end{itemize}
750         \item Especially when combined with increased resolution of these devices
751         \item Standards such as HTML5, SVG, etc, expose path rendering
752         \item Javascript is getting fast enough that we can't blame it anymore (the path rendering is the bottleneck not the JS)
753         \item GPU is more power efficient than the CPU
754 \end{itemize}
755
756 Results show the extension is faster than almost every renderer it was compared with for almost every test image.
757
758 Comparisons to other attempts:
759 \begin{itemize}
760         \item Cairo and Glitz \cite{nilsson2004glitz} (abandoned)
761 \       \item Direct2D from Microsoft uses CPU to tesselate trapezoids and then renders these on the GPU
762         \item Skia in Android/Chrome uses CPU but now has Ganesh which is also hybrid CPU/GPU
763         \item Khronos Group created OpenVG\cite{rice2008openvg} with several companies creating hardware units to implement the standard. Performance is not as good as ``what we report''
764 \end{itemize}
765
766
767 \section{A Multiple Precision Binary Floating Point Library With Correct Rounding \cite{fousse2007mpfr}}
768
769 This is what is now the GNU MPFR C library; it has packages in debian wheezy.
770
771 The library was motivated by the lack of existing arbitrary precision libraries which conformed to IEEE rounding standards.
772 Examples include Mathematica, GNU MP (which this library is actually built upon), Maple (which is an exception but buggy).
773
774 TODO: Read up on IEEE rounding to better understand the first section
775
776 Data:
777 \begin{itemize}
778         \item $(s, m, e)$ where $e$ is signed
779         \item Precision $p$ is number of bits in $m$
780         \item $\frac{1}{2} \leq m < 1$
781         \item The leading bit of the mantissa is always $1$ but it is not implied
782         \item There are no denormalised numbers
783         \item Mantissa is stored as an array of ``limbs'' (unsigned integers) as in GMP
784 \end{itemize}
785
786 The paper includes performance comparisons with several other libraries, and a list of literature using the MPFR (the dates indicating that the library has been used reasonably widely before this paper was published).
787
788 \section{Lecture Notes on the Status of IEEE Standard 754 for Binary Floating-Point Arithmetic \cite{kahan1996ieee754}}
789
790 11 years after the IEEE 754 standard becomes official, Kahan discusses various misunderstood features of the standard and laments at the failure of compilers and microprocessors to conform to some of these.
791
792 I am not sure how relevant these complaints are today, but it makes for interesting reading as Kahan is clearly very passionate about the need to conform \emph{exactly} to IEEE 754.
793
794 Issues considered are: Rounding rules, Exception handling and NaNs (eg: The payload of NaNs is not used in any software Kahan is aware of), Bugs in compilers (mostly Fortran) where an expression contains floats of different precisions (the compiler may attempt to optimise an expression resulting in a failure to round a double to a single), Infinity (which is unsupported by many compilers though it is supported in hardware)...
795
796
797 An example is this Fortran compiler ``nasty bug'' where the compiler replaces $s$ with $x$ in line 4 and thus a rounding operation is lost.
798 \begin{minted}{Fortran}
799         real(8) :: x, y % double precision (or extended as real(12))
800         real(4) :: s, t % single precision
801         s = x % s should be rounded
802         t = (s - y) / (...) % Compiler incorrectly replaces s with x in this line
803 \end{minted}
804
805 \subsection{The Baleful Influence of Benchmarks \cite{kahan1996ieee754} pg 20}
806
807 This section discusses the tendency to rate hardware (or software) on their speed performance and neglect accuracy.
808
809 Is this complaint still relevant now when we consider the eagerness to perform calculations on the GPU?
810 ie: Doing the coordinate transforms on the GPU is faster, but less accurate (see our program).
811
812 Benchmarks need to be well designed when considering accuracy; how do we know an inaccurate computer hasn't gotten the right answer for a benchmark by accident?
813
814 A proposed benchmark for determining the worst case rounding error is given. This is based around computing the roots to a quadratic equation.
815 A quick scan of the source code for paranoia does not reveal such a test.
816
817 As we needed benchmarks for CPUs perhaps we need benchmarks for GPUs. The GPU Paranoia paper\cite{hillesland2004paranoia} is the only one I have found so far.
818
819 \section{Prof W. Kahan's Web Pages \cite{kahanweb}}
820
821 William Kahan, architect of the IEEE 754-1985 standard, creator of the program ``paranoia'', the ``Kahan Summation Algorithm'' and contributor to the revised standard. 
822
823 Kahan's web page has more examples of errors in floating point arithmetic (and places where things have not conformed to the IEEE 754 standard) than you can poke a stick at.
824
825 Wikipedia's description is pretty accurate: ``He is an outspoken advocate of better education of the general computing population about floating-point issues, and regularly denounces decisions in the design of computers and programming languages that may impair good floating-point computations.''
826
827 Kahan's articles are written with almost religious zeal but they are backed up by examples and results, a couple of which I have confirmed.\footnote{One that doesn't work is an example of wierd arithmetic in Excel 2000 when repeated in LibreOffice Calc 4.1.5.3} This is the unpublished work. I haven't read any of the published papers yet. 
828
829 The articles are filled sporadically with lamentation for the decline of experts in numerical analysis (and error) which is somewhat ironic; if there were no IEEE 754 standard meaning any man/woman and his/her dog could write floating point arithmetic and expect it to produce platform independent results\footnote{Even if, as Kahan's articles often point out, platforms aren't actually following IEEE 754} this decline would probably not have happened.
830
831 These examples would be of real value if the topic of the project were on accuracy of numerical operations. They also explain some of the more bizarre features of IEEE 754 (in a manner attacking those who dismiss these features as being too bizarre to care about of course).
832
833 It's somewhat surprising he hasn't written anything (that I could see from scanning the list) about the lack of IEEE in PDF/PostScript (until Adobe Reader 6) and further that the precision is only binary32.
834
835 I kind of feel really guilty saying this, but since our aim is to obtain arbitrary scaling, it will be inevitable that we break from the IEEE 754 standard. Or at least, I (Sam) will. Probably. Also there is no way I will have time to read and understand the thousands of pages that Kahan has written.
836
837 Therefore we might end up doing some things Kahan would not approve of.
838
839 Still this is a very valuable reference to go in the overview of floating point arithmetic section.
840
841 \chapter{General Notes}
842
843 \section{The DOM Model}
844
845 A document is modelled as a tree. The root of the tree is the document. This has nodes of varying types. Some nodes may have children, attributes, and data.
846
847 \section{Floating-Point Numbers\cite{HFP,goldberg1991whatevery,goldberg1992thedesign,priest1991algorithms}}
848
849 A set of FP numbers is characterised by:
850 \begin{enumerate}
851         \item Radix (base) $\beta \geq 2$
852         \item Precision %$p \req 2$ ``number of sig digits'' 
853         \item Two ``extremal`` exponents $e_min < 0 < e_max$ (generally, don't have to have the $0$ in there) 
854 \end{enumerate}
855
856 Numbers are represented by {\bf integers}: $(M, e)$ such that $x = M \times \beta^{e - p + 1}$
857
858 Require: $|M| \leq \beta^{p}-1$ and $e_min \leq e \leq e_max$.
859
860 Representations are not unique; set of equivelant representations is a cohort.
861
862 $\beta^{e-p+1}$ is the quantum, $e-p+1$ is the quantum exponent.
863
864 Alternate represetnation: $(s, m, e)$ such that $x = (-1)^s \times m \times \beta^{e}$
865 $m$ is the significand, mantissa, or fractional part. Depending on what you read.
866
867
868
869
870
871 \section{Rounding Errors}
872
873
874 They happen. There is ULP and I don't mean a political party.
875
876 TODO: Probably say something more insightful. Other than "here is a graph that shows errors and we blame rounding".
877
878 \subsection{Results of calculatepi}
879
880 We can calculate pi by numerically solving the integral:
881 \begin{align*}
882         \int_0^1 \left(\frac{4}{1+x^2}\right) dx &= \pi
883 \end{align*}
884
885 Results with Simpson Method:
886 \begin{figure}[H]
887         \centering
888         \includegraphics[width=0.8\textwidth]{figures/calculatepi.pdf}
889         \caption{Example of accumulated rounding errors in a numerical calculation}
890 \end{figure}
891
892 Tests with \verb/calculatepi/ show it's not quite as simple as just blindly replacing all your additions with Fast2Sum from Dekker\cite{dekker1971afloating}.
893 ie: The graph looks exactly the same for single precision. \verb/calculatepi/ obviously also has multiplication ops in it which I didn't change. Will look at after sleep maybe.
894
895
896 \pagebreak
897 \bibliographystyle{unsrt}
898 \bibliography{papers}
899
900 \end{document}
901

UCC git Repository :: git.ucc.asn.au