Is there any simple way that I can know some codes are executed in GPU rather than CPU?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With