Hey everyone,

I had a question in mind today and I thought I'd ask here. I have some basic knowledge in C++ and that's it. I am not a coder. (More into Power Engineering :D )

My question is why is it so hard to write code in parallel so that the power of GPU can be harnessed. (offloading tasks from the CPU)

I know that some software benefit from Nvidia's CUDA and ATI's STREAM, but the tasks have been limited to video/audio editing/converting.

Since games run on GPUs and they are easily written, why can't regular software code benefit from that?


I would really appreciate some enlightenment.

Thank you.
Slightly related to topic , I had a final yesterday in which i was asked to write pseudocode and draw a flow chart for a program . i couldn't do the program in anyway possible except parallel programing :P i created two independent processes running next to each other , i don't know if my answer was viable ? perhaps ill get a big fat zero .
Any parallel program can easily be converted into a serial program. Not all serial programs can be converted into parallel programs.
Take this: Hash an array of a thousand numbers using MD5. (easily convertible to parallel, GPU would gladly crunch it).
Hash a number a thousand times: There isn't any naive way to make use of multicore here. Each result is dependent on the one just before it. That's really the limitation of parallel programming: if your cores have to wait each other, they lose efficiency.
------------------
Still if you think about it, the universe is a huge parallel computing device, and parallel computing has a lot of potential looking into the limitations we have accelerating those CPUs now (mostly for economic reasons as well).

Diamond chips may soon rise us into the 80GHz CPU spectrum, that might be extremely interesting.
jadberro wroteSlightly related to topic , I had a final yesterday in which i was asked to write pseudocode and draw a flow chart for a program . i couldn't do the program in anyway possible except parallel programing :P i created two independent processes running next to each other , i don't know if my answer was viable ? perhaps ill get a big fat zero .
You're definitely getting impaled for that :)
@Xsever

games do NOT run on the GPU, the GPU is only used for rendering the frame buffer (converting the view of your scene from a 3D world to 2D) games run mostly on the CPU.
games are divided to multiple modules:
- you have the sound engine, which (usually) runs in a thread at a certain frequency so that the sound wouldn't be affected by your FPS
- there's the physics engine (if applicable) that handles collisions and physical reactions to outer events and that runs on the CPU with a higher frequency than the display (>200 iterations/second of course depending on the application)
- you have the animation engine, that's responsible for animating the characters
- there's the game logic which is the "game flow"
- and at last, comes the GPU to render the visual results of all the above modules to the screen.
there might be other modules, it all depends on the game.

what the GPU does best is floating point operations and in parallel. since rendering a single pixel to the screen is (usually) independent from rendering another pixel, the GPU can work on many pixels at the same time.
the GPU also has built in hardware chips designed for specific tasks, it is NOT a multi-purpose processor. video and image processing can benefit greatly from the GPU, but you lose precision each time u do an operation on 2 floats, that's why you can't use the GPU where u need exact precision, such in banking or accounting...

finally now to answer your question on why it is hard to write code in parallel...
it is not hard :) it all depends on the application and whether this application would benefit from parallel processing. if you want to write code that executes on the GPU there are few libraries that u can use but it is still low level coding that will make most vb.net "programmers" wet their beds at night (NO OFFENSE).

let me know if i missed anything or u need further clarifications
Hey,

The only algorithms that will benefit from a GP-GPU implementation is where the same sufficiently complex operations are done on a very large set of data.

GPUs are very specialized for batch processing:

- memory bandwidth is huge for sequential memory access (an order of magnitude faster than CPU memory), but very slow for random memory access : the memory controller is a "stupid" highly optimized piece of hardware.

- lot of computing operations can be done simultaneously (up to 128 in modern GPUs), but conditional branching have to give the same results on all "threads". If not, both branches are executed and one is discarded afterward. (pretty complex idea to understand, this is because GPUs only have 1 instruction scheduling units for many execution units).

Add this to the cost of transmitting datas from CPU to GPU and back from GPU to CPU, which makes that most of the time optimizing something on GPU can be slower.

More here http://gpgpu.org/ if you're interested in the subject.

- Jeko
Without the risk of negating most of what was said so far.

as of .NET 3.5 sp1, This is already being done in applications built using WPF as well as WPF based applications in Windows 7 and Visual Studio 2010.

You can refer to channel9 on MSDN for more information.
wikipedia wroteRouting the graphics through Direct3D allows Windows to offload some graphics tasks to the GPU found on the computer's graphics card. This can reduce the workload on the computer's CPU. Since GPUs are fast, parallel pixel processors this also tends to speed up screen refreshes.
http://en.wikipedia.org/wiki/Windows_Presentation_Foundation
@xterm: This is just the graphics using the pixel shaders found in the GPUs. It doesn't pertain a lot though to sequential algorithms and so on..
arithma wrote@xterm: This is just the graphics using the pixel shaders found in the GPUs. It doesn't pertain a lot though to sequential algorithms and so on..
I'm answering Xsever's question:
Xsever wroteSince games run on GPUs and they are easily written, why can't regular software code benefit from that?
Edit: I get what you mean arithma, but you *can* still pass tasks to the GPU.

http://brahma.ananthonline.net/
arithma wrote
jadberro wroteSlightly related to topic , I had a final yesterday in which i was asked to write pseudocode and draw a flow chart for a program . i couldn't do the program in anyway possible except parallel programing :P i created two independent processes running next to each other , i don't know if my answer was viable ? perhaps ill get a big fat zero .
You're definitely getting impaled for that :)
off goes about 8 marks :P , who cares Ive got plenty