Ginkgo Generated from branch based on master. Ginkgo version 1.8.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
stream.hpp
1// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_LOG_STREAM_HPP_
6#define GKO_PUBLIC_CORE_LOG_STREAM_HPP_
7
8
9#include <fstream>
10#include <iostream>
11
12
13#include <ginkgo/core/log/logger.hpp>
14
15
16namespace gko {
17namespace log {
18
19
30template <typename ValueType = default_precision>
31class Stream : public Logger {
32public:
33 /* Executor events */
35 const size_type& num_bytes) const override;
36
38 const size_type& num_bytes,
39 const uintptr& location) const override;
40
41 void on_free_started(const Executor* exec,
42 const uintptr& location) const override;
43
44 void on_free_completed(const Executor* exec,
45 const uintptr& location) const override;
46
47 void on_copy_started(const Executor* from, const Executor* to,
48 const uintptr& location_from,
49 const uintptr& location_to,
50 const size_type& num_bytes) const override;
51
52 void on_copy_completed(const Executor* from, const Executor* to,
53 const uintptr& location_from,
54 const uintptr& location_to,
55 const size_type& num_bytes) const override;
56
57 /* Operation events */
59 const Operation* operation) const override;
60
62 const Operation* operation) const override;
63
64 /* PolymorphicObject events */
66 const Executor*, const PolymorphicObject* po) const override;
67
69 const Executor* exec, const PolymorphicObject* input,
70 const PolymorphicObject* output) const override;
71
73 const Executor* exec, const PolymorphicObject* from,
74 const PolymorphicObject* to) const override;
75
77 const Executor* exec, const PolymorphicObject* from,
78 const PolymorphicObject* to) const override;
79
81 const Executor* exec, const PolymorphicObject* from,
82 const PolymorphicObject* to) const override;
83
85 const Executor* exec, const PolymorphicObject* from,
86 const PolymorphicObject* to) const override;
87
89 const Executor* exec, const PolymorphicObject* po) const override;
90
91 /* LinOp events */
92 void on_linop_apply_started(const LinOp* A, const LinOp* b,
93 const LinOp* x) const override;
94
95 void on_linop_apply_completed(const LinOp* A, const LinOp* b,
96 const LinOp* x) const override;
97
98 void on_linop_advanced_apply_started(const LinOp* A, const LinOp* alpha,
99 const LinOp* b, const LinOp* beta,
100 const LinOp* x) const override;
101
102 void on_linop_advanced_apply_completed(const LinOp* A, const LinOp* alpha,
103 const LinOp* b, const LinOp* beta,
104 const LinOp* x) const override;
105
106 /* LinOpFactory events */
108 const LinOp* input) const override;
109
111 const LinOpFactory* factory, const LinOp* input,
112 const LinOp* output) const override;
113
114 /* Criterion events */
116 const size_type& num_iterations,
117 const LinOp* residual,
118 const LinOp* residual_norm,
119 const LinOp* solution,
120 const uint8& stopping_id,
121 const bool& set_finalized) const override;
122
124 const stop::Criterion* criterion, const size_type& num_iterations,
125 const LinOp* residual, const LinOp* residual_norm,
126 const LinOp* solution, const uint8& stopping_id,
127 const bool& set_finalized, const array<stopping_status>* status,
128 const bool& one_changed, const bool& all_converged) const override;
129
130 /* Internal solver events */
132 const LinOp* x, const size_type& num_iterations,
133 const LinOp* residual,
134 const LinOp* residual_norm,
135 const LinOp* implicit_resnorm_sq,
136 const array<stopping_status>* status,
137 bool stopped) const override;
138
139 GKO_DEPRECATED(
140 "Please use the version with the additional stopping "
141 "information.")
143 const size_type& num_iterations,
144 const LinOp* residual, const LinOp* solution,
145 const LinOp* residual_norm) const override;
146
147 GKO_DEPRECATED(
148 "Please use the version with the additional stopping "
149 "information.")
151 const LinOp* solver, const size_type& num_iterations,
152 const LinOp* residual, const LinOp* solution,
153 const LinOp* residual_norm,
154 const LinOp* implicit_sq_residual_norm) const override;
155
170 GKO_DEPRECATED("use three-parameter create")
171 static std::unique_ptr<Stream> create(
172 std::shared_ptr<const Executor> exec,
173 const Logger::mask_type& enabled_events = Logger::all_events_mask,
174 std::ostream& os = std::cout, bool verbose = false)
175 {
176 return std::unique_ptr<Stream>(new Stream(enabled_events, os, verbose));
177 }
178
193 static std::unique_ptr<Stream> create(
194 const Logger::mask_type& enabled_events = Logger::all_events_mask,
195 std::ostream& os = std::cerr, bool verbose = false)
196 {
197 return std::unique_ptr<Stream>(new Stream(enabled_events, os, verbose));
198 }
199
200protected:
212 GKO_DEPRECATED("use three-parameter constructor")
213 explicit Stream(
214 std::shared_ptr<const gko::Executor> exec,
215 const Logger::mask_type& enabled_events = Logger::all_events_mask,
216 std::ostream& os = std::cerr, bool verbose = false)
217 : Stream(enabled_events, os, verbose)
218 {}
219
231 explicit Stream(
232 const Logger::mask_type& enabled_events = Logger::all_events_mask,
233 std::ostream& os = std::cerr, bool verbose = false)
234 : Logger(enabled_events), os_(&os), verbose_(verbose)
235 {}
236
237
238private:
239 std::ostream* os_;
240 static constexpr const char* prefix_ = "[LOG] >>> ";
241 bool verbose_;
242};
243
244
245} // namespace log
246} // namespace gko
247
248
249#endif // GKO_PUBLIC_CORE_LOG_STREAM_HPP_
The first step in using the Ginkgo library consists of creating an executor.
Definition executor.hpp:616
A LinOpFactory represents a higher order mapping which transforms one linear operator into another.
Definition lin_op.hpp:386
Definition lin_op.hpp:118
Operations can be used to define functionalities whose implementations differ among devices.
Definition executor.hpp:259
A PolymorphicObject is the abstract base for all "heavy" objects in Ginkgo that behave polymorphicall...
Definition polymorphic_object.hpp:44
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition logger.hpp:25
Definition logger.hpp:76
static constexpr mask_type all_events_mask
Bitset Mask which activates all events.
Definition logger.hpp:89
Stream is a Logger which logs every event to a stream.
Definition stream.hpp:31
void on_free_started(const Executor *exec, const uintptr &location) const override
Executor's free started event.
void on_allocation_started(const Executor *exec, const size_type &num_bytes) const override
Executor's allocation started event.
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_iteration_complete(const LinOp *solver, const LinOp *b, 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_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.
static std::unique_ptr< Stream > create(const Logger::mask_type &enabled_events=Logger::all_events_mask, std::ostream &os=std::cerr, bool verbose=false)
Creates a Stream logger.
Definition stream.hpp:193
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_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_operation_completed(const Executor *exec, const Operation *operation) const override
Executor's operation completed event (method run).
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_polymorphic_object_create_completed(const Executor *exec, const PolymorphicObject *input, const PolymorphicObject *output) const override
PolymorphicObject's create completed event.
static std::unique_ptr< Stream > create(std::shared_ptr< const Executor > exec, const Logger::mask_type &enabled_events=Logger::all_events_mask, std::ostream &os=std::cout, bool verbose=false)
Creates a Stream logger.
Definition stream.hpp:171
void on_polymorphic_object_copy_completed(const Executor *exec, const PolymorphicObject *from, const PolymorphicObject *to) const override
PolymorphicObject's copy completed 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_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.
void on_polymorphic_object_create_started(const Executor *, const PolymorphicObject *po) const override
PolymorphicObject's create started 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_linop_apply_completed(const LinOp *A, const LinOp *b, const LinOp *x) const override
LinOp's apply completed 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_polymorphic_object_copy_started(const Executor *exec, const PolymorphicObject *from, const PolymorphicObject *to) const override
PolymorphicObject's copy started 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_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_linop_factory_generate_completed(const LinOpFactory *factory, const LinOp *input, const LinOp *output) const override
LinOp Factory's generate completed event.
void on_linop_factory_generate_started(const LinOpFactory *factory, const LinOp *input) const override
LinOp Factory's generate started event.
The Criterion class is a base class for all stopping criteria.
Definition criterion.hpp:36
@ criterion
Stopping criterion events.
@ factory
LinOpFactory events.
@ operation
Kernel execution and data movement.
The Ginkgo namespace.
Definition abstract_factory.hpp:20
std::uint8_t uint8
8-bit unsigned integral type.
Definition types.hpp:115
std::uintptr_t uintptr
Unsigned integer type capable of holding a pointer to void.
Definition types.hpp:138
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:86
This structure is used to represent versions of various Ginkgo modules.
Definition version.hpp:26