How Graphics Processing Unit (GPU) Can Be Used to Speed Up Computing

in #science9 years ago (edited)


491602_8911_3.jpgsource



Most time in computing, what we're trying to achieve is to be able to do more things or do things faster and of course we're trying to find all sorts of different ways for us to achieve that. One method that has been in use and has been getting more and more popular these days is to actually accelerate doing tasks using the GPU of a computer.

We often hear many interesting things about using a GPU to do some form of processing, the questions are:

Why and how is it that a GPU can do things faster? Why is it that we don't use it all the time for general-purpose computation and how is it done?

We’ll find out all of these in this article today.

In order to understand how we can actually use a GPU that is the graphics processing unit of your computer to speed up general-purpose computation, we first need to understand how it does its actual job and that is to actually render graphics.

header_productshot1.pngsource

What is the purpose of a GPU?

When it comes to rendering 3D graphics, there is actually quite a lot of work to do. It's not particularly hard work but there is a lot to it, for instance when you want to draw a 3D object on screen, what you pass to your computer are actually a bunch of vertices.

These vertices basically come together to form a mesh and this mesh is a representation of your 3D object. The positions of all the vertices are given in what is known as the world space, there is some origin somewhere and all the vertices will have an XY and Z coordinate relative to that origin.

cube-mesh-1.pngsource

The task of your computer when it comes to rendering out the 3D object is to convert all those coordinates to the coordinates that will actually appear on your screen, then it needs to fill in all the pixels that exist between those maps vertices.

One of the things that really shells a 3D effect is lighting and shading, this is called lighting computation and is something that needs to be done to create your final 3D rendered image.

coarse_model.jpgsource

The trivial way to achieve this effect is to simply loop through all the pixels and manually perform all the computation you need to perform, that of course takes a long time because there are many pixels especially on today's high-resolution screens. Instead, a better solution needs to be found and that exists in our graphics cards of today.

The reason why a GPU is often used in real time graphics rendering is because it's able to do a lot at once in parallel. That's basically how graphics works on a GPU and why a GPU can actually render your graphics very quickly.

One of the recent developments in graphics cards terms is the ability for you to program certain stages of computation that's actually performed on your graphics card. I’d say it's recent but it's not that recent, but at any rate you are able to change how your graphic card performs certain actions which I mentioned earlier and in doing so, we can make it draw nicer images or we can use it for a completely different purpose and that is general-purpose computation.

These programmable stages on your graphics card are known as Shaders. Graphics packages like OpenGL actually provide quite a few different types of Shaders, I’ll focus on two of them.

(Vertex Shader and Fragment Shader).

VERTEX SHADER

This is what converts coordinates from world space to screen space and is invoked once per Vertex. Once we know where every Vertex lies on screen, we know the areas they fill as well.

shader_detail.gifsource

FRAGMENT SHADER

A fragment is the same thing as a pixel, but with extra information such as depth.

Fragment Shaders are invoked to fill up these areas, one invocation per pixel.

This is where things get interesting because since there are many pixels on screen, and that means there are many parallel Fragment Shader invocations. That is precisely what makes graphics rendering very fast and that is precisely what we're going to take advantage of if we want to do general-purpose computation.

How do we actually use our GPU for general-purpose computation?

Well as it turns out, it's not too difficult of an idea, all we have to do is to take our input data- that is the data we want to process and somehow turn it into an image. Then we push this image to the rendering pipeline. Instead of allowing it to be rendered normally like an image, we use some specialized Shader to process that image.

At the end of the day, the results we get from the render pass is another image which we can then read-off back into the format we want, numerical data for instance and that's how we've just tricked our GPU into doing general-purpose computation.



References for further reading: Ref1, Ref2, Ref3



Thanks.png



Thanks to @camzy & @samstickkz for the amazing toon.

index.jpg

upvotefollowresteem.gif

Coin Marketplace

STEEM 0.04
TRX 0.32
JST 0.081
BTC 61667.55
ETH 1637.39
USDT 1.00
SBD 0.41