ReUseX  0.0.1
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
timer.hpp
Go to the documentation of this file.
1#pragma once
3#include <spdlog/spdlog.h>
4
6
7class EventTimer {
8 public:
10 checkRuntime(cudaEventCreate(&begin_));
11 checkRuntime(cudaEventCreate(&end_));
12 }
13
14 virtual ~EventTimer() {
15 checkRuntime(cudaEventDestroy(begin_));
16 checkRuntime(cudaEventDestroy(end_));
17 }
18
19 void start(cudaStream_t stream = nullptr) {
20 stream_ = stream;
21 checkRuntime(cudaEventRecord(begin_, stream));
22 }
23
24 float stop(const char *prefix = "timer") {
25 float times = 0;
26 checkRuntime(cudaEventRecord(end_, stream_));
27 checkRuntime(cudaEventSynchronize(end_));
28 checkRuntime(cudaEventElapsedTime(&times, begin_, end_));
29 spdlog::info("[⏰ {}] : {:.5f} ms", prefix, times);
30 return times;
31 }
32
33 private:
34 cudaStream_t stream_ = nullptr;
35 cudaEvent_t begin_ = nullptr, end_ = nullptr;
36};
37
38}; // namespace ReUseX::vision::tensor_rt::nv
#define checkRuntime(call)
Definition check.hpp:34
void start(cudaStream_t stream=nullptr)
Definition timer.hpp:19
float stop(const char *prefix="timer")
Definition timer.hpp:24