Automatic commit of irc logs
[ipdf/documents.git] / FloatingPointCPUvsGPU.tex
1 \documentclass[9pt]{article}
2 \input{template}
3
4 \begin{document}
5 \title{Floating Point and CPU vs GPU Rendering}
6 \author{Sam Moore, David Gow}
7 \maketitle
8
9 \section*{Abstract}
10
11 We qualitatively illustrate differences between floating point operations on the x86-64 CPU and several GPUs by rendering filled ellipses.
12
13 \section{Introduction}
14
15 The IEEE Standard for Floating-Point Arithmetic \cite{ieee2008-754} has been widely adopted by hardware manufacturers of CPUs and programming language standards.
16
17 Although it is well known that the behaviour of GPU drivers is inconsistent, there is little formal academic research into the behaviour of floating point operations using such drivers. 
18
19 In 2004 Hillesland and Lastra adapted Kahan's well known program for testing floating point arithmetic on CPUs during the 1980s ``Paranoia'' for GPUs and found that many GPUs did not appear to be compliant with IEEE-754\cite{hillesland2004paranoia}.
20
21 Given the recent interest in use of the GPU for vector graphics\cite{kilgard2012gpu} the behaviour of GPUs when performing floating point operations is worthy of closer investigation.
22
23 Using a straight forward filled ellipse rendering algorithm implemented in C/C++ and GLSL we show inconsistent floating point behaviour when comparing the x86-64 CPU, an nVidia GPU\footnote{??? using the nVidia driver}, an intel GPU\footnote{??? using the intel driver} and an AMD/ATI GPU\footnote{Whistler LE (Radeon HD 6610M/7610M) using the fglrx driver}.
24
25 \section{Algorithm}
26
27 For each pixel position $(x,y)$ normalised relative to the bounding rectangle, if $x^2 + y^2 \leq 1$ then $(x,y)$ should be filled.
28
29 Although $x$ and $y$ may be treated as integers on the CPU, since the OpenGL API requires floating point vertex coordinates, our CPU implementation also normalises the coordinates relative to the bounding rectangle; this way we can compare the performance of floating point operations on the CPU and GPU(s).
30
31 \pagebreak
32 \subsection{GLSL Fragment Shader}
33 \begin{minted}{glsl}
34 #version 140
35 // Fragment shader (others omitted)
36
37 in vec2 objcoords; // Coordinates x, y, relative to bounding rectangle (from other shaders)
38 out vec4 output_colour;
39
40 uniform vec4 colour;
41
42 void main()
43 {
44         if ((objcoords.x)*(objcoords.x) + (objcoords.y)*(objcoords.y) > 1.0)
45         {
46                 discard;
47         }
48         output_colour = colour;
49 }
50 \end{minted}
51
52 \subsection{CPU Rendering Algorithm (simplified)}
53 \begin{minted}{c++}
54 // where bounds = {x,y,w,h} gives the bounding rectangle in integer pixel positions
55 // and centre = {x,y} is the centre of the circle
56 // and pixels[][] is the display buffer
57 for (int x = bounds.x; x < bounds.x+bounds.w; ++x)
58 {
59         for (int y = bounds.y; y < bounds.y+bounds.h; ++y)
60         {
61                 float dx = 2.0*(float)(x - centre.x)/(float)(bounds.w);
62                 float dy = 2.0*(float)(y - centre.y)/(float)(bounds.h);
63                 if (dx*dx + dy*dy <= 1.0)
64                 {
65                         pixels[x][y] = true;
66                 }
67         }
68 }
69 \end{minted}
70
71 Note: The \verb/pixels/ buffer is uploaded directly to the GPU after CPU rendering is completed.
72
73 \section{Results}
74
75 Figure \ref{comparison.pdf} shows the edge of a unit radius circle viewed under a magnification of approximately $5\times10^6$ as rendered using the CPU.
76
77
78
79 \section{Conclusion}
80
81 nVidia looks qualitatively similar to the CPU rendering. Frankly I was just happy fglrx didn't segfault. Wierd shit happens with intel. If anyone isn't obeying IEEE-754 here, it is probably intel.
82
83 \bibliographystyle{unsrt}
84 \bibliography{papers}
85
86 \pagebreak
87
88 \begin{figure}[H]
89 \centering
90 \includegraphics[width=0.8\textwidth]{figures/circles_gpu_vs_cpu/comparison.pdf}
91 \caption{The edges of a unit circle viewed through bounds (x,y,w,h) =  (0.0869386,0.634194,2.63295e-07,2.63295e-07)}\label{comparison.pdf}
92 \end{figure}
93
94
95
96
97
98 \end{document}

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