Time usage in Cuda

Source: Internet
Author: User

Reprinted: http://blog.csdn.net/jdhanhua/article/details/4843653

An unknown error is reported when time_t and a series of functions are used for compiling the. Cu file with nvcc.

There are three methods to calculate the computing time in Cuda:

 

<1> use the functions in cutil. h
Unsigned int timer = 0;
// Create a timer
Cutcreatetimer (& timer );
// Start timing
Cutstarttimer (timer );
{
// Code segment for Statistics
............
}
// Stop timing
Cutstoptimer (timer );
// Obtain the time from start time to stop
Cutgettimervalue (timer );
// Delete the timer Value
Cutdeletetimer (timer );
 

I do not know the statistical accuracy in this case.

 

<2> clock function in time. h
Clock_t start, finish;
Float costtime;
Start = clock ();
{
// Code segment for Statistics
............
}
Finish = clock ();
// Obtain the time difference between the two records
Costtime = (float) (finish-Start)/clocks_per_sec;
The length of the timer unit is 1 millisecond.Precision is also 1 ms.

 

<3> event
Cudaevent_t start, stop;
Cudaeventcreate (& START );
Cudaeventcreate (& stop );
Cudaeventrecend (START, 0 );
{
// Code segment for Statistics
............
}
Cudaeventrecord (STOP, 0 );
Float costtime;
Cudaeventelapsedtime (& costtime, start, stop );
 
Cudaerror_t cudaeventcreate (cudaevent_t * event) --- create an event object;
Cudaerror_t cudaeventrecord (cudaevent_t event, custream stream) --- records events;
Cudaerror_t cudaeventelapsedtime (float * time, cudaevent_t start, cudaevent_t end) --- calculate the time difference between two events;
Cudaerror_t cudaeventdestroy (cudaevent_t event) --- destroys the event object.
Calculate the time difference between two events (In milliseconds, the precision is0.5Microseconds). If no event is recorded, this function returns cudaerrorinvalidvalue. If any event in the record uses a non-zero stream, the result is uncertain.

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.