Ginkgo  Generated from pipelines/1330831941 branch based on master. Ginkgo version 1.8.0
A numerical linear algebra library targeting many-core architectures
batch_logger.hpp
1 // SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_LOG_BATCH_LOGGER_HPP_
6 #define GKO_PUBLIC_CORE_LOG_BATCH_LOGGER_HPP_
7 
8 
9 #include <memory>
10 
11 
12 #include <ginkgo/core/base/batch_multi_vector.hpp>
13 #include <ginkgo/core/base/types.hpp>
14 #include <ginkgo/core/log/logger.hpp>
15 
16 
17 namespace gko {
18 namespace batch {
24 namespace log {
25 namespace detail {
26 
27 
33 template <typename ValueType>
34 struct log_data final {
35  using real_type = remove_complex<ValueType>;
36  using index_type = int;
37 
38  log_data(std::shared_ptr<const Executor> exec, size_type num_batch_items);
39 
40  log_data(std::shared_ptr<const Executor> exec, size_type num_batch_items,
41  array<unsigned char>& workspace);
42 
46  array<real_type> res_norms;
47 
51  array<index_type> iter_counts;
52 };
53 
54 
55 } // namespace detail
56 
57 
70 template <typename ValueType = default_precision>
71 class BatchConvergence final : public gko::log::Logger {
72 public:
73  using real_type = remove_complex<ValueType>;
74  using index_type = int;
75  using mask_type = gko::log::Logger::mask_type;
76 
77  void on_batch_solver_completed(
78  const array<index_type>& iteration_count,
79  const array<real_type>& residual_norm) const override;
80 
93  static std::unique_ptr<BatchConvergence> create(
94  const mask_type& enabled_events =
95  gko::log::Logger::batch_solver_completed_mask)
96  {
97  return std::unique_ptr<BatchConvergence>(
98  new BatchConvergence(enabled_events));
99  }
100 
104  const array<index_type>& get_num_iterations() const noexcept
105  {
106  return iteration_count_;
107  }
108 
112  const array<real_type>& get_residual_norm() const noexcept
113  {
114  return residual_norm_;
115  }
116 
117 protected:
118  explicit BatchConvergence(const mask_type& enabled_events =
119  gko::log::Logger::batch_solver_completed_mask)
120  : gko::log::Logger(enabled_events)
121  {}
122 
123 private:
124  mutable array<index_type> iteration_count_{};
125  mutable array<real_type> residual_norm_{};
126 };
127 
128 
129 } // namespace log
130 } // namespace batch
131 } // namespace gko
132 
133 
134 #endif // GKO_PUBLIC_CORE_LOG_BATCH_LOGGER_HPP_
gko::batch::log::BatchConvergence::get_residual_norm
const array< real_type > & get_residual_norm() const noexcept
Definition: batch_logger.hpp:112
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:108
gko::batch::log::BatchConvergence::create
static std::unique_ptr< BatchConvergence > create(const mask_type &enabled_events=gko::log::Logger::batch_solver_completed_mask)
Creates a convergence logger.
Definition: batch_logger.hpp:93
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
gko::array< unsigned char >
gko::log::Logger
Definition: logger.hpp:76
gko::batch::log::BatchConvergence::get_num_iterations
const array< index_type > & get_num_iterations() const noexcept
Definition: batch_logger.hpp:104
gko::batch::log::BatchConvergence
Logs the final residuals and iteration counts for a batch solver.
Definition: batch_logger.hpp:71
gko::remove_complex
typename detail::remove_complex_s< T >::type remove_complex
Obtain the type which removed the complex of complex/scalar type or the template parameter of class b...
Definition: math.hpp:326