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
stream.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_STREAM_HPP_
34#define GKO_PUBLIC_CORE_LOG_STREAM_HPP_
35
36
37#include <fstream>
38#include <iostream>
39
40
41#include <ginkgo/core/log/logger.hpp>
42
43
44namespace gko {
45namespace log {
46
47
58template <typename ValueType = default_precision>
59class Stream : public Logger {
60public:
61 /* Executor events */
63 const size_type& num_bytes) const override;
64
66 const size_type& num_bytes,
67 const uintptr& location) const override;
68
69 void on_free_started(const Executor* exec,
70 const uintptr& location) const override;
71
72 void on_free_completed(const Executor* exec,
73 const uintptr& location) const override;
74
77 const uintptr& location_to,
78 const size_type& num_bytes) const override;
79
82 const uintptr& location_to,
83 const size_type& num_bytes) const override;
84
85 /* Operation events */
87 const Operation* operation) const override;
88
90 const Operation* operation) const override;
91
92 /* PolymorphicObject events */
94 const Executor*, const PolymorphicObject* po) const override;
95
97 const Executor* exec, const PolymorphicObject* input,
98 const PolymorphicObject* output) const override;
99
101 const Executor* exec, const PolymorphicObject* from,
102 const PolymorphicObject* to) const override;
103
105 const Executor* exec, const PolymorphicObject* from,
106 const PolymorphicObject* to) const override;
107
109 const Executor* exec, const PolymorphicObject* from,
110 const PolymorphicObject* to) const override;
111
113 const Executor* exec, const PolymorphicObject* from,
114 const PolymorphicObject* to) const override;
115
117 const Executor* exec, const PolymorphicObject* po) const override;
118
119 /* LinOp events */
120 void on_linop_apply_started(const LinOp* A, const LinOp* b,
121 const LinOp* x) const override;
122
123 void on_linop_apply_completed(const LinOp* A, const LinOp* b,
124 const LinOp* x) const override;
125
126 void on_linop_advanced_apply_started(const LinOp* A, const LinOp* alpha,
127 const LinOp* b, const LinOp* beta,
128 const LinOp* x) const override;
129
130 void on_linop_advanced_apply_completed(const LinOp* A, const LinOp* alpha,
131 const LinOp* b, const LinOp* beta,
132 const LinOp* x) const override;
133
134 /* LinOpFactory events */
136 const LinOp* input) const override;
137
139 const LinOpFactory* factory, const LinOp* input,
140 const LinOp* output) const override;
141
142 /* Criterion events */
144 const size_type& num_iterations,
145 const LinOp* residual,
146 const LinOp* residual_norm,
147 const LinOp* solution,
148 const uint8& stopping_id,
149 const bool& set_finalized) const override;
150
152 const stop::Criterion* criterion, const size_type& num_iterations,
153 const LinOp* residual, const LinOp* residual_norm,
154 const LinOp* solution, const uint8& stopping_id,
155 const bool& set_finalized, const array<stopping_status>* status,
156 const bool& one_changed, const bool& all_converged) const override;
157
158 /* Internal solver events */
160 const LinOp* x, const size_type& num_iterations,
161 const LinOp* residual,
162 const LinOp* residual_norm,
164 const array<stopping_status>* status,
165 bool stopped) const override;
166
167 GKO_DEPRECATED(
168 "Please use the version with the additional stopping "
169 "information.")
171 const size_type& num_iterations,
172 const LinOp* residual, const LinOp* solution,
173 const LinOp* residual_norm) const override;
174
175 GKO_DEPRECATED(
177 "information.")
179 const LinOp* solver, const size_type& num_iterations,
180 const LinOp* residual, const LinOp* solution,
181 const LinOp* residual_norm,
182 const LinOp* implicit_sq_residual_norm) const override;
183
202 GKO_DEPRECATED("use three-parameter create")
203 static std::unique_ptr<Stream> create(
204 std::shared_ptr<const Executor> exec,
206 std::ostream& os = std::cout, bool verbose = false)
207 {
208 return std::unique_ptr<Stream>(new Stream(enabled_events, os, verbose));
209 }
210
229 static std::unique_ptr<Stream> create(
230 const Logger::mask_type& enabled_events = Logger::all_events_mask,
231 std::ostream& os = std::cerr, bool verbose = false)
232 {
233 return std::unique_ptr<Stream>(new Stream(enabled_events, os, verbose));
234 }
235
236protected:
248 GKO_DEPRECATED("use three-parameter constructor")
250 std::shared_ptr<const gko::Executor> exec,
252 std::ostream& os = std::cerr, bool verbose = false)
254 {}
255
267 explicit Stream(
268 const Logger::mask_type& enabled_events = Logger::all_events_mask,
269 std::ostream& os = std::cerr, bool verbose = false)
270 : Logger(enabled_events), os_(&os), verbose_(verbose)
271 {}
272
273
274private:
275 std::ostream* os_;
276 static constexpr const char* prefix_ = "[LOG] >>> ";
277 bool verbose_;
278};
279
280
281} // namespace log
282} // namespace gko
283
284
285#endif // GKO_PUBLIC_CORE_LOG_STREAM_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
Stream is a Logger which logs every event to a stream.
Definition stream.hpp:59
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:229
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:203
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: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
This structure is used to represent versions of various Ginkgo modules.
Definition version.hpp:54