Ginkgo  Generated from tags/v1.0.0^0 branch based on master. Ginkgo version 1.0.0
A numerical linear algebra library targeting many-core architectures
stream.hpp
1 /*******************************<GINKGO LICENSE>******************************
2 Copyright (c) 2017-2019, the Ginkgo authors
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8 
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15 
16 3. Neither the name of the copyright holder nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19 
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 ******************************<GINKGO LICENSE>*******************************/
32 
33 #ifndef GKO_CORE_LOG_STREAM_HPP_
34 #define GKO_CORE_LOG_STREAM_HPP_
35 
36 
37 #include <ginkgo/core/log/logger.hpp>
38 
39 
40 #include <fstream>
41 #include <iostream>
42 
43 
44 namespace gko {
45 namespace log {
46 
47 
58 template <typename ValueType = default_precision>
59 class Stream : public Logger {
60 public:
61  /* Executor events */
62  void on_allocation_started(const Executor *exec,
63  const size_type &num_bytes) const override;
64 
65  void on_allocation_completed(const Executor *exec,
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 
75  void on_copy_started(const Executor *from, const Executor *to,
76  const uintptr &location_from,
77  const uintptr &location_to,
78  const size_type &num_bytes) const override;
79 
80  void on_copy_completed(const Executor *from, const Executor *to,
81  const uintptr &location_from,
82  const uintptr &location_to,
83  const size_type &num_bytes) const override;
84 
85  /* Operation events */
86  void on_operation_launched(const Executor *exec,
87  const Operation *operation) const override;
88 
89  void on_operation_completed(const Executor *exec,
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 *po) const override;
110 
111  /* LinOp events */
112  void on_linop_apply_started(const LinOp *A, const LinOp *b,
113  const LinOp *x) const override;
114 
115  void on_linop_apply_completed(const LinOp *A, const LinOp *b,
116  const LinOp *x) const override;
117 
118  void on_linop_advanced_apply_started(const LinOp *A, const LinOp *alpha,
119  const LinOp *b, const LinOp *beta,
120  const LinOp *x) const override;
121 
122  void on_linop_advanced_apply_completed(const LinOp *A, const LinOp *alpha,
123  const LinOp *b, const LinOp *beta,
124  const LinOp *x) const override;
125 
126  /* LinOpFactory events */
128  const LinOp *input) const override;
129 
131  const LinOpFactory *factory, const LinOp *input,
132  const LinOp *output) const override;
133 
134  /* Criterion events */
135  void on_criterion_check_started(const stop::Criterion *criterion,
136  const size_type &num_iterations,
137  const LinOp *residual,
138  const LinOp *residual_norm,
139  const LinOp *solution,
140  const uint8 &stopping_id,
141  const bool &set_finalized) const override;
142 
144  const stop::Criterion *criterion, const size_type &num_iterations,
145  const LinOp *residual, const LinOp *residual_norm,
146  const LinOp *solutino, const uint8 &stopping_id,
147  const bool &set_finalized, const Array<stopping_status> *status,
148  const bool &one_changed, const bool &all_converged) const override;
149 
150  /* Internal solver events */
152  const LinOp *solver, const size_type &num_iterations,
153  const LinOp *residual, const LinOp *solution = nullptr,
154  const LinOp *residual_norm = nullptr) const override;
155 
174  static std::unique_ptr<Stream> create(
175  std::shared_ptr<const Executor> exec,
176  const Logger::mask_type &enabled_events = Logger::all_events_mask,
177  std::ostream &os = std::cout, bool verbose = false)
178  {
179  return std::unique_ptr<Stream>(
180  new Stream(exec, enabled_events, os, verbose));
181  }
182 
183 protected:
195  explicit Stream(
196  std::shared_ptr<const gko::Executor> exec,
197  const Logger::mask_type &enabled_events = Logger::all_events_mask,
198  std::ostream &os = std::cout, bool verbose = false)
199  : Logger(exec, enabled_events), os_(os), verbose_(verbose)
200  {}
201 
202 
203 private:
204  std::ostream &os_;
205  static constexpr const char *prefix_ = "[LOG] >>> ";
206  bool verbose_;
207 };
208 
209 
210 } // namespace log
211 } // namespace gko
212 
213 
214 #endif // GKO_CORE_LOG_STREAM_HPP_
Definition: logger.hpp:90
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&#39;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&#39;s check started event.
void on_linop_factory_generate_started(const LinOpFactory *factory, const LinOp *input) const override
LinOp Factory&#39;s generate started event.
void on_polymorphic_object_create_started(const Executor *, const PolymorphicObject *po) const override
PolymorphicObject&#39;s create started event.
void on_linop_apply_started(const LinOp *A, const LinOp *b, const LinOp *x) const override
LinOp&#39;s apply started event.
void on_free_started(const Executor *exec, const uintptr &location) const override
Executor&#39;s free started event.
A LinOpFactory represents a higher order mapping which transforms one linear operator into another...
Definition: lin_op.hpp:356
void on_allocation_started(const Executor *exec, const size_type &num_bytes) const override
Executor&#39;s allocation 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 *solutino, 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&#39;s check completed event.
void on_polymorphic_object_create_completed(const Executor *exec, const PolymorphicObject *input, const PolymorphicObject *output) const override
PolymorphicObject&#39;s create completed event.
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:94
The Ginkgo namespace.
Definition: abstract_factory.hpp:45
A PolymorphicObject is the abstract base for all "heavy" objects in Ginkgo that behave polymorphicall...
Definition: polymorphic_object.hpp:67
void on_operation_launched(const Executor *exec, const Operation *operation) const override
Executor&#39;s operation launched event (method run).
void on_allocation_completed(const Executor *exec, const size_type &num_bytes, const uintptr &location) const override
Executor&#39;s allocation completed event.
void on_polymorphic_object_copy_started(const Executor *exec, const PolymorphicObject *from, const PolymorphicObject *to) const override
PolymorphicObject&#39;s copy started event.
Definition: lin_op.hpp:134
void on_operation_completed(const Executor *exec, const Operation *operation) const override
Executor&#39;s operation completed event (method run).
std::uint8_t uint8
8-bit unsigned integral type.
Definition: types.hpp:123
Stream is a Logger which logs every event to a stream.
Definition: stream.hpp:59
void on_iteration_complete(const LinOp *solver, const size_type &num_iterations, const LinOp *residual, const LinOp *solution=nullptr, const LinOp *residual_norm=nullptr) const override
Register the iteration_complete event which logs every completed iterations.
void on_linop_apply_completed(const LinOp *A, const LinOp *b, const LinOp *x) const override
LinOp&#39;s apply completed event.
Operations can be used to define functionalities whose implementations differ among devices...
Definition: executor.hpp:173
void on_linop_advanced_apply_completed(const LinOp *A, const LinOp *alpha, const LinOp *b, const LinOp *beta, const LinOp *x) const override
LinOp&#39;s advanced apply completed event.
An Array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the Arr...
Definition: array.hpp:63
void on_free_completed(const Executor *exec, const uintptr &location) const override
Executor&#39;s free completed event.
void on_polymorphic_object_deleted(const Executor *exec, const PolymorphicObject *po) const override
PolymorphicObject&#39;s deleted event.
static constexpr mask_type all_events_mask
Bitset Mask which activates all events.
Definition: logger.hpp:103
The Criterion class is a base class for all stopping criteria.
Definition: criterion.hpp:63
void on_polymorphic_object_copy_completed(const Executor *exec, const PolymorphicObject *from, const PolymorphicObject *to) const override
PolymorphicObject&#39;s copy 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&#39;s advanced apply started event.
The first step in using the Ginkgo library consists of creating an executor.
Definition: executor.hpp:410
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:174
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&#39;s copy completed event.
void on_linop_factory_generate_completed(const LinOpFactory *factory, const LinOp *input, const LinOp *output) const override
LinOp Factory&#39;s generate completed event.