-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCudaEventTimer.cpp
More file actions
41 lines (34 loc) · 947 Bytes
/
Copy pathCudaEventTimer.cpp
File metadata and controls
41 lines (34 loc) · 947 Bytes
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
#include "CudaEventTimer.hpp"
#include "checkCudaCall.hpp"
#define startevent (static_cast<cudaEvent_t*>(m_events)[0])
#define stopevent (static_cast<cudaEvent_t*>(m_events)[1])
CudaEventTimer::CudaEventTimer()
{
m_events = std::malloc(sizeof(cudaEvent_t) * 2);
checkCudaCall(cudaEventCreate(&startevent));
checkCudaCall(cudaEventCreate(&stopevent));
}
CudaEventTimer::~CudaEventTimer()
{
checkCudaCall(cudaEventDestroy(startevent));
checkCudaCall(cudaEventDestroy(stopevent));
std::free(m_events);
}
void CudaEventTimer::start()
{
checkCudaCall(cudaEventRecord(startevent));
}
void CudaEventTimer::stop()
{
checkCudaCall(cudaEventRecord(stopevent));
m_doneonce = true;
}
float CudaEventTimer::sync()
{
if(!m_doneonce)
return 0.f;
float ret = 0.f;
checkCudaCall(cudaEventSynchronize(stopevent));
checkCudaCall(cudaEventElapsedTime(&ret, startevent, stopevent));
return ret;
}