5 #ifndef GKO_PUBLIC_CORE_BASE_DENSE_CACHE_HPP_
6 #define GKO_PUBLIC_CORE_BASE_DENSE_CACHE_HPP_
13 #include <ginkgo/core/base/array.hpp>
14 #include <ginkgo/core/base/dim.hpp>
15 #include <ginkgo/core/base/executor.hpp>
27 template <
typename ValueType>
46 template <
typename ValueType>
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{};
69 void init_from(
const matrix::Dense<ValueType>* template_vec)
const;
80 void init(std::shared_ptr<const Executor> exec, dim<2> size)
const;
86 matrix::Dense<ValueType>& operator*()
const {
return *vec; }
92 matrix::Dense<ValueType>* operator->()
const {
return vec.get(); }
98 matrix::Dense<ValueType>* get()
const {
return vec.get(); }
103 class GenericDenseCacheAccessor;
116 struct GenericDenseCache {
117 friend class GenericDenseCacheAccessor;
119 GenericDenseCache() =
default;
120 ~GenericDenseCache() =
default;
121 GenericDenseCache(
const GenericDenseCache&);
122 GenericDenseCache(GenericDenseCache&&) noexcept;
123 GenericDenseCache& operator=(const GenericDenseCache&);
124 GenericDenseCache& operator=(GenericDenseCache&&) noexcept;
131 template <typename ValueType>
132 std::shared_ptr<matrix::Dense<ValueType>> get(
133 std::shared_ptr<const Executor> exec, dim<2> size) const;
136 mutable
array<
char> workspace;
141 class ScalarCacheAccessor;
155 friend class ScalarCacheAccessor;
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;
169 template <
typename ValueType>
170 std::shared_ptr<const matrix::Dense<ValueType>> get()
const;
173 std::shared_ptr<const Executor> exec;
175 mutable std::map<std::string, std::shared_ptr<const gko::LinOp>> scalars;
183 #endif // GKO_PUBLIC_CORE_BASE_DENSE_CACHE_HPP_