-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.h
53 lines (44 loc) · 1000 Bytes
/
timer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef GPU_TIMER_H__
#define GPU_TIMER_H__
#include <cuda_runtime.h>
struct GpuTimer
{
long long int start;
long long int stop;
double get_time()
{
struct timespec time;
clock_gettime(CLOCK_REALTIME, &time);
return (double)time.tv_sec + (double)time.tv_nsec * 1.0e-9 ;
}
__host__ GpuTimer()
{
start = 0;
stop = 0;
// cudaEventCreate(&start);
// cudaEventCreate(&stop);
}
__host__ ~GpuTimer()
{
// cudaEventDestroy(start);
// cudaEventDestroy(stop);
}
__device__ void Start()
{
// cudaEventRecord(start, 0);
start = clock64();
}
__device__ void Stop()
{
// cudaEventRecord(stop, 0);
stop = clock64();
}
__host__ long long int Elapsed()
{
long long int elapsed = stop - start;
//cudaEventSynchronize(stop);
//cudaEventElapsedTime(&elapsed, start, stop);
return elapsed;
}
};
#endif /* GPU_TIMER_H__ */