ReUseX  0.0.5
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
timer.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 Povl Filip Sonne-Frederiksen
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#pragma once
6#include "reusex/core/logging.hpp"
7#include "reusex/vision/tensor_rt/common/check.hpp"
8
10
12 public:
14 checkRuntime(cudaEventCreate(&begin_));
15 checkRuntime(cudaEventCreate(&end_));
16 }
17
18 virtual ~EventTimer() {
19 checkRuntime(cudaEventDestroy(begin_));
20 checkRuntime(cudaEventDestroy(end_));
21 }
22
23 void start(cudaStream_t stream = nullptr) {
24 stream_ = stream;
25 checkRuntime(cudaEventRecord(begin_, stream));
26 }
27
28 float stop(const char *prefix = "timer") {
29 float times = 0;
30 checkRuntime(cudaEventRecord(end_, stream_));
31 checkRuntime(cudaEventSynchronize(end_));
32 checkRuntime(cudaEventElapsedTime(&times, begin_, end_));
33 reusex::info("[⏰ {}] : {:.5f} ms", prefix, times);
34 return times;
35 }
36
37 private:
38 cudaStream_t stream_ = nullptr;
39 cudaEvent_t begin_ = nullptr, end_ = nullptr;
40};
41
42}; // namespace reusex::vision::tensor_rt::nv
#define checkRuntime(call)
Definition check.hpp:40
void start(cudaStream_t stream=nullptr)
Definition timer.hpp:23
float stop(const char *prefix="timer")
Definition timer.hpp:28
void info(fmt::format_string< Args... > format, Args &&...args)
Definition logging.hpp:86