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.