Ginkgo Generated from branch based on main. Ginkgo version 1.9.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
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#include <ginkgo/core/base/batch_multi_vector.hpp>
12#include <ginkgo/core/base/types.hpp>
13#include <ginkgo/core/log/logger.hpp>
14
15
16namespace gko {
17namespace batch {
23namespace log {
24namespace detail {
25
26
32template <typename ValueType>
33struct 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
69template <typename ValueType = default_precision>
70class BatchConvergence final : public gko::log::Logger {
71public:
72 using real_type = remove_complex<ValueType>;
73 using index_type = int;
74 using mask_type = gko::log::Logger::mask_type;
75
76 void on_batch_solver_completed(
77 const array<index_type>& iteration_count,
78 const array<real_type>& residual_norm) const override;
79
92 static std::unique_ptr<BatchConvergence> create(
93 const mask_type& enabled_events =
94 gko::log::Logger::batch_solver_completed_mask)
95 {
96 return std::unique_ptr<BatchConvergence>(
97 new BatchConvergence(enabled_events));
98 }
99
103 const array<index_type>& get_num_iterations() const noexcept
104 {
105 return iteration_count_;
106 }
107
111 const array<real_type>& get_residual_norm() const noexcept
112 {
113 return residual_norm_;
114 }
115
116protected:
117 explicit BatchConvergence(const mask_type& enabled_events =
118 gko::log::Logger::batch_solver_completed_mask)
119 : gko::log::Logger(enabled_events)
120 {}
121
122private:
123 mutable array<index_type> iteration_count_{};
124 mutable array<real_type> residual_norm_{};
125};
126
127
128} // namespace log
129} // namespace batch
130} // namespace gko
131
132
133#endif // GKO_PUBLIC_CORE_LOG_BATCH_LOGGER_HPP_
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition logger.hpp:25
Logs the final residuals and iteration counts for a batch solver.
Definition batch_logger.hpp:70
const array< index_type > & get_num_iterations() const noexcept
Definition batch_logger.hpp:103
const array< real_type > & get_residual_norm() const noexcept
Definition batch_logger.hpp:111
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:92
Definition logger.hpp:76
The Ginkgo namespace.
Definition abstract_factory.hpp:20
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:260
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:89