Sign in to follow this  
ynm

What is the difference between CPU and GPU?

Recommended Posts

Hi everyone,

As I understand, CPU is central processing unit which I can program it to do some works, and GPU is something you can program it do do some works, in parallel but its function is limited, e.g it can add but can not multiply. But as all computer world is based on binary bits and logic functions AND, OR, NOT, so if one tries, he can program GPU to do whatever CPU can do, right? Or there are works that CPU can do but GPU can not do?

Regards

Share this post


Link to post
Share on other sites
Thanks,


Can GPU do branch commands like 'if'? And I heard that some kinds of the best ray tracing engine can only do with CPU, is this true and why don't they use GPU for the maths?

Can a computer run on GPU alone? If not then why?


Regards

PS: @Radikalizm, the example of add and multiply is just an example because I don't know how to say it clearly

Share this post


Link to post
Share on other sites
You don't write whole programs for GPU. What you do is that you have it run a small set of instructions (a kernel) in paralell many times over on a set of data.

For instance, you copy a buch of vertex data to the device memory, then ask the GPU to do math on the vertices. Then for each set of vertices you output a bunch of pixels which you also run a kernel on each pixel. These are called vertex and pixel shaders and are used to generate an image to be displayed on your monitor.

Recently, people started to use this pipeline for other purposes then generating an image. Namely number crunshing.

Share this post


Link to post
Share on other sites
Yes, modern GPUs are able to do branching, but I believe CPUs are generally more efficient at doing branches, or at least it used to be like that.

You have to keep in mind that a GPU is designed to do a large amount of similar jobs at once in parallel, that's why it's so efficient at doing heavy calculations. It'd be extremely hard or maybe even impossible to build an operating system kernel which could run on this kind of architecture. Working with memory would also be a major issue.

About ray tracers, there are a lot of ray tracing implementations which run on the GPU or which at least use the GPU to accelerate the process. The problem with CPU - GPU interop is that you'll encountering latency issues when uploading data to the GPU or when reading back data. It's only worth it to upload a job to the GPU if the speed improvement you'll get from it takes into account the memory latency from the data upload and potential readback as well.

Share this post


Link to post
Share on other sites
GPUs have been Turing complete for a while, so they can theoretically perform any calculation a CPU can perform.
In practice, the GPUs don't have any way to communicate with peripherals, just with the CPU, so that should make it obvious why one can't run a computer with a GPU alone.
It would also be extremely impractical to run some types of programs on a GPU - for example, a general purpose operating system - because the GPUs lack key features such as interrupts that are critical to implementing those programs in practice.

Share this post


Link to post
Share on other sites
[quote name='superman3275' timestamp='1353733380' post='5003673']
I think about it like this:

CPU does the math, GPU does the rendering.

