ginkgo/core/matrix/fbcsr.hpp Source File

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

Reference API: ginkgo/core/matrix/fbcsr.hpp Source File
Reference API
fbcsr.hpp
1// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_MATRIX_FBCSR_HPP_
6#define GKO_PUBLIC_CORE_MATRIX_FBCSR_HPP_
7
8
9#include <ginkgo/core/base/array.hpp>
10#include <ginkgo/core/base/lin_op.hpp>
11#include <ginkgo/core/base/math.hpp>
12
13
14namespace gko {
15namespace matrix {
16
17
18template <typename ValueType>
19class Dense;
20
21template <typename ValueType, typename IndexType>
22class Csr;
23
24template <typename ValueType, typename IndexType>
25class SparsityCsr;
26
27template <typename ValueType, typename IndexType>
28class Fbcsr;
29
30template <typename ValueType, typename IndexType>
32
33
34namespace detail {
35
36
47template <typename IndexType>
48inline IndexType get_num_blocks(const int block_size, const IndexType size)
49{
50 GKO_ASSERT_BLOCK_SIZE_CONFORMANT(size, block_size);
51 return size / block_size;
52}
53
54
55} // namespace detail
56
57
97template <typename ValueType = default_precision, typename IndexType = int32>
98class Fbcsr : public EnableLinOp<Fbcsr<ValueType, IndexType>>,
99 public ConvertibleTo<Fbcsr<next_precision<ValueType>, IndexType>>,
100#if GINKGO_ENABLE_HALF
101 public ConvertibleTo<
102 Fbcsr<next_precision<next_precision<ValueType>>, IndexType>>,
103#endif
104 public ConvertibleTo<Dense<ValueType>>,
105 public ConvertibleTo<Csr<ValueType, IndexType>>,
106 public ConvertibleTo<SparsityCsr<ValueType, IndexType>>,
107 public DiagonalExtractable<ValueType>,
108 public ReadableFromMatrixData<ValueType, IndexType>,
109 public WritableToMatrixData<ValueType, IndexType>,
110 public Transposable,
112 remove_complex<Fbcsr<ValueType, IndexType>>> {
113 friend class EnablePolymorphicObject<Fbcsr, LinOp>;
114 friend class Csr<ValueType, IndexType>;
115 friend class Dense<ValueType>;
116 friend class SparsityCsr<ValueType, IndexType>;
117 friend class FbcsrBuilder<ValueType, IndexType>;
118 friend class Fbcsr<to_complex<ValueType>, IndexType>;
119
120public:
121 using value_type = ValueType;
122 using index_type = IndexType;
126 using absolute_type = remove_complex<Fbcsr>;
127
134
139 using EnableLinOp<Fbcsr<ValueType, IndexType>>::convert_to;
140
141 using ConvertibleTo<
142 Fbcsr<next_precision<ValueType>, IndexType>>::convert_to;
143 using ConvertibleTo<Fbcsr<next_precision<ValueType>, IndexType>>::move_to;
144 using ConvertibleTo<Dense<ValueType>>::convert_to;
145 using ConvertibleTo<Dense<ValueType>>::move_to;
146 using ConvertibleTo<Csr<ValueType, IndexType>>::convert_to;
150
151 friend class Fbcsr<previous_precision<ValueType>, IndexType>;
152
153 void convert_to(
154 Fbcsr<next_precision<ValueType>, IndexType>* result) const override;
155
156 void move_to(Fbcsr<next_precision<ValueType>, IndexType>* result) override;
157
158#if GINKGO_ENABLE_HALF
159 friend class Fbcsr<previous_precision<previous_precision<ValueType>>,
160 IndexType>;
162 IndexType>>::convert_to;
163 using ConvertibleTo<
165
166 void convert_to(Fbcsr<next_precision<next_precision<ValueType>>, IndexType>*
167 result) const override;
168
169 void move_to(Fbcsr<next_precision<next_precision<ValueType>>, IndexType>*
170 result) override;
171#endif
172
173 void convert_to(Dense<ValueType>* other) const override;
174
175 void move_to(Dense<ValueType>* other) override;
176
183 void convert_to(Csr<ValueType, IndexType>* result) const override;
184
185 void move_to(Csr<ValueType, IndexType>* result) override;
186
193 void convert_to(SparsityCsr<ValueType, IndexType>* result) const override;
194
195 void move_to(SparsityCsr<ValueType, IndexType>* result) override;
196
203 void read(const mat_data& data) override;
204
205 void read(const device_mat_data& data) override;
206
207 void read(device_mat_data&& data) override;
208
209 void write(mat_data& data) const override;
210
211 std::unique_ptr<LinOp> transpose() const override;
212
213 std::unique_ptr<LinOp> conj_transpose() const override;
214
215 std::unique_ptr<Diagonal<ValueType>> extract_diagonal() const override;
216
217 std::unique_ptr<absolute_type> compute_absolute() const override;
218
220
226
234
238 value_type* get_values() noexcept { return values_.get_data(); }
239
247 const value_type* get_const_values() const noexcept
248 {
249 return values_.get_const_data();
250 }
251
255 index_type* get_col_idxs() noexcept { return col_idxs_.get_data(); }
256
264 const index_type* get_const_col_idxs() const noexcept
265 {
266 return col_idxs_.get_const_data();
267 }
268
272 index_type* get_row_ptrs() noexcept { return row_ptrs_.get_data(); }
273
281 const index_type* get_const_row_ptrs() const noexcept
282 {
283 return row_ptrs_.get_const_data();
284 }
285
290 {
291 return values_.get_size();
292 }
293
298 {
299 return col_idxs_.get_size();
300 }
301
305 int get_block_size() const noexcept { return bs_; }
306
310 index_type get_num_block_rows() const noexcept
311 {
312 return this->get_size()[0] / bs_;
313 }
314
318 index_type get_num_block_cols() const noexcept
319 {
320 return this->get_size()[1] / bs_;
321 }
322
332 static std::unique_ptr<Fbcsr> create(std::shared_ptr<const Executor> exec,
333 int block_size = 1);
334
346 static std::unique_ptr<Fbcsr> create(std::shared_ptr<const Executor> exec,
347 const dim<2>& size,
348 size_type num_nonzeros,
349 int block_size);
350
371 static std::unique_ptr<Fbcsr> create(std::shared_ptr<const Executor> exec,
372 const dim<2>& size, int block_size,
373 array<value_type> values,
374 array<index_type> col_idxs,
375 array<index_type> row_ptrs);
376
382 template <typename InputValueType, typename InputColumnIndexType,
383 typename InputRowPtrType>
384 GKO_DEPRECATED(
385 "explicitly construct the gko::array argument instead of passing "
386 "initializer lists")
387 static std::unique_ptr<Fbcsr> create(
388 std::shared_ptr<const Executor> exec, const dim<2>& size,
389 int block_size, std::initializer_list<InputValueType> values,
390 std::initializer_list<InputColumnIndexType> col_idxs,
391 std::initializer_list<InputRowPtrType> row_ptrs)
392 {
393 return create(exec, size, block_size,
394 array<value_type>{exec, std::move(values)},
395 array<index_type>{exec, std::move(col_idxs)},
396 array<index_type>{exec, std::move(row_ptrs)});
397 }
398
413 static std::unique_ptr<const Fbcsr> create_const(
414 std::shared_ptr<const Executor> exec, const dim<2>& size, int blocksize,
415 gko::detail::const_array_view<ValueType>&& values,
416 gko::detail::const_array_view<IndexType>&& col_idxs,
417 gko::detail::const_array_view<IndexType>&& row_ptrs);
418
424
431
435 Fbcsr(const Fbcsr&);
436
443
444protected:
445 Fbcsr(std::shared_ptr<const Executor> exec, int block_size = 1);
446
447 Fbcsr(std::shared_ptr<const Executor> exec, const dim<2>& size,
448 size_type num_nonzeros, int block_size);
449
450 Fbcsr(std::shared_ptr<const Executor> exec, const dim<2>& size,
451 int block_size, array<value_type> values, array<index_type> col_idxs,
452 array<index_type> row_ptrs);
453
454 void apply_impl(const LinOp* b, LinOp* x) const override;
455
456 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
457 LinOp* x) const override;
458
459private:
460 int bs_;
461 array<value_type> values_;
462 array<index_type> col_idxs_;
463 array<index_type> row_ptrs_;
464};
465
466
467} // namespace matrix
468} // namespace gko
469
470
471#endif // GKO_PUBLIC_CORE_MATRIX_FBCSR_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 executor.hpp:615
Definition lin_op.hpp:117
Definition lin_op.hpp:605
Definition lin_op.hpp:433
Definition lin_op.hpp:660
Definition array.hpp:166
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 fbcsr.hpp:31
Fixed-block compressed sparse row storage matrix format.
Definition fbcsr.hpp:112
void read(device_mat_data &&data) override
size_type get_num_stored_blocks() const noexcept
Definition fbcsr.hpp:297
std::unique_ptr< LinOp > transpose() const override
void read(const device_mat_data &data) override
size_type get_num_stored_elements() const noexcept
Definition fbcsr.hpp:289
const value_type * get_const_values() const noexcept
Definition fbcsr.hpp:247
const index_type * get_const_col_idxs() const noexcept
Definition fbcsr.hpp:264
index_type get_num_block_rows() const noexcept
Definition fbcsr.hpp:310
index_type * get_row_ptrs() noexcept
Definition fbcsr.hpp:272
int get_block_size() const noexcept
Definition fbcsr.hpp:305
index_type * get_col_idxs() noexcept
Definition fbcsr.hpp:255
static std::unique_ptr< Fbcsr > create(std::shared_ptr< const Executor > exec, int block_size=1)
Fbcsr(const Fbcsr &)
void write(mat_data &data) const override
static std::unique_ptr< const Fbcsr > create_const(std::shared_ptr< const Executor > exec, const dim< 2 > &size, int blocksize, gko::detail::const_array_view< ValueType > &&values, gko::detail::const_array_view< IndexType > &&col_idxs, gko::detail::const_array_view< IndexType > &&row_ptrs)
void compute_absolute_inplace() override
static std::unique_ptr< Fbcsr > create(std::shared_ptr< const Executor > exec, const dim< 2 > &size, size_type num_nonzeros, int block_size)
void sort_by_column_index()
value_type * get_values() noexcept
Definition fbcsr.hpp:238
std::unique_ptr< LinOp > conj_transpose() const override
Fbcsr & operator=(Fbcsr &&)
std::unique_ptr< absolute_type > compute_absolute() const override
std::unique_ptr< Diagonal< ValueType > > extract_diagonal() const override
const index_type * get_const_row_ptrs() const noexcept
Definition fbcsr.hpp:281
Fbcsr & operator=(const Fbcsr &)
void convert_to(Csr< ValueType, IndexType > *result) const override
static std::unique_ptr< Fbcsr > create(std::shared_ptr< const Executor > exec, const dim< 2 > &size, int block_size, array< value_type > values, array< index_type > col_idxs, array< index_type > row_ptrs)
void read(const mat_data &data) override
bool is_sorted_by_column_index() const
index_type get_num_block_cols() const noexcept
Definition fbcsr.hpp:318
void convert_to(SparsityCsr< ValueType, IndexType > *result) const override
Definition sparsity_csr.hpp:55
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
STL namespace.
Definition dim.hpp:26
Definition matrix_data.hpp:126