Ginkgo  Generated from pipelines/2171896597 branch based on develop. Ginkgo version 1.11.0
A numerical linear algebra library targeting many-core architectures
batch_logger.hpp
1 // SPDX-FileCopyrightText: 2017 - 2025 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 #include <ginkgo/core/base/batch_multi_vector.hpp>
12 #include <ginkgo/core/base/types.hpp>
13 #include <ginkgo/core/log/logger.hpp>
14 
15 
16 namespace gko {
17 namespace batch {
23 namespace log {
24 namespace detail {
25 
26 
32 template <typename ValueType>
33 struct log_data final {
34  using real_type = remove_complex<ValueType>;
35  using index_type = int;
36 
37  log_data(std::shared_ptr<const Executor> exec, size_type num_batch_items);
38 
39  log_data(std::shared_ptr<const Executor> exec, size_type num_batch_items,
40  array<unsigned char>& workspace);
41 
45  array<real_type> res_norms;
46 
50  array<index_type> iter_counts;
51 };
52 
53 
54 } // namespace detail
55 
56 
69 template <typename ValueType = default_precision>
70 class BatchConvergence final : public gko::log::Logger {
71  GKO_ASSERT_SUPPORTED_VALUE_TYPE;
72 
73 public:
74  using real_type = remove_complex<ValueType>;
75  using index_type = int;
76  using mask_type = gko::log::Logger::mask_type;
77 
78  void on_batch_solver_completed(
79  const array<index_type>& iteration_count,
80  const array<real_type>& residual_norm) const override;
81 
94  static std::unique_ptr<BatchConvergence> create(
95  const mask_type& enabled_events =
96  gko::log::Logger::batch_solver_completed_mask)
97  {
98  return std::unique_ptr<BatchConvergence>(
99  new BatchConvergence(enabled_events));
100  }
101 
105  const array<index_type>& get_num_iterations() const noexcept
106  {
107  return iteration_count_;
108  }
109 
113  const array<real_type>& get_residual_norm() const noexcept
114  {
115  return residual_norm_;
116  }
117 
118 protected:
119  explicit BatchConvergence(const mask_type& enabled_events =
120  gko::log::Logger::batch_solver_completed_mask)
121  : gko::log::Logger(enabled_events)
122  {}
123 
124 private:
125  mutable array<index_type> iteration_count_{};
126  mutable array<real_type> residual_norm_{};
127 };
128 
129 
130 } // namespace log
131 } // namespace batch
132 } // namespace gko
133 
134 
135 #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:113
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:90
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:94
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
gko::array< unsigned char >
gko::log::Logger
Definition: logger.hpp:74
gko::batch::log::BatchConvergence::get_num_iterations
const array< index_type > & get_num_iterations() const noexcept
Definition: batch_logger.hpp:105
gko::batch::log::BatchConvergence
Logs the final residuals and iteration counts for a batch solver.
Definition: batch_logger.hpp:70
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:264