Ta-Da [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] (I'm not a smart programmer [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img] ).
[/quote]
GPU does the math too. I would say it's more like, CPU does the logic that brings everything together, and GPU is the powerhouse that drives rendering, and possibly physics (and perhaps other stuff too).

Share this post


Link to post
Share on other sites
[quote name='Bacterius' timestamp='1353737350' post='5003684']
[quote name='superman3275' timestamp='1353733380' post='5003673']
I think about it like this:

CPU does the math, GPU does the rendering.

Ta-Da [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] (I'm not a smart programmer [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img] ).
[/quote]
GPU does the math too. I would say it's more like, CPU does the logic that brings everything together, and GPU is the powerhouse that drives rendering, and possibly physics (and perhaps other stuff too).
[/quote] Also audio processing can be done on the GPU

Share this post


Link to post
Share on other sites
Hi,

I want to write some simple programs like hello world for GPU, how can I do this? I have here an old ATI card 4330 on my laptop, can I write program using it?

Regards

Share this post


Link to post
Share on other sites
In addition to the libs mentioned by Hodgman, for GPGPU in C++ context you may also be interested in taking a look at the following:
- Thrust: http://thrust.github.com/
- C++ AMP: http://en.wikipedia.org/wiki/C%2B%2B_AMP http://www.gregcons.com/KateBlog/DidYouNoticeCAMPYouReallyNeedTo.aspx
// MS implementation (DX11-based) is Windows-only, but the specification is open and there's already an OpenCL-based PoC in the works: http://blogs.msdn.com/b/nativeconcurrency/archive/2012/11/16/introducing-shevlin-park-a-proof-of-concept-c-amp-implementation-on-opencl.aspx Edited by Matt-D

Share this post


Link to post
Share on other sites
May I ask why you wish to program onto the GPU directly? Chances are if you have an actual reason (and know this reason etc) then you already have knowledge of the GPU surpassing most of us here which (no offense intended here) it is obvious you do do not.


The actual lettering GPU stands for Graphics Processing Unit. This shows what its intended for pretty well.
Usually it has many many many cores (hundreds on several gaming cards, my own has over 300), these cores are capable of floating point maths natively (many CPU's are not and instead have additional circuitry for that). 1 processor core can only run a single task at a time, any code you ever write will also only ever use 1 core at a time (even GPU programming I believe) unless you specifically program it to make use of all the cores.
Something like a program that just takes 2 numbers, adds them together and spits the result back out will have no benefit to being parallelised. Something like graphics where you need to be doing a million things at once will see a huge benefit.
A single GPU core isn't actually very powerful with the exception of its floating point abilities, infact it wouldn't surprise me if the primary core of some of the higher end smart phones is more powerful (although I admit, I did not go online and check that). In theory as a GPU is what is referred to as turing complete it can do anything a CPU can, in practice a GPU has no way of interfacing with things like your keyboard etc, it can only spit out video data and only when its told to. In theory linux or something could be compiled to run on a GTX560, in practise though it would be running on just one of its several hundred cores with a ridiculous amount of limitations.

Some other tasks now done on the GPU are physics/biology/chemistry simulations and certain mathematical problems on large amounts of data although per core may be slower to do on the GPU than the CPU can of course be done on 100 or more pieces of data at once unlike your CPU where you can hope to do it on 4 at most maybe.


OpenCL can be hardware accelerated on both AMD and NVidia GPU's (aswell as some other more obsure hardware) or it can be run in pure CPU mode. NVidia have their CUDA library which works on NVidia GPU's and PPU's only (PPU's are rare and I don't think NVidia actually make them any more), for some things CUDA is faster, some OpenCL is faster, NVidia's PhysX physics library can use CUDA when present. The Bullet physics library can optionally use OpenCL or CUDA when possible too. OpenCV can use OpenCL aswell.

Generally any purpose you will need hardware acceleration from yourself will have a library available. GPU programming is a highly specialised field. For the majority of this post I am ignoring programmable shader pipelines because although they are still technically programming on a GPU it isn't what you appear to be after.

Share this post


Link to post
Share on other sites
@ all: many thanks,

I am learning about ray tracing because I love it, so I am trying to write on GPU (cast many rays at once) to test its limit. It is not my main job just hobby but I want to understand the concept. I am leaning to directcompute now but it seems tutorial on this field is very limited.

Regards

Share this post


Link to post
Share on other sites
[quote name='Bacterius' timestamp='1353737350' post='5003684']
[quote name='superman3275' timestamp='1353733380' post='5003673']
I think about it like this:

CPU does the math, GPU does the rendering.

Ta-Da [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] (I'm not a smart programmer [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img] ).
[/quote]
GPU does the math too. I would say it's more like, CPU does the logic that brings everything together, and GPU is the powerhouse that drives rendering, and possibly physics (and perhaps other stuff too).
[/quote]

Perhaps the best way to say it is that a CPU is a generalized processor, and a GPU is a processor designed to efficiently operate on graphical entities. It's more or less a very specialized CPU - what it is designed to do, it does much faster than a general CPU, and what it wasn't designed to do, it does much, much, much slower.

Share this post


Link to post
Share on other sites
[quote name='Cagnazzo' timestamp='1353821524' post='5003889']
... and a GPU is a processor designed to efficiently operate on graphical entities.
[/quote]

The rasterizer is pretty much the only thing that's really graphics-centered in GPUs anymore, they're good at all problems that can be solved in a massively parallel manner and with similar loop counts etc (little branching)

Share this post


Link to post
Share on other sites
This is a readable total-newbie-style overview: https://en.bitcoin.it/wiki/Why_a_GPU_mines_faster_than_a_CPU

BTW, there's a new class that launched in Coursera which deals with GPGPU:
https://class.coursera.org/hetero-2012-001/

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this