5 static int _Tnum_timers
;
6 static CUevent
*_Tstart_events
, *_Tstop_events
;
7 static CUstream _Tstream
;
10 init_timers (int ntimers
)
15 _Tnum_timers
= ntimers
;
17 _Tstart_events
= (CUevent
*) malloc (_Tnum_timers
* sizeof (CUevent
));
18 _Tstop_events
= (CUevent
*) malloc (_Tnum_timers
* sizeof (CUevent
));
20 r
= cuStreamCreate (&_Tstream
, CU_STREAM_DEFAULT
);
21 if (r
!= CUDA_SUCCESS
)
23 fprintf (stderr
, "cuStreamCreate failed: %d\n", r
);
27 for (i
= 0; i
< _Tnum_timers
; i
++)
29 r
= cuEventCreate (&_Tstart_events
[i
], CU_EVENT_DEFAULT
);
30 if (r
!= CUDA_SUCCESS
)
32 fprintf (stderr
, "cuEventCreate failed: %d\n", r
);
36 r
= cuEventCreate (&_Tstop_events
[i
], CU_EVENT_DEFAULT
);
37 if (r
!= CUDA_SUCCESS
)
39 fprintf (stderr
, "cuEventCreate failed: %d\n", r
);
50 for (i
= 0; i
< _Tnum_timers
; i
++)
52 cuEventDestroy (_Tstart_events
[i
]);
53 cuEventDestroy (_Tstop_events
[i
]);
56 cuStreamDestroy (_Tstream
);
58 free (_Tstart_events
);
63 start_timer (int timer
)
67 r
= cuEventRecord (_Tstart_events
[timer
], _Tstream
);
68 if (r
!= CUDA_SUCCESS
)
70 fprintf (stderr
, "cuEventRecord failed: %d\n", r
);
76 stop_timer (int timer
)
81 r
= cuEventRecord (_Tstop_events
[timer
], _Tstream
);
82 if (r
!= CUDA_SUCCESS
)
84 fprintf (stderr
, "cuEventRecord failed: %d\n", r
);
88 r
= cuEventSynchronize (_Tstop_events
[timer
]);
89 if (r
!= CUDA_SUCCESS
)
91 fprintf (stderr
, "cuEventSynchronize failed: %d\n", r
);
95 r
= cuEventElapsedTime (&etime
, _Tstart_events
[timer
], _Tstop_events
[timer
]);
96 if (r
!= CUDA_SUCCESS
)
98 fprintf (stderr
, "cuEventElapsedTime failed: %d\n", r
);