@@ -47,7 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47
47
#include " benchmark/utils/general.hpp"
48
48
49
49
50
- // A logger that accumulates the time of all operations
50
+ // A logger that accumulates the time and work estimates of all operations
51
51
struct OperationLogger : gko::log::Logger {
52
52
void on_allocation_started (const gko::Executor* exec,
53
53
const gko::size_type&) const override
@@ -84,10 +84,10 @@ struct OperationLogger : gko::log::Logger {
84
84
85
85
void on_copy_completed (const gko::Executor* from, const gko::Executor* to,
86
86
const gko::uintptr&, const gko::uintptr&,
87
- const gko::size_type&) const override
87
+ const gko::size_type& num_bytes ) const override
88
88
{
89
89
from->synchronize ();
90
- this ->end_operation (to, " copy" );
90
+ this ->end_operation (to, " copy" , { 0 , num_bytes} );
91
91
}
92
92
93
93
void on_operation_launched (const gko::Executor* exec,
@@ -99,7 +99,7 @@ struct OperationLogger : gko::log::Logger {
99
99
void on_operation_completed (const gko::Executor* exec,
100
100
const gko::Operation* op) const override
101
101
{
102
- this ->end_operation (exec, op->get_name ());
102
+ this ->end_operation (exec, op->get_name (), op-> get_work_estimate () );
103
103
}
104
104
105
105
void write_data (rapidjson::Value& object,
@@ -114,10 +114,29 @@ struct OperationLogger : gko::log::Logger {
114
114
repetitions,
115
115
alloc);
116
116
}
117
+ add_or_set_member (object, " work" ,
118
+ rapidjson::Value (rapidjson::kObjectType ), alloc);
119
+ auto & work_object = object[" work" ];
120
+ for (const auto & entry : work) {
121
+ add_or_set_member (work_object, entry.first .c_str (),
122
+ rapidjson::Value (rapidjson::kObjectType ), alloc);
123
+ add_or_set_member (work_object[entry.first .c_str ()], " flops" ,
124
+ entry.second .flops / repetitions, alloc);
125
+ add_or_set_member (work_object[entry.first .c_str ()], " memory" ,
126
+ entry.second .memory_volume / repetitions, alloc);
127
+ }
128
+ add_or_set_member (work_object, " total" ,
129
+ rapidjson::Value (rapidjson::kObjectType ), alloc);
130
+ add_or_set_member (work_object[" total" ], " flops" ,
131
+ total_work.flops / repetitions, alloc);
132
+ add_or_set_member (work_object[" total" ], " memory" ,
133
+ total_work.memory_volume / repetitions, alloc);
117
134
}
118
135
119
136
OperationLogger (bool nested_name) : use_nested_name{nested_name} {}
120
137
138
+ gko::work_estimate get_total_work () const { return total_work; }
139
+
121
140
private:
122
141
void start_operation (const gko::Executor* exec,
123
142
const std::string& name) const
@@ -131,7 +150,8 @@ struct OperationLogger : gko::log::Logger {
131
150
start[nested_name] = std::chrono::steady_clock::now ();
132
151
}
133
152
134
- void end_operation (const gko::Executor* exec, const std::string& name) const
153
+ void end_operation (const gko::Executor* exec, const std::string& name,
154
+ gko::work_estimate operation_work = {}) const
135
155
{
136
156
exec->synchronize ();
137
157
const std::lock_guard<std::mutex> lock (mutex);
@@ -141,6 +161,12 @@ struct OperationLogger : gko::log::Logger {
141
161
const auto diff = end - start[nested_name];
142
162
// make sure timings for nested operations are not counted twice
143
163
total[nested_name] += diff - nested.back ().second ;
164
+ auto & operation_sum = work[nested_name];
165
+ GKO_ASSERT (operation_sum.available == operation_work.available );
166
+ operation_sum.flops += operation_work.flops ;
167
+ operation_sum.memory_volume += operation_work.memory_volume ;
168
+ total_work.flops += operation_work.flops ;
169
+ total_work.memory_volume += operation_work.memory_volume ;
144
170
nested.pop_back ();
145
171
if (!nested.empty ()) {
146
172
nested.back ().second += diff;
@@ -151,6 +177,8 @@ struct OperationLogger : gko::log::Logger {
151
177
mutable std::mutex mutex;
152
178
mutable std::map<std::string, std::chrono::steady_clock::time_point> start;
153
179
mutable std::map<std::string, std::chrono::steady_clock::duration> total;
180
+ mutable std::map<std::string, gko::work_estimate> work;
181
+ mutable gko::work_estimate total_work;
154
182
// the position i of this vector holds the total time spend on child
155
183
// operations on nesting level i
156
184
mutable std::vector<
0 commit comments