Ginkgo Generated from branch based on main. Ginkgo version 1.10.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
dense_cache.hpp
1// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_BASE_DENSE_CACHE_HPP_
6#define GKO_PUBLIC_CORE_BASE_DENSE_CACHE_HPP_
7
8
9#include <map>
10#include <memory>
11#include <string>
12
13#include <ginkgo/core/base/array.hpp>
14#include <ginkgo/core/base/dim.hpp>
15#include <ginkgo/core/base/executor.hpp>
16
17
18namespace gko {
19
20
21class LinOp;
22
23
24namespace matrix {
25
26
27template <typename ValueType>
28class Dense;
29
30
31}
32
33
34namespace detail {
35
36
46template <typename ValueType>
47struct DenseCache {
48 DenseCache() = default;
49 ~DenseCache() = default;
50 DenseCache(const DenseCache&) {}
51 DenseCache(DenseCache&&) noexcept {}
52 DenseCache& operator=(const DenseCache&) { return *this; }
53 DenseCache& operator=(DenseCache&&) noexcept { return *this; }
54 mutable std::unique_ptr<matrix::Dense<ValueType>> vec{};
55
56
69 void init_from(const matrix::Dense<ValueType>* template_vec) const;
70
80 void init(std::shared_ptr<const Executor> exec, dim<2> size) const;
81
86 matrix::Dense<ValueType>& operator*() const { return *vec; }
87
92 matrix::Dense<ValueType>* operator->() const { return vec.get(); }
93
98 matrix::Dense<ValueType>* get() const { return vec.get(); }
99};
100
101
102// helper to access private member for testing
103class GenericDenseCacheAccessor;
104
105
116struct GenericDenseCache {
117 friend class GenericDenseCacheAccessor;
118
119 GenericDenseCache() = default;
120 ~GenericDenseCache() = default;
121 GenericDenseCache(const GenericDenseCache&);
122 GenericDenseCache(GenericDenseCache&&) noexcept;
123 GenericDenseCache& operator=(const GenericDenseCache&);
124 GenericDenseCache& operator=(GenericDenseCache&&) noexcept;
125
131 template <typename ValueType>
132 std::shared_ptr<matrix::Dense<ValueType>> get(
133 std::shared_ptr<const Executor> exec, dim<2> size) const;
134
135private:
136 mutable array<char> workspace;
137};
138
139
140// helper to access private member for testing.
141class ScalarCacheAccessor;
142
143
154struct ScalarCache {
155 friend class ScalarCacheAccessor;
156
157 ScalarCache(std::shared_ptr<const Executor> executor, double scalar_value);
158 ~ScalarCache() = default;
159 ScalarCache(const ScalarCache& other);
160 ScalarCache(ScalarCache&& other) noexcept;
161 ScalarCache& operator=(const ScalarCache& other);
162 ScalarCache& operator=(ScalarCache&& other) noexcept;
163
169 template <typename ValueType>
170 std::shared_ptr<const matrix::Dense<ValueType>> get() const;
171
172private:
173 std::shared_ptr<const Executor> exec;
174 double value;
175 mutable std::map<std::string, std::shared_ptr<const gko::LinOp>> scalars;
176};
177
178
179} // namespace detail
180} // namespace gko
181
182
183#endif // GKO_PUBLIC_CORE_BASE_DENSE_CACHE_HPP_
Definition lin_op.hpp:117
Dense is a matrix format which explicitly stores all values of the matrix.
Definition dense.hpp:120
The matrix namespace.
Definition dense_cache.hpp:24
The Ginkgo namespace.
Definition abstract_factory.hpp:20
@ array
The matrix should be written as dense matrix in column-major order.
Definition mtx_io.hpp:96