Ginkgo: ginkgo/core/log/stream.hpp Source File

| Ginkgo Generated from branch based on main. Ginkgo version 1.11.0 A numerical linear algebra library targeting many-core architectures

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