Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know if a code is executed using GPU or CPU?

Is there any simple way that I can know some codes are executed in GPU rather than CPU?

like image 368
Adam Lee Avatar asked Dec 01 '22 23:12

Adam Lee


1 Answers

I think you need to get your concept about the separation of work between CPU and GPU straight. If you code something and compile it with a regular compiler that's not targeted at GPU execution, the code will always execute of the CPU.

All calls to OpenGL or DirectX functions in your main program are executed on the CPU, there's no "magical" translation layer. However some those calls make the GPU do something, like drawing triangles.

CUDA and OpenCL are languages aimed at data parallel execution architectures. The GPU is such an architecture. But CUDA and OpenCL code require some host program, which in turn will be executed on the CPU. The very same goes for programmable shaders (HLSL, GLSL).

So: The host part of the program (setting up the work environment, issuing rendering calls or GPU execution) will run on CPU. The code running on GPU is compiled in a separate compilation unit (i.e. GLSL shader code uploaded to OpenGL, OpenCL/CUDA code compiled with a OpenCL/CUDA compiler).

like image 175
datenwolf Avatar answered Dec 11 '22 12:12

datenwolf