Ginkgo  Generated from pipelines/1554403166 branch based on develop. Ginkgo version 1.9.0
A numerical linear algebra library targeting many-core architectures
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 #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 public:
32  /* Executor events */
33  void on_allocation_started(const Executor* exec,
34  const size_type& num_bytes) const override;
35 
36  void on_allocation_completed(const Executor* exec,
37  const size_type& num_bytes,
38  const uintptr& location) const override;
39 
40  void on_free_started(const Executor* exec,
41  const uintptr& location) const override;
42 
43  void on_free_completed(const Executor* exec,
44  const uintptr& location) const override;
45 
46  void on_copy_started(const Executor* from, const Executor* to,
47  const uintptr& location_from,
48  const uintptr& location_to,
49  const size_type& num_bytes) const override;
50 
51  void on_copy_completed(const Executor* from, const Executor* to,
52  const uintptr& location_from,
53  const uintptr& location_to,
54  const size_type& num_bytes) const override;
55 
56  /* Operation events */
57  void on_operation_launched(const Executor* exec,
58  const Operation* operation) const override;
59 
60  void on_operation_completed(const Executor* exec,
61  const Operation* operation) const override;
62 
63  /* PolymorphicObject events */
65  const Executor*, const PolymorphicObject* po) const override;
66 
68  const Executor* exec, const PolymorphicObject* input,
69  const PolymorphicObject* output) const override;
70 
72  const Executor* exec, const PolymorphicObject* from,
73  const PolymorphicObject* to) const override;
74 
76  const Executor* exec, const PolymorphicObject* from,
77  const PolymorphicObject* to) const override;
78 
80  const Executor* exec, const PolymorphicObject* from,
81  const PolymorphicObject* to) const override;
82 
84  const Executor* exec, const PolymorphicObject* from,
85  const PolymorphicObject* to) const override;
86 
88  const Executor* exec, const PolymorphicObject* po) const override;
89 
90  /* LinOp events */
91  void on_linop_apply_started(const LinOp* A, const LinOp* b,
92  const LinOp* x) const override;
93 
94  void on_linop_apply_completed(const LinOp* A, const LinOp* b,
95  const LinOp* x) const override;
96 
97  void on_linop_advanced_apply_started(const LinOp* A, const LinOp* alpha,
98  const LinOp* b, const LinOp* beta,
99  const LinOp* x) const override;
100 
101  void on_linop_advanced_apply_completed(const LinOp* A, const LinOp* alpha,
102  const LinOp* b, const LinOp* beta,
103  const LinOp* x) const override;
104 
105  /* LinOpFactory events */
107  const LinOp* input) const override;
108 
110  const LinOpFactory* factory, const LinOp* input,
111  const LinOp* output) const override;
112 
113  /* Criterion events */
115  const size_type& num_iterations,
116  const LinOp* residual,
117  const LinOp* residual_norm,
118  const LinOp* solution,
119  const uint8& stopping_id,
120  const bool& set_finalized) const override;
121 
123  const stop::Criterion* criterion, const size_type& num_iterations,
124  const LinOp* residual, const LinOp* residual_norm,
125  const LinOp* solution, const uint8& stopping_id,
126  const bool& set_finalized, const array<stopping_status>* status,
127  const bool& one_changed, const bool& all_converged) const override;
128 
129  /* Internal solver events */
130  void on_iteration_complete(const LinOp* solver, const LinOp* b,
131  const LinOp* x, const size_type& num_iterations,
132  const LinOp* residual,
133  const LinOp* residual_norm,
134  const LinOp* implicit_resnorm_sq,
135  const array<stopping_status>* status,
136  bool stopped) const override;
137 
138  GKO_DEPRECATED(
139  "Please use the version with the additional stopping "
140  "information.")
141  void on_iteration_complete(const LinOp* solver,
142  const size_type& num_iterations,
143  const LinOp* residual, const LinOp* solution,
144  const LinOp* residual_norm) const override;
145 
146  GKO_DEPRECATED(
147  "Please use the version with the additional stopping "
148  "information.")
150  const LinOp* solver, const size_type& num_iterations,
151  const LinOp* residual, const LinOp* solution,
152  const LinOp* residual_norm,
153  const LinOp* implicit_sq_residual_norm) const override;
154 
169  GKO_DEPRECATED("use three-parameter create")
170  static std::unique_ptr<Stream> create(
171  std::shared_ptr<const Executor> exec,
172  const Logger::mask_type& enabled_events = Logger::all_events_mask,
173  std::ostream& os = std::cout, bool verbose = false)
174  {
175  return std::unique_ptr<Stream>(new Stream(enabled_events, os, verbose));
176  }
177 
192  static std::unique_ptr<Stream> create(
193  const Logger::mask_type& enabled_events = Logger::all_events_mask,
194  std::ostream& os = std::cerr, bool verbose = false)
195  {
196  return std::unique_ptr<Stream>(new Stream(enabled_events, os, verbose));
197  }
198 
199 protected:
211  GKO_DEPRECATED("use three-parameter constructor")
212  explicit Stream(
213  std::shared_ptr<const gko::Executor> exec,
214  const Logger::mask_type& enabled_events = Logger::all_events_mask,
215  std::ostream& os = std::cerr, bool verbose = false)
216  : Stream(enabled_events, os, verbose)
217  {}
218 
230  explicit Stream(
231  const Logger::mask_type& enabled_events = Logger::all_events_mask,
232  std::ostream& os = std::cerr, bool verbose = false)
233  : Logger(enabled_events), os_(&os), verbose_(verbose)
234  {}
235 
236 
237 private:
238  std::ostream* os_;
239  static constexpr const char* prefix_ = "[LOG] >>> ";
240  bool verbose_;
241 };
242 
243 
244 } // namespace log
245 } // namespace gko
246 
247 
248 #endif // GKO_PUBLIC_CORE_LOG_STREAM_HPP_
gko::uint8
std::uint8_t uint8
8-bit unsigned integral type.
Definition: types.hpp:115
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:170
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::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::LinOp
Definition: lin_op.hpp:117
gko::PolymorphicObject
A PolymorphicObject is the abstract base for all "heavy" objects in Ginkgo that behave polymorphicall...
Definition: polymorphic_object.hpp:43
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::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:138
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:86
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
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
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::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:88
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_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::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:192
gko::log::Logger
Definition: logger.hpp:75
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_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_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_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::Executor
The first step in using the Ginkgo library consists of creating an executor.
Definition: executor.hpp:615
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_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::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:384
gko::Operation
Operations can be used to define functionalities whose implementations differ among devices.
Definition: executor.hpp:258
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.