13 #include <mach/clock.h> 14 #include <mach/mach.h> 17 #include "util/cuda_util.hpp" 39 struct timespec tsstop;
44 #if defined(__NVCC__) && !defined(CUDA_ON_CPU) 46 hipEvent_t start_g, stop_g;
48 cudaEvent_t start_g, stop_g;
55 #if defined(SYNC_BEFORE_TAKE_TIME) && defined(__NVCC__) 57 hipDeviceSynchronize();
59 cudaDeviceSynchronize();
63 #ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time 66 host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
67 clock_get_time(cclock, &mts);
68 mach_port_deallocate(mach_task_self(), cclock);
69 tsstop.tv_sec = mts.tv_sec;
70 tsstop.tv_nsec = mts.tv_nsec;
72 clock_gettime(CLOCK_REALTIME, &tsstop);
95 #if defined(SYNC_BEFORE_TAKE_TIME) && defined(__NVCC__) 96 cudaDeviceSynchronize();
99 #ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time 102 host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
103 clock_get_time(cclock, &mts);
104 mach_port_deallocate(mach_task_self(), cclock);
108 clock_gettime(CLOCK_REALTIME, &
tsstart);
135 return ((
double)(tsstop.tv_sec -
tsstart.tv_sec)) + ((1e-9) * ((
double)(tsstop.tv_nsec -
tsstart.tv_nsec)));
147 return (((
double)(
cstop -
cstart)) / CLOCKS_PER_SEC);
160 #if defined(__NVCC__) && !defined(CUDA_ON_CPU) 165 hipEventCreate(&start_g);
166 hipEventRecord(start_g,0);
168 cudaEventCreate(&start_g);
169 cudaEventRecord(start_g,0);
176 hipEventCreate(&stop_g);
177 hipEventRecord(stop_g,0);
178 hipEventSynchronize(stop_g);
180 cudaEventCreate(&stop_g);
181 cudaEventRecord(stop_g,0);
182 cudaEventSynchronize(stop_g);
191 hipEventElapsedTime(&elapsedTime, start_g,stop_g);
193 cudaEventElapsedTime(&elapsedTime, start_g,stop_g);
struct timespec tsstart
starting time
timer()
Default constructor.
double getwct()
Return the elapsed real time.
double getcputime()
Return the cpu time.
bool running
Flag that indicate if the timer is running or not.
clock_t cstart
start time from epoch
clock_t cstop
stop time from epoch
void start()
Start the timer.
void reset()
Reset the timer.
Class for cpu time benchmarking.
void stop()
Stop the timer.