Ginkgo Generated from branch based on master. Ginkgo version 1.7.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
record.hpp
1/*******************************<GINKGO LICENSE>******************************
2Copyright (c) 2017-2023, the Ginkgo authors
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions
7are met:
8
91. Redistributions of source code must retain the above copyright
10notice, this list of conditions and the following disclaimer.
11
122. Redistributions in binary form must reproduce the above copyright
13notice, this list of conditions and the following disclaimer in the
14documentation and/or other materials provided with the distribution.
15
163. Neither the name of the copyright holder nor the names of its
17contributors may be used to endorse or promote products derived from
18this software without specific prior written permission.
19
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31******************************<GINKGO LICENSE>*******************************/
32
33#ifndef GKO_PUBLIC_CORE_LOG_RECORD_HPP_
34#define GKO_PUBLIC_CORE_LOG_RECORD_HPP_
35
36
37#include <deque>
38#include <memory>
39
40
41#include <ginkgo/core/log/logger.hpp>
42#include <ginkgo/core/matrix/dense.hpp>
43#include <ginkgo/core/stop/criterion.hpp>
44
45
46namespace gko {
47
53namespace log {
54
55
60 std::unique_ptr<const LinOp> solver;
61 std::unique_ptr<const LinOp> right_hand_side;
62 std::unique_ptr<const LinOp> solution;
63 const size_type num_iterations;
64 std::unique_ptr<const LinOp> residual;
65 std::unique_ptr<const LinOp> residual_norm;
66 std::unique_ptr<const LinOp> implicit_sq_residual_norm;
68 bool all_stopped;
69
70 iteration_complete_data(const LinOp* solver, const LinOp* right_hand_side,
71 const LinOp* solution,
72 const size_type num_iterations,
73 const LinOp* residual = nullptr,
74 const LinOp* residual_norm = nullptr,
75 const LinOp* implicit_sq_residual_norm = nullptr,
76 const gko::array<stopping_status>* status = nullptr,
77 bool all_stopped = false)
78 : num_iterations{num_iterations}, all_stopped(all_stopped)
79 {
80 this->solver = solver->clone();
81 this->solution = solution->clone();
82 if (right_hand_side != nullptr) {
83 this->right_hand_side = right_hand_side->clone();
84 }
85 if (residual != nullptr) {
86 this->residual = residual->clone();
87 }
88 if (residual_norm != nullptr) {
89 this->residual_norm = residual_norm->clone();
90 }
91 if (implicit_sq_residual_norm != nullptr) {
92 this->implicit_sq_residual_norm =
93 implicit_sq_residual_norm->clone();
94 }
95 if (status != nullptr) {
96 this->status = *status;
97 }
98 }
99};
100
101
106 const Executor* exec;
107 const size_type num_bytes;
108 const uintptr location;
109};
110
111
116 const Executor* exec;
117 const Operation* operation;
118};
119
120
125 const Executor* exec;
126 std::unique_ptr<const PolymorphicObject> input;
127 std::unique_ptr<const PolymorphicObject> output; // optional
128
130 const PolymorphicObject* input,
131 const PolymorphicObject* output = nullptr)
132 : exec{exec}
133 {
134 this->input = input->clone();
135 if (output != nullptr) {
136 this->output = output->clone();
137 }
138 }
139};
140
141
146 std::unique_ptr<const LinOp> A;
147 std::unique_ptr<const LinOp> alpha;
148 std::unique_ptr<const LinOp> b;
149 std::unique_ptr<const LinOp> beta;
150 std::unique_ptr<const LinOp> x;
151
152 linop_data(const LinOp* A, const LinOp* alpha, const LinOp* b,
153 const LinOp* beta, const LinOp* x)
154 {
155 this->A = A->clone();
156 if (alpha != nullptr) {
157 this->alpha = alpha->clone();
158 }
159 this->b = b->clone();
160 if (beta != nullptr) {
161 this->beta = beta->clone();
162 }
163 this->x = x->clone();
164 }
165};
166
167
172 const LinOpFactory* factory;
173 std::unique_ptr<const LinOp> input;
174 std::unique_ptr<const LinOp> output;
175
176 linop_factory_data(const LinOpFactory* factory, const LinOp* input,
177 const LinOp* output)
179 {
180 this->input = input->clone();
181 if (output != nullptr) {
182 this->output = output->clone();
183 }
184 }
185};
186
187
192 const stop::Criterion* criterion;
193 const size_type num_iterations;
194 std::unique_ptr<const LinOp> residual;
195 std::unique_ptr<const LinOp> residual_norm;
196 std::unique_ptr<const LinOp> solution;
197 const uint8 stopping_id;
198 const bool set_finalized;
199 const array<stopping_status>* status;
200 const bool oneChanged;
201 const bool converged;
202
204 const size_type& num_iterations, const LinOp* residual,
205 const LinOp* residual_norm, const LinOp* solution,
206 const uint8 stopping_id, const bool set_finalized,
207 const array<stopping_status>* status = nullptr,
208 const bool oneChanged = false, const bool converged = false)
210 num_iterations{num_iterations},
211 residual{nullptr},
212 residual_norm{nullptr},
213 solution{nullptr},
214 stopping_id{stopping_id},
215 set_finalized{set_finalized},
216 status{status},
217 oneChanged{oneChanged},
218 converged{converged}
219 {
220 if (residual != nullptr) {
221 this->residual = std::unique_ptr<const LinOp>(residual->clone());
222 }
223 if (residual_norm != nullptr) {
224 this->residual_norm =
225 std::unique_ptr<const LinOp>(residual_norm->clone());
226 }
227 if (solution != nullptr) {
228 this->solution = std::unique_ptr<const LinOp>(solution->clone());
229 }
230 }
231};
232
233
244class Record : public Logger {
245public:
249 struct logged_data {
250 std::deque<std::unique_ptr<executor_data>> allocation_started;
251 std::deque<std::unique_ptr<executor_data>> allocation_completed;
252 std::deque<std::unique_ptr<executor_data>> free_started;
253 std::deque<std::unique_ptr<executor_data>> free_completed;
254 std::deque<std::unique_ptr<std::tuple<executor_data, executor_data>>>
255 copy_started;
256 std::deque<std::unique_ptr<std::tuple<executor_data, executor_data>>>
257 copy_completed;
258
259 std::deque<std::unique_ptr<operation_data>> operation_launched;
260 std::deque<std::unique_ptr<operation_data>> operation_completed;
261
262 std::deque<std::unique_ptr<polymorphic_object_data>>
263 polymorphic_object_create_started;
264 std::deque<std::unique_ptr<polymorphic_object_data>>
265 polymorphic_object_create_completed;
266 std::deque<std::unique_ptr<polymorphic_object_data>>
267 polymorphic_object_copy_started;
268 std::deque<std::unique_ptr<polymorphic_object_data>>
269 polymorphic_object_copy_completed;
270 std::deque<std::unique_ptr<polymorphic_object_data>>
271 polymorphic_object_move_started;
272 std::deque<std::unique_ptr<polymorphic_object_data>>
273 polymorphic_object_move_completed;
274 std::deque<std::unique_ptr<polymorphic_object_data>>
275 polymorphic_object_deleted;
276
277 std::deque<std::unique_ptr<linop_data>> linop_apply_started;
278 std::deque<std::unique_ptr<linop_data>> linop_apply_completed;
279 std::deque<std::unique_ptr<linop_data>> linop_advanced_apply_started;
280 std::deque<std::unique_ptr<linop_data>> linop_advanced_apply_completed;
281 std::deque<std::unique_ptr<linop_factory_data>>
282 linop_factory_generate_started;
283 std::deque<std::unique_ptr<linop_factory_data>>
284 linop_factory_generate_completed;
285
286 std::deque<std::unique_ptr<criterion_data>> criterion_check_started;
287 std::deque<std::unique_ptr<criterion_data>> criterion_check_completed;
288
289 std::deque<std::unique_ptr<iteration_complete_data>>
290 iteration_completed;
291 };
292
293 /* Executor events */
295 const size_type& num_bytes) const override;
296
298 const size_type& num_bytes,
299 const uintptr& location) const override;
300
301 void on_free_started(const Executor* exec,
302 const uintptr& location) const override;
303
304 void on_free_completed(const Executor* exec,
305 const uintptr& location) const override;
306
308 const uintptr& location_from,
309 const uintptr& location_to,
310 const size_type& num_bytes) const override;
311
313 const uintptr& location_from,
314 const uintptr& location_to,
315 const size_type& num_bytes) const override;
316
317 /* Operation events */
319 const Operation* operation) const override;
320
322 const Operation* operation) const override;
323
324 /* PolymorphicObject events */
326 const Executor* exec, const PolymorphicObject* po) const override;
327
329 const Executor* exec, const PolymorphicObject* input,
330 const PolymorphicObject* output) const override;
331
333 const Executor* exec, const PolymorphicObject* from,
334 const PolymorphicObject* to) const override;
335
337 const Executor* exec, const PolymorphicObject* from,
338 const PolymorphicObject* to) const override;
339
341 const Executor* exec, const PolymorphicObject* from,
342 const PolymorphicObject* to) const override;
343
345 const Executor* exec, const PolymorphicObject* from,
346 const PolymorphicObject* to) const override;
347
349 const Executor* exec, const PolymorphicObject* po) const override;
350
351 /* LinOp events */
352 void on_linop_apply_started(const LinOp* A, const LinOp* b,
353 const LinOp* x) const override;
354
355 void on_linop_apply_completed(const LinOp* A, const LinOp* b,
356 const LinOp* x) const override;
357
358 void on_linop_advanced_apply_started(const LinOp* A, const LinOp* alpha,
359 const LinOp* b, const LinOp* beta,
360 const LinOp* x) const override;
361
362 void on_linop_advanced_apply_completed(const LinOp* A, const LinOp* alpha,
363 const LinOp* b, const LinOp* beta,
364 const LinOp* x) const override;
365
366 /* LinOpFactory events */
368 const LinOp* input) const override;
369
371 const LinOpFactory* factory, const LinOp* input,
372 const LinOp* output) const override;
373
374 /* Criterion events */
376 const size_type& num_iterations,
377 const LinOp* residual,
378 const LinOp* residual_norm,
379 const LinOp* solution,
380 const uint8& stopping_id,
381 const bool& set_finalized) const override;
382
384 const stop::Criterion* criterion, const size_type& num_iterations,
385 const LinOp* residual, const LinOp* residual_norm,
386 const LinOp* implicit_residual_norm_sq, const LinOp* solution,
387 const uint8& stopping_id, const bool& set_finalized,
388 const array<stopping_status>* status, const bool& one_changed,
389 const bool& all_converged) const override;
390
392 const stop::Criterion* criterion, const size_type& num_iterations,
393 const LinOp* residual, const LinOp* residual_norm,
394 const LinOp* solution, const uint8& stopping_id,
395 const bool& set_finalized, const array<stopping_status>* status,
396 const bool& one_changed, const bool& all_converged) const override;
397
398 /* Internal solver events */
400 const LinOp* solver, const LinOp* right_hand_side, const LinOp* x,
401 const size_type& num_iterations, const LinOp* residual,
402 const LinOp* residual_norm, const LinOp* implicit_resnorm_sq,
403 const array<stopping_status>* status, bool stopped) const override;
404
405 GKO_DEPRECATED(
406 "Please use the version with the additional stopping "
407 "information.")
409 const size_type& num_iterations,
410 const LinOp* residual, const LinOp* solution,
411 const LinOp* residual_norm) const override;
412
413 GKO_DEPRECATED(
415 "information.")
417 const LinOp* solver, const size_type& num_iterations,
418 const LinOp* residual, const LinOp* solution,
419 const LinOp* residual_norm,
420 const LinOp* implicit_sq_residual_norm) const override;
421
440 GKO_DEPRECATED("use two-parameter create")
441 static std::unique_ptr<Record> create(
442 std::shared_ptr<const Executor> exec,
445 {
446 return std::unique_ptr<Record>(new Record(enabled_events, max_storage));
447 }
448
467 static std::unique_ptr<Record> create(
468 const mask_type& enabled_events = Logger::all_events_mask,
470 {
471 return std::unique_ptr<Record>(new Record(enabled_events, max_storage));
472 }
473
479 const logged_data& get() const noexcept { return data_; }
480
484 logged_data& get() noexcept { return data_; }
485
486protected:
498 GKO_DEPRECATED("use two-parameter constructor")
499 explicit Record(std::shared_ptr<const gko::Executor> exec,
503 {}
504
515 explicit Record(const mask_type& enabled_events = Logger::all_events_mask,
517 : Logger(enabled_events), max_storage_{max_storage}
518 {}
519
528 template <typename deque_type>
529 void append_deque(std::deque<deque_type>& deque, deque_type object) const
530 {
531 if (this->max_storage_ && deque.size() == this->max_storage_) {
532 deque.pop_front();
533 }
534 deque.push_back(std::move(object));
535 }
536
537private:
538 mutable logged_data data_{};
539 size_type max_storage_{};
540};
541
542
543} // namespace log
544} // namespace gko
545
546
547#endif // GKO_PUBLIC_CORE_LOG_RECORD_HPP_
The first step in using the Ginkgo library consists of creating an executor.
Definition executor.hpp:644
A LinOpFactory represents a higher order mapping which transforms one linear operator into another.
Definition lin_op.hpp:414
Definition lin_op.hpp:146
Operations can be used to define functionalities whose implementations differ among devices.
Definition executor.hpp:287
A PolymorphicObject is the abstract base for all "heavy" objects in Ginkgo that behave polymorphicall...
Definition polymorphic_object.hpp:72
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition array.hpp:187
Definition logger.hpp:104
static constexpr mask_type all_events_mask
Bitset Mask which activates all events.
Definition logger.hpp:117
Record is a Logger which logs every event to an object.
Definition record.hpp:244
void on_polymorphic_object_deleted(const Executor *exec, const PolymorphicObject *po) const override
PolymorphicObject's deleted event.
void on_linop_advanced_apply_completed(const LinOp *A, const LinOp *alpha, const LinOp *b, const LinOp *beta, const LinOp *x) const override
LinOp's advanced apply completed event.
void on_allocation_completed(const Executor *exec, const size_type &num_bytes, const uintptr &location) const override
Executor's allocation completed event.
void on_polymorphic_object_move_started(const Executor *exec, const PolymorphicObject *from, const PolymorphicObject *to) const override
PolymorphicObject's move started event.
void on_copy_completed(const Executor *from, const Executor *to, const uintptr &location_from, const uintptr &location_to, const size_type &num_bytes) const override
Executor's copy completed event.
void on_linop_advanced_apply_started(const LinOp *A, const LinOp *alpha, const LinOp *b, const LinOp *beta, const LinOp *x) const override
LinOp's advanced apply started event.
void on_polymorphic_object_create_started(const Executor *exec, const PolymorphicObject *po) const override
PolymorphicObject's create started event.
void on_copy_started(const Executor *from, const Executor *to, const uintptr &location_from, const uintptr &location_to, const size_type &num_bytes) const override
Executor's copy started event.
void on_criterion_check_completed(const stop::Criterion *criterion, const size_type &num_iterations, const LinOp *residual, const LinOp *residual_norm, const LinOp *implicit_residual_norm_sq, const LinOp *solution, const uint8 &stopping_id, const bool &set_finalized, const array< stopping_status > *status, const bool &one_changed, const bool &all_converged) const override
stop::Criterion's check completed event.
void on_linop_apply_completed(const LinOp *A, const LinOp *b, const LinOp *x) const override
LinOp's apply completed event.
void on_polymorphic_object_copy_completed(const Executor *exec, const PolymorphicObject *from, const PolymorphicObject *to) const override
PolymorphicObject's copy completed event.
void on_linop_factory_generate_completed(const LinOpFactory *factory, const LinOp *input, const LinOp *output) const override
LinOp Factory's generate completed event.
static std::unique_ptr< Record > create(const mask_type &enabled_events=Logger::all_events_mask, size_type max_storage=1)
Creates a Record logger.
Definition record.hpp:467
void on_polymorphic_object_copy_started(const Executor *exec, const PolymorphicObject *from, const PolymorphicObject *to) const override
PolymorphicObject's copy started event.
void on_polymorphic_object_move_completed(const Executor *exec, const PolymorphicObject *from, const PolymorphicObject *to) const override
PolymorphicObject's move completed event.
void on_free_started(const Executor *exec, const uintptr &location) const override
Executor's free started event.
logged_data & get() noexcept
Definition record.hpp:484
void on_linop_apply_started(const LinOp *A, const LinOp *b, const LinOp *x) const override
LinOp's apply started event.
void on_criterion_check_started(const stop::Criterion *criterion, const size_type &num_iterations, const LinOp *residual, const LinOp *residual_norm, const LinOp *solution, const uint8 &stopping_id, const bool &set_finalized) const override
stop::Criterion's check started event.
const logged_data & get() const noexcept
Returns the logged data.
Definition record.hpp:479
static std::unique_ptr< Record > create(std::shared_ptr< const Executor > exec, const mask_type &enabled_events=Logger::all_events_mask, size_type max_storage=1)
Creates a Record logger.
Definition record.hpp:441
void on_polymorphic_object_create_completed(const Executor *exec, const PolymorphicObject *input, const PolymorphicObject *output) const override
PolymorphicObject's create completed event.
void on_criterion_check_completed(const stop::Criterion *criterion, const size_type &num_iterations, const LinOp *residual, const LinOp *residual_norm, const LinOp *solution, const uint8 &stopping_id, const bool &set_finalized, const array< stopping_status > *status, const bool &one_changed, const bool &all_converged) const override
stop::Criterion's check completed event.
void on_iteration_complete(const LinOp *solver, const LinOp *right_hand_side, const LinOp *x, const size_type &num_iterations, const LinOp *residual, const LinOp *residual_norm, const LinOp *implicit_resnorm_sq, const array< stopping_status > *status, bool stopped) const override
Register the iteration_complete event which logs every completed iterations.
void on_free_completed(const Executor *exec, const uintptr &location) const override
Executor's free completed event.
void on_operation_launched(const Executor *exec, const Operation *operation) const override
Executor's operation launched event (method run).
void on_linop_factory_generate_started(const LinOpFactory *factory, const LinOp *input) const override
LinOp Factory's generate started event.
void on_allocation_started(const Executor *exec, const size_type &num_bytes) const override
Executor's allocation started event.
void on_operation_completed(const Executor *exec, const Operation *operation) const override
Executor's operation completed event (method run).
The Criterion class is a base class for all stopping criteria.
Definition criterion.hpp:64
@ criterion
Stopping criterion events.
@ factory
LinOpFactory events.
@ operation
Kernel execution and data movement.
The Ginkgo namespace.
Definition abstract_factory.hpp:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803
std::uint8_t uint8
8-bit unsigned integral type.
Definition types.hpp:149
std::uintptr_t uintptr
Unsigned integer type capable of holding a pointer to void.
Definition types.hpp:172
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:120
Struct storing the actually logged data.
Definition record.hpp:249
Struct representing Criterion related data.
Definition record.hpp:191
Struct representing Executor related data.
Definition record.hpp:105
Struct representing iteration complete related data.
Definition record.hpp:59
Struct representing LinOp related data.
Definition record.hpp:145
Struct representing LinOp factory related data.
Definition record.hpp:171
Struct representing Operator related data.
Definition record.hpp:115
Struct representing PolymorphicObject related data.
Definition record.hpp:124
This structure is used to represent versions of various Ginkgo modules.
Definition version.hpp:54