-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.h
More file actions
40 lines (35 loc) · 1.01 KB
/
Copy pathtimer.h
File metadata and controls
40 lines (35 loc) · 1.01 KB
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
#pragma once
#include <chrono>
#include <cuda_runtime.h>
#include "cuda_check.h"
namespace sbfft {
struct CpuTimer {
std::chrono::steady_clock::time_point t0;
void tic() { t0 = std::chrono::steady_clock::now(); }
double toc_ms() const {
return std::chrono::duration<double, std::milli>(
std::chrono::steady_clock::now() - t0).count();
}
};
struct GpuTimer {
cudaEvent_t a, b;
GpuTimer() {
CUDA_CHECK(cudaEventCreate(&a));
CUDA_CHECK(cudaEventCreate(&b));
}
~GpuTimer() {
cudaEventDestroy(a);
cudaEventDestroy(b);
}
GpuTimer(const GpuTimer&) = delete;
GpuTimer& operator=(const GpuTimer&) = delete;
void tic(cudaStream_t s = 0) { CUDA_CHECK(cudaEventRecord(a, s)); }
float toc_ms(cudaStream_t s = 0) {
CUDA_CHECK(cudaEventRecord(b, s));
CUDA_CHECK(cudaEventSynchronize(b));
float ms = 0.f;
CUDA_CHECK(cudaEventElapsedTime(&ms, a, b));
return ms;
}
};
} // namespace sbfft