<blockquote>
  <p>is it important with modern GPU architectures to avoid floating point operations in favor of integer operations?</p>
</blockquote>

<p>Almost certainly not. CPUs have a long history where for many years they only handled integers natively and floating point operations were all done with slow math libraries. That changed about 20-25 years ago, but the thinking has remained entrenched for many years. (And certain applications like finance may require it for other reasons.)</p>

<p>Modern GPUs, though, have always been about doing lots of floating point calculations in parallel. If you think about how most 3D rasterizers (like OpenGL, Metal, DirectX, etc.) work, they take all the vertices, transform them into normalized device coordinates, and then interpolate between them to draw the actual geometry. While you certainly could do that all with fixed point math, it probably wouldn't gain you much. But you also aren't doing those calculations yourself, unless you've written your own rasterizer as a compute kernel.</p>

<p>Now depending on what type of work you're doing, the precision of the floating point operations may be reduced. In a language like glsl (in OpenGL ES, anyway) you can <a href="https://www.khronos.org/opengl/wiki/Type_Qualifier_(GLSL)#Precision_qualifiers" rel="nofollow noreferrer">specify the precision</a> of the uniforms. On mobile hardware, it might be worth doing the calculations as floating point, but with only 16 or 24 bits instead of 32 because it saves power,   for example. (And even some desktop GPUs have used lower-precision floating point in the past.) But the desktop hardware of today is optimized for doing floating point work.</p>

<p>In short, I don't see a compelling reason to stick to integer math when working on the GPU.</p>

CC BY-SA 4.0
2019-04-13T01:42:51.783Z
It should be noted that, on the hardware-side, the picture will look different. GPU cores are purpose-built for floating point because they are there to run shaders and float is what shaders do. In fact, it's only recently that we're seeing integer performance on-par with float. So when we're talking about software on the GPU, float is king. I'm not a hardware engineer, but based on all I know, the cost of floating point in terms of area and power is much, much higher. So when you're building a hardware rasterizer, you will want to stick with fixed-point (i.e. integer) arithmetic if you can…
Michael Kenzel
CC BY-SA 4.0
2019-04-12T04:14:37.567Z
2019-04-12T04:14:37.567Z
user1118321
<p>When it comes to line drawing, <a href="https://www.geeksforgeeks.org/dda-line-generation-algorithm-computer-graphics/" rel="nofollow noreferrer">DDA</a> is the simplest and most intuitive algorithm, the core idea being:</p>

<ul>
<li>compute the slope of the line</li>
<li>for every increment in x, increment y by the slope</li>
</ul>

<p>However, DDA is not favored due to its use of floating point operations. In fact, avoiding floating point operations is a common theme in graphics. I am wondering about the relative cost of floating point operations versus integer operations in modern GPU's</p>

<p>I could do some benchmarking but my CUDA is rusty. There is a <a href="https://stackoverflow.com/q/2550281/1382487" title="Floating point vs integer calculations on modern hardware">question on SO</a> and the common wisdom there seems to be, "it depends".</p>

<p>My question is specific to computer graphics and line drawing. If a more general answer can be given, that will also be appreciated.</p>

<p>To state my question specifically, is it important with modern GPU architectures to avoid floating point operations in favor of integer operations?</p>

CC BY-SA 4.0
2019-04-11T05:53:22.683Z
Hi and welcome. Slightly offtopic but still worth knowing. Line drawing algorithms may be intuitive. But they tend to lead people astray when you move up this way to try to implement antialiasing. For these kinds of reasons antialiasing is essentially broken in mostly all 2D vector rendering engines.
joojaa
CC BY-SA 4.0
2019-04-12T02:29:50.057Z
@joojaa That's really interesting. Do you have a link where I could read more about that?
user1118321
<gpu><line-drawing><efficiency><float>
Floating Point Operations in Line Drawing Algorithms
wsaleem
# Floating Point Operations in Line Drawing Algorithms

(Asked by: username_0 on 2019-04-11)

When it comes to line drawing, [DDA](https://www.geeksforgeeks.org/dda-line-generation-algorithm-computer-graphics/) is the simplest and most intuitive algorithm, the core idea being:

* compute the slope of the line
* for every increment in x, increment y by the slope

However, DDA is not favored due to its use of floating point operations. In fact, avoiding floating point operations is a common theme in graphics. I am wondering about the relative cost of floating point operations versus integer operations in modern GPU's

I could do some benchmarking but my CUDA is rusty. There is a [question on SO](https://stackoverflow.com/q/2550281/1382487 "Floating point vs integer calculations on modern hardware") and the common wisdom there seems to be, "it depends".

My question is specific to computer graphics and line drawing. If a more general answer can be given, that will also be appreciated.

To state my question specifically, is it important with modern GPU architectures to avoid floating point operations in favor of integer operations?

**Tags:** gpu, line-drawing, efficiency, float

> **Comments:**
> **username_1**: Hi and welcome. Slightly offtopic but still worth knowing. Line drawing algorithms may be intuitive. But they tend to lead people astray when you move up this way to try to implement antialiasing. For these kinds of reasons antialiasing is essentially broken in mostly all 2D vector rendering engines.  
> **username_2**: @username_1 That's really interesting. Do you have a link where I could read more about that?  

---

## 1 answers

### Answer by username_2 on 2019-04-12. Score: 4

> is it important with modern GPU architectures to avoid floating point operations in favor of integer operations?

Almost certainly not. CPUs have a long history where for many years they only handled integers natively and floating point operations were all done with slow math libraries. That changed about 20-25 years ago, but the thinking has remained entrenched for many years. (And certain applications like finance may require it for other reasons.)

Modern GPUs, though, have always been about doing lots of floating point calculations in parallel. If you think about how most 3D rasterizers (like OpenGL, Metal, DirectX, etc.) work, they take all the vertices, transform them into normalized device coordinates, and then interpolate between them to draw the actual geometry. While you certainly could do that all with fixed point math, it probably wouldn't gain you much. But you also aren't doing those calculations yourself, unless you've written your own rasterizer as a compute kernel.

Now depending on what type of work you're doing, the precision of the floating point operations may be reduced. In a language like glsl (in OpenGL ES, anyway) you can [specify the precision](https://www.khronos.org/opengl/wiki/Type_Qualifier_(GLSL)#Precision_qualifiers) of the uniforms. On mobile hardware, it might be worth doing the calculations as floating point, but with only 16 or 24 bits instead of 32 because it saves power, for example. (And even some desktop GPUs have used lower-precision floating point in the past.) But the desktop hardware of today is optimized for doing floating point work.

In short, I don't see a compelling reason to stick to integer math when working on the GPU.

> **Comments:**
> **username_3**: It should be noted that, on the hardware-side, the picture will look different. GPU cores are purpose-built for floating point because they are there to run shaders and float is what shaders do. In fact, it's only recently that we're seeing integer performance on-par with float. So when we're talking about software on the GPU, float is king. I'm not a hardware engineer, but based on all I know, the cost of floating point in terms of area and power is much, much higher. So when you're building a hardware rasterizer, you will want to stick with fixed-point (i.e. integer) arithmetic if you can…  

---

