What is the difference between CPU and GPU?

Started by
18 comments, last by Matt-D 11 years, 4 months ago

I think about it like this:

CPU does the math, GPU does the rendering.

Ta-Da smile.png (I'm not a smart programmer tongue.png ).

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).

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Advertisement

[quote name='superman3275' timestamp='1353733380' post='5003673']
I think about it like this:

CPU does the math, GPU does the rendering.

Ta-Da smile.png (I'm not a smart programmer tongue.png ).

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

C dominates the world of linear procedural computing, which won't advance. The future lies in MASSIVE parallelism.

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
If you want to learn how to write graphical programs for a GPU, you'll use HLSL (via Direct3D), GLSL (via OpenGL), or Cg (via either).
However, you don't write full programs in these languages -- you only write small functions (such as to colour in a pixel, or move a vertex) which are called by Direct3D or OpenGL, so you also have to learn how to write D3D/GL programs on the CPU as usual.

The small GPU programs/functions are called "shaders", and GLSL/HLSL are "shader languages".
Your GPU supports Direct3D 10.1 and OpenGL 3.3, which both in turn support fairly modern versions of the above shader languages.

If you want to learn how to use the GPU for non-graphical uses, then you're in the same boat, except the CPU-side APIs that you first need to learn are (one of) DirectCompute, OpenCL or CUDA.
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
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.
@ 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

[quote name='superman3275' timestamp='1353733380' post='5003673']
I think about it like this:

CPU does the math, GPU does the rendering.

Ta-Da smile.png (I'm not a smart programmer tongue.png ).

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.

... and a GPU is a processor designed to efficiently operate on graphical entities.


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)
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/

This topic is closed to new replies.

Advertisement