ginkgo/core/matrix/sellp.hpp Source File

ginkgo/core/matrix/sellp.hpp Source File#

Reference API: ginkgo/core/matrix/sellp.hpp Source File
Reference API
sellp.hpp
1// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_MATRIX_SELLP_HPP_
6#define GKO_PUBLIC_CORE_MATRIX_SELLP_HPP_
7
8
9#include <ginkgo/core/base/array.hpp>
10#include <ginkgo/core/base/lin_op.hpp>
11
12
13namespace gko {
14namespace matrix {
15
16
17constexpr int default_slice_size = 64;
18constexpr int default_stride_factor = 1;
19
20
21template <typename ValueType>
22class Dense;
23
24template <typename ValueType, typename IndexType>
25class Csr;
26
41template <typename ValueType = default_precision, typename IndexType = int32>
42class Sellp : public EnableLinOp<Sellp<ValueType, IndexType>>,
43 public ConvertibleTo<Sellp<next_precision<ValueType>, IndexType>>,
44#if GINKGO_ENABLE_HALF
45 public ConvertibleTo<
46 Sellp<next_precision<next_precision<ValueType>>, IndexType>>,
47#endif
48 public ConvertibleTo<Dense<ValueType>>,
49 public ConvertibleTo<Csr<ValueType, IndexType>>,
50 public DiagonalExtractable<ValueType>,
51 public ReadableFromMatrixData<ValueType, IndexType>,
52 public WritableToMatrixData<ValueType, IndexType>,
54 remove_complex<Sellp<ValueType, IndexType>>> {
55 friend class EnablePolymorphicObject<Sellp, LinOp>;
56 friend class Dense<ValueType>;
57 friend class Csr<ValueType, IndexType>;
58 friend class Sellp<to_complex<ValueType>, IndexType>;
59
60public:
61 using EnableLinOp<Sellp>::convert_to;
62 using EnableLinOp<Sellp>::move_to;
63 using ConvertibleTo<
64 Sellp<next_precision<ValueType>, IndexType>>::convert_to;
65 using ConvertibleTo<Sellp<next_precision<ValueType>, IndexType>>::move_to;
66 using ConvertibleTo<Dense<ValueType>>::convert_to;
67 using ConvertibleTo<Dense<ValueType>>::move_to;
70 using ReadableFromMatrixData<ValueType, IndexType>::read;
71
72 using value_type = ValueType;
73 using index_type = IndexType;
76 using absolute_type = remove_complex<Sellp>;
77
78 friend class Sellp<previous_precision<ValueType>, IndexType>;
79
80 void convert_to(
81 Sellp<next_precision<ValueType>, IndexType>* result) const override;
82
83 void move_to(Sellp<next_precision<ValueType>, IndexType>* result) override;
84
85#if GINKGO_ENABLE_HALF
86 friend class Sellp<previous_precision<previous_precision<ValueType>>,
87 IndexType>;
89 IndexType>>::convert_to;
90 using ConvertibleTo<
92
93 void convert_to(Sellp<next_precision<next_precision<ValueType>>, IndexType>*
94 result) const override;
95
96 void move_to(Sellp<next_precision<next_precision<ValueType>>, IndexType>*
97 result) override;
98#endif
99
100 void convert_to(Dense<ValueType>* other) const override;
101
102 void move_to(Dense<ValueType>* other) override;
103
104 void convert_to(Csr<ValueType, IndexType>* other) const override;
105
106 void move_to(Csr<ValueType, IndexType>* other) override;
107
108 void read(const mat_data& data) override;
109
110 void read(const device_mat_data& data) override;
111
112 void read(device_mat_data&& data) override;
113
114 void write(mat_data& data) const override;
115
116 std::unique_ptr<Diagonal<ValueType>> extract_diagonal() const override;
117
118 std::unique_ptr<absolute_type> compute_absolute() const override;
119
121
127 value_type* get_values() noexcept { return values_.get_data(); }
128
136 const value_type* get_const_values() const noexcept
137 {
138 return values_.get_const_data();
139 }
140
146 index_type* get_col_idxs() noexcept { return col_idxs_.get_data(); }
147
155 const index_type* get_const_col_idxs() const noexcept
156 {
157 return col_idxs_.get_const_data();
158 }
159
166 {
167 return slice_lengths_.get_data();
168 }
169
177 const size_type* get_const_slice_lengths() const noexcept
178 {
179 return slice_lengths_.get_const_data();
180 }
181
187 size_type* get_slice_sets() noexcept { return slice_sets_.get_data(); }
188
196 const size_type* get_const_slice_sets() const noexcept
197 {
198 return slice_sets_.get_const_data();
199 }
200
206 size_type get_slice_size() const noexcept { return slice_size_; }
207
213 size_type get_stride_factor() const noexcept { return stride_factor_; }
214
220 size_type get_total_cols() const noexcept
221 {
222 return values_.get_size() / slice_size_;
223 }
224
231 {
232 return values_.get_size();
233 }
234
247 value_type& val_at(size_type row, size_type slice_set,
248 size_type idx) noexcept
249 {
250 return values_.get_data()[this->linearize_index(row, slice_set, idx)];
251 }
252
256 value_type val_at(size_type row, size_type slice_set,
257 size_type idx) const noexcept
258 {
259 return values_
260 .get_const_data()[this->linearize_index(row, slice_set, idx)];
261 }
262
275 index_type& col_at(size_type row, size_type slice_set,
276 size_type idx) noexcept
277 {
278 return this->get_col_idxs()[this->linearize_index(row, slice_set, idx)];
279 }
280
284 index_type col_at(size_type row, size_type slice_set,
285 size_type idx) const noexcept
286 {
287 return this
288 ->get_const_col_idxs()[this->linearize_index(row, slice_set, idx)];
289 }
290
301 static std::unique_ptr<Sellp> create(std::shared_ptr<const Executor> exec,
302 const dim<2>& size = {},
303 size_type total_cols = 0);
304
317 static std::unique_ptr<Sellp> create(std::shared_ptr<const Executor> exec,
318 const dim<2>& size,
319 size_type slice_size,
320 size_type stride_factor,
321 size_type total_cols);
322
328
335
340 Sellp(const Sellp&);
341
348
349protected:
350 Sellp(std::shared_ptr<const Executor> exec, const dim<2>& size = {},
351 size_type total_cols = {});
352
353 Sellp(std::shared_ptr<const Executor> exec, const dim<2>& size,
354 size_type slice_size, size_type stride_factor, size_type total_cols);
355
356 void apply_impl(const LinOp* b, LinOp* x) const override;
357
358 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
359 LinOp* x) const override;
360
361 size_type linearize_index(size_type row, size_type slice_set,
362 size_type col) const noexcept
363 {
364 return (slice_set + col) * slice_size_ + row;
365 }
366
367private:
368 array<value_type> values_;
369 array<index_type> col_idxs_;
370 array<size_type> slice_lengths_;
371 array<size_type> slice_sets_;
372 size_type slice_size_;
373 size_type stride_factor_;
374};
375
376
377} // namespace matrix
378} // namespace gko
379
380
381#endif // GKO_PUBLIC_CORE_MATRIX_SELLP_HPP_
Definition polymorphic_object.hpp:479
Definition lin_op.hpp:742
Definition lin_op.hpp:793
Definition lin_op.hpp:878
Definition polymorphic_object.hpp:668
Definition lin_op.hpp:117
Definition lin_op.hpp:605
Definition lin_op.hpp:660
value_type * get_data() noexcept
Definition array.hpp:673
const value_type * get_const_data() const noexcept
Definition array.hpp:682
size_type get_size() const noexcept
Definition array.hpp:656
Definition device_matrix_data.hpp:36
Definition csr.hpp:123
Definition dense.hpp:116
Definition sellp.hpp:54
size_type get_slice_size() const noexcept
Definition sellp.hpp:206
void read(const device_mat_data &data) override
value_type & val_at(size_type row, size_type slice_set, size_type idx) noexcept
Definition sellp.hpp:247
static std::unique_ptr< Sellp > create(std::shared_ptr< const Executor > exec, const dim< 2 > &size, size_type slice_size, size_type stride_factor, size_type total_cols)
index_type & col_at(size_type row, size_type slice_set, size_type idx) noexcept
Definition sellp.hpp:275
Sellp(const Sellp &)
std::unique_ptr< absolute_type > compute_absolute() const override
void read(const mat_data &data) override
value_type * get_values() noexcept
Definition sellp.hpp:127
void read(device_mat_data &&data) override
Sellp & operator=(Sellp &&)
size_type get_stride_factor() const noexcept
Definition sellp.hpp:213
const size_type * get_const_slice_sets() const noexcept
Definition sellp.hpp:196
index_type * get_col_idxs() noexcept
Definition sellp.hpp:146
size_type get_total_cols() const noexcept
Definition sellp.hpp:220
index_type col_at(size_type row, size_type slice_set, size_type idx) const noexcept
Definition sellp.hpp:284
size_type * get_slice_lengths() noexcept
Definition sellp.hpp:165
Sellp & operator=(const Sellp &)
void compute_absolute_inplace() override
static std::unique_ptr< Sellp > create(std::shared_ptr< const Executor > exec, const dim< 2 > &size={}, size_type total_cols=0)
size_type * get_slice_sets() noexcept
Definition sellp.hpp:187
size_type get_num_stored_elements() const noexcept
Definition sellp.hpp:230
void write(mat_data &data) const override
value_type val_at(size_type row, size_type slice_set, size_type idx) const noexcept
Definition sellp.hpp:256
const index_type * get_const_col_idxs() const noexcept
Definition sellp.hpp:155
std::unique_ptr< Diagonal< ValueType > > extract_diagonal() const override
const size_type * get_const_slice_lengths() const noexcept
Definition sellp.hpp:177
const value_type * get_const_values() const noexcept
Definition sellp.hpp:136
The Ginkgo namespace.
Definition abstract_factory.hpp:20
typename detail::next_precision_impl< T >::type next_precision
Definition math.hpp:438
std::size_t size_type
Definition types.hpp:89
typename detail::to_complex_s< T >::type to_complex
Definition math.hpp:279
typename detail::remove_complex_s< T >::type remove_complex
Definition math.hpp:260
Definition dim.hpp:26
Definition matrix_data.hpp:126