What is the difference between a CPU and a GPU oriented code?

谁都会走 提交于 2019-12-23 22:10:03

问题


Let us suppose a game developer develops an application. So, while writing the application will the developer write some code segment which should goto CPU and some which should goto GPU or is decided by scheduler at run time?


回答1:


CPUs and GPUs are different, optimised to do different things. GPUs are less clever, but massively more parallel and carry out a huge amount of specialised processing, as opposed to the traditional CPUs more general processing.

GPUs have to be tasked by the CPU. No scheduler run time devisions are possible, because they are different, capable of different instructions.




回答2:


Since you have tagged C, let me tell you that any program you write in C and compile using GCC or any compiler is aimed for your CPU.

If you code something and compile it with a regular compiler, that's not targeted for GPU execution, the code will always execute at the CPU.

The calls made to your graphics library are "executed" by your CPU, however the graphics oriented calls (example, drawing something) are operated by your GPU.

Further, answering this depends on what language and programs you are executing. CUDA and OpenCL, or OpenGL compute shaders are executed at GPU.

So basically, all the program execution of your code, that is setting up the compiler environment for rendering calls in your code is done by CPU.




回答3:


CPU and GPU are very different and have different programming models and programming languages. You could use C on the CPU and OpenCL (or CUDA, if you restrict yourself to Nvidia products) on the GPU.

You generally won't be able to run an arbitrary C code on the GPU.

Coding for GPUs is painful, and you have to tune the code to the particular hardware.

See also tools like PIPS4u & OpenACC



来源:https://stackoverflow.com/questions/33192406/what-is-the-difference-between-a-cpu-and-a-gpu-oriented-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!