Problem description: Cuda is usually used for acceleration.ProgramTo compare the acceleration effect.
Solution:
1). GPU-side timing, that is, device-side timing.
2). CPU-side timing, that is, host-side timing.
Device timing has two different methods: calling the clock () function and using the Cuda API for event management.
Clock function timing:
1). A section to be measured in kernel functionsCodeRespectively, call the clock function once and record the result.
2) according to the two clock function return values, perform the difference calculation, and divide it by the GPU running frequency (SP frequency) to get the kernel execution time.
Generally, you only need to record the time required for executing each block, and finally obtain the start and end times of multiple blocks,
Then compare the start and end times, and select the minimum start time (the first block) and the maximum end time (the last block ),
The difference between the two time values can be obtained by dividing the GPU running frequency.
Cuda API event timing:
Use the event management API provided by Cuda to implement the timing function.
Host timing:
Use the functions provided in the library function for timing, such as gettimeofday (), clock ()...
Note:
1). The second and third timing methods are used in practice.
2) When testing on the CPU end, you must understand the asynchronous features of the Cuda API. When necessary, use the cudathreadsynchronize () function for synchronization.
3) when the Cuda Runtime API is used, the Cuda environment will be started when the first Runtime API function is called.
To avoid taking this part of time into account, it is best to perform a calculation that includes data input and output before the formal test starts,
In this way, the GPU enters the working state from the usual energy-saving mode, making the test results more reliable.
Original article: http://www.cnblogs.com/dwdxdy/archive/2012/06/04/2534065.html