Halide 22.0.0 Halide compiler and libraries

Timer.h
Go to the documentation of this file.
1#ifndef HL_TIMER_H
2#define HL_TIMER_H
3
4#include <chrono>
5#include <set>
6#include <string>
7#include <vector>
8
9#include "ASLog.h"
10
11 namespace Halide {
12 namespace Internal {
13 namespace Autoscheduler {
14
15 using Clock = std::chrono::high_resolution_clock;
16
17 struct ScopedTimer {
18 std::chrono::time_point<Clock> start = Clock::now();
19 std::string msg;
20
21 explicit ScopedTimer(const std::string &msg)
22 : msg{msg} {
23 aslog(0) << "Start: " << msg << "\n";
24 }
25
26 ~ScopedTimer() {
27 auto duration = Clock::now() - start;
28 auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
29 aslog(0) << "Duration (ms): " << msg << " = " << ms << "\n";
30 }
31};
32
33 struct Timer {
34 std::chrono::time_point<Clock> start = Clock::now();
35
36 Timer() = default;
37
38 void restart() {
39 start = Clock::now();
40 }
41
42 std::chrono::duration<double> elapsed() const {
43 return Clock::now() - start;
44 }
45};
46
47} // namespace Autoscheduler
48} // namespace Internal
49} // namespace Halide
50
51#endif // HL_TIMER_H
ASLog.h
Halide::Internal::aslog
Definition: ASLog.h:16
Halide::Internal::Autoscheduler::Clock
std::chrono::high_resolution_clock Clock
Definition: Timer.h:15
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AbstractGenerator.h:19
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
Halide::Internal::Autoscheduler::ScopedTimer
Definition: Timer.h:17
Halide::Internal::Autoscheduler::ScopedTimer::ScopedTimer
ScopedTimer(const std::string &msg)
Definition: Timer.h:21
Halide::Internal::Autoscheduler::ScopedTimer::msg
std::string msg
Definition: Timer.h:19
Halide::Internal::Autoscheduler::ScopedTimer::start
std::chrono::time_point< Clock > start
Definition: Timer.h:18
Halide::Internal::Autoscheduler::ScopedTimer::~ScopedTimer
~ScopedTimer()
Definition: Timer.h:26
Halide::Internal::Autoscheduler::Timer
Definition: Timer.h:33
Halide::Internal::Autoscheduler::Timer::restart
void restart()
Definition: Timer.h:38
Halide::Internal::Autoscheduler::Timer::start
std::chrono::time_point< Clock > start
Definition: Timer.h:34
Halide::Internal::Autoscheduler::Timer::Timer
Timer()=default
Halide::Internal::Autoscheduler::Timer::elapsed
std::chrono::duration< double > elapsed() const
Definition: Timer.h:42