Ginkgo  Generated from pipelines/3133041809 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
stream.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 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 
15 namespace gko {
16 namespace log {
17 
18 
29 template <typename ValueType = default_precision>
30 class Stream : public Logger {
31  GKO_ASSERT_SUPPORTED_VALUE_TYPE;
32 
33 public:
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 */
67  const Executor*, const PolymorphicObject* po) const override;
68 
70  const Executor* exec, const PolymorphicObject* input,
71  const PolymorphicObject* output) const override;
72 
74  const Executor* exec, const PolymorphicObject* from,
75  const PolymorphicObject* to) const override;
76 
78  const Executor* exec, const PolymorphicObject* from,
79  const PolymorphicObject* to) const override;
80 
82  const Executor* exec, const PolymorphicObject* from,
83  const PolymorphicObject* to) const override;
84 
86  const Executor* exec, const PolymorphicObject* from,
87  const PolymorphicObject* to) const override;
88 
90  const Executor* exec, const PolymorphicObject* po) const override;
91 
92  /* LinOp events */
93  void on_linop_apply_started(const LinOp* A, const AbstractMultiVector* b,
94  const AbstractMultiVector* x) const override;
95 
96  void on_linop_apply_completed(const LinOp* A, const AbstractMultiVector* b,
97  const AbstractMultiVector* x) const override;
98 
100  const LinOp* A, const AbstractMultiVector* alpha,
101  const AbstractMultiVector* b, const AbstractMultiVector* beta,
102  const AbstractMultiVector* x) const override;
103 
105  const LinOp* A, const AbstractMultiVector* alpha,
106  const AbstractMultiVector* b, const AbstractMultiVector* beta,
107  const AbstractMultiVector* x) const override;
108 
109  /* LinOpFactory events */
111  const LinOp* input) const override;
112 
114  const LinOpFactory* factory, const LinOp* input,
115  const LinOp* output) const override;
116 
117  /* Criterion events */
119  const size_type& num_iterations,
120  const AbstractMultiVector* residual,
121  const AbstractMultiVector* residual_norm,
122  const AbstractMultiVector* solution,
123  const uint8& stopping_id,
124  const bool& set_finalized) const override;
125 
127  const stop::Criterion* criterion, const size_type& num_iterations,
128  const AbstractMultiVector* residual,
129  const AbstractMultiVector* residual_norm,
130  const AbstractMultiVector* solution, const uint8& stopping_id,
131  const bool& set_finalized, const array<stopping_status>* status,
132  const bool& one_changed, const bool& all_converged) const override;
133 
134  /* Internal solver events */
135  void on_iteration_complete(const LinOp* solver,
136  const AbstractMultiVector* b,
137  const AbstractMultiVector* x,
138  const size_type& num_iterations,
139  const AbstractMultiVector* residual,
140  const AbstractMultiVector* residual_norm,
141  const AbstractMultiVector* implicit_resnorm_sq,
142  const array<stopping_status>* status,
143  bool stopped) const override;
144 
145  GKO_DEPRECATED(
146  "Please use the version with the additional stopping "
147  "information.")
149  const LinOp* solver, const size_type& num_iterations,
150  const AbstractMultiVector* residual,
151  const AbstractMultiVector* solution,
152  const AbstractMultiVector* residual_norm) const override;
153 
154  GKO_DEPRECATED(
155  "Please use the version with the additional stopping "
156  "information.")
158  const LinOp* solver, const size_type& num_iterations,
159  const AbstractMultiVector* residual,
160  const AbstractMultiVector* solution,
161  const AbstractMultiVector* residual_norm,
162  const AbstractMultiVector* implicit_sq_residual_norm) const override;
163 
178  GKO_DEPRECATED("use three-parameter create")
179  static std::unique_ptr<Stream> create(
180  std::shared_ptr<const Executor> exec,
181  const Logger::mask_type& enabled_events = Logger::all_events_mask,
182  std::ostream& os = std::cout, bool verbose = false)
183  {
184  return std::unique_ptr<Stream>(new Stream(enabled_events, os, verbose));
185  }
186 
201  static std::unique_ptr<Stream> create(
202  const Logger::mask_type& enabled_events = Logger::all_events_mask,
203  std::ostream& os = std::cerr, bool verbose = false)
204  {
205  return std::unique_ptr<Stream>(new Stream(enabled_events, os, verbose));
206  }
207 
208 protected:
220  GKO_DEPRECATED("use three-parameter constructor")
221  explicit Stream(
222  std::shared_ptr<const gko::Executor> exec,
223  const Logger::mask_type& enabled_events = Logger::all_events_mask,
224  std::ostream& os = std::cerr, bool verbose = false)
225  : Stream(enabled_events, os, verbose)
226  {}
227 
239  explicit Stream(
240  const Logger::mask_type& enabled_events = Logger::all_events_mask,
241  std::ostream& os = std::cerr, bool verbose = false)
242  : Logger(enabled_events), os_(&os), verbose_(verbose)
243  {}
244 
245 
246 private:
247  std::ostream* os_;
248  static constexpr const char* prefix_ = "[LOG] >>> ";
249  bool verbose_;
250 };
251 
252 
253 } // namespace log
254 } // namespace gko
255 
256 
257 #endif // GKO_PUBLIC_CORE_LOG_STREAM_HPP_
gko::uint8
std::uint8_t uint8
8-bit unsigned integral type.
Definition: types.hpp:131
gko::log::Stream::on_linop_advanced_apply_started
void on_linop_advanced_apply_started(const LinOp *A, const AbstractMultiVector *alpha, const AbstractMultiVector *b, const AbstractMultiVector *beta, const AbstractMultiVector *x) const override
LinOp's advanced apply 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::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:179
gko::log::Stream
Stream is a Logger which logs every event to a stream.
Definition: stream.hpp:30
gko::log::profile_event_category::solver
Solver events.
gko::LinOp
Definition: lin_op.hpp:163
gko::PolymorphicObject
A PolymorphicObject is the abstract base for all "heavy" objects in Ginkgo that behave polymorphicall...
Definition: polymorphic_object.hpp:46
gko::log::profile_event_category::factory
LinOpFactory events.
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_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_iteration_complete
void on_iteration_complete(const LinOp *solver, const AbstractMultiVector *b, const AbstractMultiVector *x, const size_type &num_iterations, const AbstractMultiVector *residual, const AbstractMultiVector *residual_norm, const AbstractMultiVector *implicit_resnorm_sq, const array< stopping_status > *status, bool stopped) const override
Register the iteration_complete event which logs every completed iterations.
gko::log::profile_event_category::criterion
Stopping criterion events.
gko::uintptr
std::uintptr_t uintptr
Unsigned integer type capable of holding a pointer to void.
Definition: types.hpp:154
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::on_polymorphic_object_create_started
void on_polymorphic_object_create_started(const Executor *, const PolymorphicObject *po) const override
PolymorphicObject's create started event.
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:102
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_linop_advanced_apply_completed
void on_linop_advanced_apply_completed(const LinOp *A, const AbstractMultiVector *alpha, const AbstractMultiVector *b, const AbstractMultiVector *beta, const AbstractMultiVector *x) const override
LinOp's advanced apply completed event.
gko::log::Stream::on_criterion_check_started
void on_criterion_check_started(const stop::Criterion *criterion, const size_type &num_iterations, const AbstractMultiVector *residual, const AbstractMultiVector *residual_norm, const AbstractMultiVector *solution, const uint8 &stopping_id, const bool &set_finalized) const override
stop::Criterion's check started event.
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:19
gko::array
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition: array.hpp:26
gko::log::Logger::all_events_mask
static constexpr mask_type all_events_mask
Bitset Mask which activates all events.
Definition: logger.hpp:90
gko::log::Stream::on_criterion_check_completed
void on_criterion_check_completed(const stop::Criterion *criterion, const size_type &num_iterations, const AbstractMultiVector *residual, const AbstractMultiVector *residual_norm, const AbstractMultiVector *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_launched
void on_operation_launched(const Executor *exec, const Operation *operation) const override
Executor's operation launched event (method run).
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_linop_apply_started
void on_linop_apply_started(const LinOp *A, const AbstractMultiVector *b, const AbstractMultiVector *x) const override
LinOp's apply started 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:201
gko::log::Logger
Definition: logger.hpp:77
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_polymorphic_object_deleted
void on_polymorphic_object_deleted(const Executor *exec, const PolymorphicObject *po) const override
PolymorphicObject's deleted event.
gko::stop::Criterion
The Criterion class is a base class for all stopping criteria.
Definition: criterion.hpp:36
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_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_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_operation_completed
void on_operation_completed(const Executor *exec, const Operation *operation) const override
Executor's operation completed event (method run).
gko::log::profile_event_category::operation
Kernel execution and data movement.
gko::log::Stream::on_linop_apply_completed
void on_linop_apply_completed(const LinOp *A, const AbstractMultiVector *b, const AbstractMultiVector *x) const override
LinOp's apply completed event.
gko::Executor
The first step in using the Ginkgo library consists of creating an executor.
Definition: executor.hpp:617
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::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::LinOpFactory
A LinOpFactory represents a higher order mapping which transforms one linear operator into another.
Definition: lin_op.hpp:447
gko::AbstractMultiVector
Abstract interface class for (multi-)vector types.
Definition: multivector.hpp:81
gko::Operation
Operations can be used to define functionalities whose implementations differ among devices.
Definition: executor.hpp:257