4

I have heard that GPU's are better at performing certain tasks than a CPU. My question is, how does a program tell a graphics card to process something instead of the CPU? Does the program talk to the GPU directly? Or does the CPU determine what to give the graphics card? It seems like the benefits of processing with a GPU would be negated somewhat if the CPU had to tell the GPU each instruction to process.

4
  • Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer. Also see How to Ask
    – gnat
    Commented Apr 14, 2015 at 19:59
  • 2
    Related: stackoverflow.com/questions/219928/intro-to-gpu-programming
    – Eric King
    Commented Apr 14, 2015 at 20:03
  • 1
    other related: stackoverflow.com/questions/6399676/… Commented Apr 14, 2015 at 20:16
  • Understanding the concept of coprocessors might be useful. A PC features many independent processors that can communicate over a data bus or as a special case over shared RAM. In a very low-level view, communicating with a graphics card is not fundamentally different from reading/writing from a hard drive or transmitting data over ethernet.
    – amon
    Commented Apr 14, 2015 at 20:32

1 Answer 1

7

My question is, how does a program tell a graphics card to process something instead of the CPU?

The short answer is that every graphics card must come with a driver implementing a standard graphics API such as OpenGL or DirectX, so that the code running on the CPU can call standard functions from that API. When writing your code, this is largely indistinguishable from coding against any other library.

However, a huge part of graphics programming involves passing special programs called "shaders" over to the graphics card, so they can be executed there. These are generally written in a different language specifically designed for shaders.

Does the program talk to the GPU directly? Or does the CPU determine what to give the graphics card?

"The program" is already running on the CPU (and any shaders it provided are running on the GPU) so I'm not sure what this is trying to ask.

It seems like the benefits of processing with a GPU would be negated somewhat if the CPU had to tell the GPU each instruction to process.

Indeed, this can happen. Moving data from the CPU to the GPU is a common bottleneck in graphically intensive programs. In fact, some features in more recent OpenGL versions are specifically designed to generate data on the GPU, so that you don't have to pass as much from the CPU.

Of course, whether the bottleneck is in the CPU, the GPU, or the communication between the two depends entirely on the individual program.

1
  • 1
    Both the current large GPU designers support the OpenCL language which gives you an API to use the gpu for other things eg. Bit Coin Hashing en.bitcoin.it/wiki/OpenCL_miner
    – Gilsham
    Commented Apr 14, 2015 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.