Halide 22.0.0 Halide compiler and libraries

Loading...
Searching...
No Matches
Statistics.h
Go to the documentation of this file.
1#ifndef STATISTICS_H
2#define STATISTICS_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 template<typename T>
18 struct ScopedStatistic {
19 const T &value;
20 std::string msg;
21
22 ScopedStatistic(const T &value, const std::string &msg)
23 : value{value},
24 msg{msg} {
25 }
26
27 ~ScopedStatistic() {
28 aslog(1) << msg << " = " << value << "\n";
29 }
30};
31
32 struct ScopedTimer {
33 std::chrono::time_point<Clock> start;
34 std::string msg;
35
36 explicit ScopedTimer(const std::string &msg)
37 : start{Clock::now()},
38 msg{msg} {
39 aslog(1) << "Start: " << msg << "\n";
40 }
41
42 ~ScopedTimer() {
43 auto duration = Clock::now() - start;
44 auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
45 aslog(1) << "Duration (ms): " << msg << " = " << ms << "\n";
46 }
47};
48
49 struct Timer {
50 std::chrono::time_point<Clock> start;
51
52 Timer()
53 : start{Clock::now()} {
54 }
55
56 void restart() {
57 start = Clock::now();
58 }
59
60 std::chrono::duration<double> elapsed() const {
61 return Clock::now() - start;
62 }
63};
64
65 struct Statistics {
66 int num_featurizations{0};
67 int num_states_added{0};
68 int num_block_memoization_hits{0};
69 int num_block_memoization_misses{0};
70 int num_memoized_featurizations{0};
71 int num_memoization_hits{0};
72 int num_memoization_misses{0};
73 int num_tilings_accepted{0};
74 int num_tilings_generated{0};
75 std::chrono::duration<double> generate_children_time{0};
76 std::chrono::duration<double> calculate_cost_time{0};
77 std::chrono::duration<double> enqueue_time{0};
78 std::chrono::duration<double> compute_in_tiles_time{0};
79 std::chrono::duration<double> filter_thread_tiles_time{0};
80 std::chrono::duration<double> filter_parallel_tiles_time{0};
81 std::chrono::duration<double> feature_write_time{0};
82 std::chrono::duration<double> featurization_time{0};
83 int num_schedules_enqueued{0};
84 std::chrono::duration<double> cost_model_evaluation_time{0};
85
86 double total_generate_children_time() const {
87 return std::chrono::duration_cast<std::chrono::milliseconds>(generate_children_time).count();
88 }
89
90 double total_compute_in_tiles_time() const {
91 return std::chrono::duration_cast<std::chrono::milliseconds>(compute_in_tiles_time).count();
92 }
93
94 double total_filter_thread_tiles_time() const {
95 return std::chrono::duration_cast<std::chrono::milliseconds>(filter_thread_tiles_time).count();
96 }
97
98 double total_filter_parallel_tiles_time() const {
99 return std::chrono::duration_cast<std::chrono::milliseconds>(filter_parallel_tiles_time).count();
100 }
101
102 double total_feature_write_time() const {
103 return std::chrono::duration_cast<std::chrono::milliseconds>(feature_write_time).count();
104 }
105
106 double total_calculate_cost_time() const {
107 return std::chrono::duration_cast<std::chrono::milliseconds>(calculate_cost_time).count();
108 }
109
110 double total_featurization_time() const {
111 return std::chrono::duration_cast<std::chrono::milliseconds>(featurization_time).count();
112 }
113
114 double average_featurization_time() const {
115 return total_featurization_time() / (double)num_featurizations;
116 }
117
118 double total_enqueue_time() const {
119 return std::chrono::duration_cast<std::chrono::milliseconds>(enqueue_time).count();
120 }
121
122 double total_cost_model_evaluation_time() const {
123 return std::chrono::duration_cast<std::chrono::milliseconds>(enqueue_time + cost_model_evaluation_time).count();
124 }
125
126 double average_cost_model_evaluation_time() const {
127 return total_cost_model_evaluation_time() / (double)num_schedules_enqueued;
128 }
129};
130
131} // namespace Autoscheduler
132} // namespace Internal
133} // namespace Halide
134
135#endif // STATISTICS_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::cast
Internal::ConstantInterval cast(Type t, const Internal::ConstantInterval &a)
Cast operators for ConstantIntervals.
Halide::Internal::Autoscheduler::ScopedStatistic
Definition Statistics.h:18
Halide::Internal::Autoscheduler::ScopedStatistic::~ScopedStatistic
~ScopedStatistic()
Definition Statistics.h:27
Halide::Internal::Autoscheduler::ScopedStatistic::msg
std::string msg
Definition Statistics.h:20
Halide::Internal::Autoscheduler::ScopedStatistic::ScopedStatistic
ScopedStatistic(const T &value, const std::string &msg)
Definition Statistics.h:22
Halide::Internal::Autoscheduler::ScopedStatistic::value
const T & value
Definition Statistics.h:19
Halide::Internal::Autoscheduler::ScopedTimer::ScopedTimer
ScopedTimer(const std::string &msg)
Definition Statistics.h:36
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 Statistics.h:42
Halide::Internal::Autoscheduler::Statistics
Definition Statistics.h:65
Halide::Internal::Autoscheduler::Statistics::average_cost_model_evaluation_time
double average_cost_model_evaluation_time() const
Definition Statistics.h:126
Halide::Internal::Autoscheduler::Statistics::cost_model_evaluation_time
std::chrono::duration< double > cost_model_evaluation_time
Definition Statistics.h:84
Halide::Internal::Autoscheduler::Statistics::num_block_memoization_hits
int num_block_memoization_hits
Definition Statistics.h:68
Halide::Internal::Autoscheduler::Statistics::num_states_added
int num_states_added
Definition Statistics.h:67
Halide::Internal::Autoscheduler::Statistics::enqueue_time
std::chrono::duration< double > enqueue_time
Definition Statistics.h:77
Halide::Internal::Autoscheduler::Statistics::num_tilings_generated
int num_tilings_generated
Definition Statistics.h:74
Halide::Internal::Autoscheduler::Statistics::compute_in_tiles_time
std::chrono::duration< double > compute_in_tiles_time
Definition Statistics.h:78
Halide::Internal::Autoscheduler::Statistics::total_filter_thread_tiles_time
double total_filter_thread_tiles_time() const
Definition Statistics.h:94
Halide::Internal::Autoscheduler::Statistics::num_memoized_featurizations
int num_memoized_featurizations
Definition Statistics.h:70
Halide::Internal::Autoscheduler::Statistics::filter_parallel_tiles_time
std::chrono::duration< double > filter_parallel_tiles_time
Definition Statistics.h:80
Halide::Internal::Autoscheduler::Statistics::total_calculate_cost_time
double total_calculate_cost_time() const
Definition Statistics.h:106
Halide::Internal::Autoscheduler::Statistics::total_generate_children_time
double total_generate_children_time() const
Definition Statistics.h:86
Halide::Internal::Autoscheduler::Statistics::average_featurization_time
double average_featurization_time() const
Definition Statistics.h:114
Halide::Internal::Autoscheduler::Statistics::total_enqueue_time
double total_enqueue_time() const
Definition Statistics.h:118
Halide::Internal::Autoscheduler::Statistics::generate_children_time
std::chrono::duration< double > generate_children_time
Definition Statistics.h:75
Halide::Internal::Autoscheduler::Statistics::num_block_memoization_misses
int num_block_memoization_misses
Definition Statistics.h:69
Halide::Internal::Autoscheduler::Statistics::calculate_cost_time
std::chrono::duration< double > calculate_cost_time
Definition Statistics.h:76
Halide::Internal::Autoscheduler::Statistics::num_memoization_misses
int num_memoization_misses
Definition Statistics.h:72
Halide::Internal::Autoscheduler::Statistics::num_memoization_hits
int num_memoization_hits
Definition Statistics.h:71
Halide::Internal::Autoscheduler::Statistics::total_compute_in_tiles_time
double total_compute_in_tiles_time() const
Definition Statistics.h:90
Halide::Internal::Autoscheduler::Statistics::filter_thread_tiles_time
std::chrono::duration< double > filter_thread_tiles_time
Definition Statistics.h:79
Halide::Internal::Autoscheduler::Statistics::num_tilings_accepted
int num_tilings_accepted
Definition Statistics.h:73
Halide::Internal::Autoscheduler::Statistics::total_cost_model_evaluation_time
double total_cost_model_evaluation_time() const
Definition Statistics.h:122
Halide::Internal::Autoscheduler::Statistics::num_featurizations
int num_featurizations
Definition Statistics.h:66
Halide::Internal::Autoscheduler::Statistics::featurization_time
std::chrono::duration< double > featurization_time
Definition Statistics.h:82
Halide::Internal::Autoscheduler::Statistics::total_featurization_time
double total_featurization_time() const
Definition Statistics.h:110
Halide::Internal::Autoscheduler::Statistics::total_filter_parallel_tiles_time
double total_filter_parallel_tiles_time() const
Definition Statistics.h:98
Halide::Internal::Autoscheduler::Statistics::num_schedules_enqueued
int num_schedules_enqueued
Definition Statistics.h:83
Halide::Internal::Autoscheduler::Statistics::feature_write_time
std::chrono::duration< double > feature_write_time
Definition Statistics.h:81
Halide::Internal::Autoscheduler::Statistics::total_feature_write_time
double total_feature_write_time() const
Definition Statistics.h:102
Halide::Internal::Autoscheduler::Timer::Timer
Timer()
Definition Statistics.h:52
Halide::Internal::Autoscheduler::Timer::restart
void restart()
Definition Statistics.h:56
Halide::Internal::Autoscheduler::Timer::start
std::chrono::time_point< Clock > start
Definition Timer.h:34
Halide::Internal::Autoscheduler::Timer::elapsed
std::chrono::duration< double > elapsed() const
Definition Statistics.h:60