Switch: Cuda timing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.