Ginkgo  Generated from pipelines/1330831941 branch based on master. Ginkgo version 1.8.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 
13 #include <ginkgo/core/log/logger.hpp>
14 
15 
16 namespace gko {
17 namespace log {
18 
19 
30 template <typename ValueType = default_precision>
31 class Stream : public Logger {
32 public:
33  /* Executor events */
34  void on_allocation_started(const Executor* exec,
35  const size_type& num_bytes) const override;
36 
37  void on_allocation_completed(const Executor* exec,
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 */
58  void on_operation_launched(const Executor* exec,
59  const Operation* operation) const override;
60 
61  void on_operation_completed(const Executor* exec,
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 */
131  void on_iteration_complete(const LinOp* solver, const LinOp* b,
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.")
142  void on_iteration_complete(const LinOp* solver,
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 
200 protected:
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 
238 private:
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_
gko::uint8
std::uint8_t uint8
8-bit unsigned integral type.
Definition: types.hpp:137
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:171
gko::log::Stream
Stream is a Logger which logs every event to a stream.
Definition: stream.hpp:31
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:118
gko::PolymorphicObject
A PolymorphicObject is the abstract base for all "heavy" objects in Ginkgo that behave polymorphicall...
Definition: polymorphic_object.hpp:44
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:160
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:108
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:27
gko::log::Logger::all_events_mask
static constexpr mask_type all_events_mask
Bitset Mask which activates all events.
Definition: logger.hpp:89
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:193
gko::log::Logger
Definition: logger.hpp:76
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:616
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:385
gko::Operation
Operations can be used to define functionalities whose implementations differ among devices.
Definition: executor.hpp:259
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.