 |
Ginkgo
Generated from pipelines/2662685947 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
|
5 #ifndef GKO_PUBLIC_CORE_PRECONDITIONER_JACOBI_HPP_
6 #define GKO_PUBLIC_CORE_PRECONDITIONER_JACOBI_HPP_
9 #include <ginkgo/core/base/array.hpp>
10 #include <ginkgo/core/base/lin_op.hpp>
11 #include <ginkgo/core/config/config.hpp>
12 #include <ginkgo/core/config/registry.hpp>
13 #include <ginkgo/core/matrix/csr.hpp>
14 #include <ginkgo/core/matrix/dense.hpp>
15 #include <ginkgo/core/matrix/diagonal.hpp>
24 namespace preconditioner {
36 template <
typename IndexType>
125 GKO_ATTRIBUTES IndexType
186 template <
typename ValueType = default_precision,
typename IndexType =
int32>
193 GKO_ASSERT_SUPPORTED_VALUE_AND_INDEX_TYPE;
198 using value_type = ValueType;
199 using index_type = IndexType;
224 return storage_scheme_;
271 void write(mat_data& data)
const override;
273 std::unique_ptr<LinOp>
transpose()
const override;
389 struct storage_optimization_type {
391 : is_block_wise{
false}, of_all_blocks{p}
394 storage_optimization_type(
396 : is_block_wise{block_wise_opt.
get_size() > 0},
397 block_wise{block_wise_opt}
400 storage_optimization_type(
401 array<precision_reduction>&& block_wise_opt)
402 : is_block_wise{block_wise_opt.
get_size() > 0},
403 block_wise{std::move(block_wise_opt)}
406 operator precision_reduction() {
return of_all_blocks; }
409 precision_reduction of_all_blocks;
532 static parameters_type
parse(
535 config::make_type_descriptor<ValueType, IndexType>());
543 explicit Jacobi(std::shared_ptr<const Executor> exec)
544 :
LinOp(exec), num_blocks_{}, blocks_(exec), conditioning_(exec)
557 explicit Jacobi(
const Factory* factory,
558 std::shared_ptr<const LinOp> system_matrix)
561 parameters_{factory->get_parameters()},
562 storage_scheme_{this->compute_storage_scheme(
565 blocks_(
factory->get_executor(),
566 storage_scheme_.compute_storage_space(
567 parameters_.block_pointers.get_size() - 1)),
568 conditioning_(
factory->get_executor())
573 this->generate(system_matrix.get(), parameters_.
skip_sorting);
584 block_interleaved_storage_scheme<index_type> compute_storage_scheme(
587 uint32 default_block_stride = 32;
589 if (
auto hip_exec = std::dynamic_pointer_cast<const gko::HipExecutor>(
591 default_block_stride = hip_exec->get_warp_size();
593 uint32 max_block_stride = default_block_stride;
594 if (param_max_block_stride != 0) {
597 max_block_stride = param_max_block_stride;
599 max_block_stride != default_block_stride) {
601 GKO_NOT_SUPPORTED(
this);
606 GKO_NOT_SUPPORTED(
this);
608 const auto group_size = static_cast<uint32>(
610 const auto block_offset = max_block_size;
611 const auto block_stride = group_size * block_offset;
612 const auto group_offset = max_block_size * block_stride;
613 return {static_cast<index_type>(block_offset),
614 static_cast<index_type>(group_offset),
627 void generate(
const LinOp* system_matrix,
bool skip_sorting);
636 void detect_blocks(
const matrix::Csr<ValueType, IndexType>* system_matrix);
638 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
641 LinOp* x)
const override;
644 block_interleaved_storage_scheme<index_type> storage_scheme_{};
646 array<value_type> blocks_;
647 array<remove_complex<value_type>> conditioning_;
655 #endif // GKO_PUBLIC_CORE_PRECONDITIONER_JACOBI_HPP_
Definition: jacobi.hpp:513
static parameters_type parse(const config::pnode &config, const config::registry &context, const config::type_descriptor &td_for_child=config::make_type_descriptor< ValueType, IndexType >())
Create the parameters from the property_tree.
void set_executor(std::shared_ptr< const Executor > exec)
Changes the Executor of the array, moving the allocated data to the new Executor.
Definition: array.hpp:714
This class is used to encode storage precisions of low precision algorithms.
Definition: types.hpp:239
IndexType block_offset
The offset between consecutive blocks within the group.
Definition: jacobi.hpp:50
bool skip_sorting
true means it is known that the matrix given to this factory will be sorted first by row,...
Definition: jacobi.hpp:343
pnode describes a tree of properties.
Definition: property_tree.hpp:28
Definition: lin_op.hpp:117
IndexType get_group_offset(IndexType block_id) const noexcept
Returns the offset of the group belonging to the block with the given ID.
Definition: jacobi.hpp:101
IndexType get_group_size() const noexcept
Returns the number of elements in the group.
Definition: jacobi.hpp:69
size_type get_num_blocks() const noexcept
Returns the number of blocks of the operator.
Definition: jacobi.hpp:211
Linear operators which support transposition should implement the Transposable interface.
Definition: lin_op.hpp:392
constexpr uint32 get_significant_bit(const T &n, uint32 hint=0u) noexcept
Returns the position of the most significant bit of the number.
Definition: math.hpp:1057
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:90
IndexType get_stride() const noexcept
Returns the stride between columns of the block.
Definition: jacobi.hpp:137
#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default)
Creates a scalar factory parameter in the factory parameters structure.
Definition: abstract_factory.hpp:437
void move_to(matrix::Dense< value_type > *result) override
Converts the implementer to an object of type result_type by moving data from this object.
This class describes the value and index types to be used when building a Ginkgo type from a configur...
Definition: type_descriptor.hpp:39
uint32 max_block_stride
Stride between two columns of a block (as number of elements).
Definition: jacobi.hpp:324
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
IndexType group_offset
The offset between two block groups.
Definition: jacobi.hpp:55
constexpr T get_superior_power(const T &base, const T &limit, const T &hint=T{1}) noexcept
Returns the smallest power of base not smaller than limit.
Definition: math.hpp:1075
void convert_to(matrix::Dense< value_type > *result) const override
Converts the implementer to an object of type result_type.
A block-Jacobi preconditioner is a block-diagonal linear operator, obtained by inverting the diagonal...
Definition: jacobi.hpp:187
uint32 group_power
Then base 2 power of the group.
Definition: jacobi.hpp:62
std::uint32_t uint32
32-bit unsigned integral type.
Definition: types.hpp:130
This structure is used as an intermediate data type to store a sparse matrix.
Definition: matrix_data.hpp:126
Jacobi & operator=(const Jacobi &other)
Copy-assigns a Jacobi preconditioner.
#define GKO_ENABLE_LIN_OP_FACTORY(_lin_op, _parameters_name, _factory_name)
This macro will generate a default implementation of a LinOpFactory for the LinOp subclass it is defi...
Definition: lin_op.hpp:900
gko::array< index_type > block_pointers
Starting (row / column) indexes of individual blocks.
Definition: jacobi.hpp:371
const remove_complex< value_type > * get_conditioning() const noexcept
Returns an array of 1-norm condition numbers of the blocks.
Definition: jacobi.hpp:252
void write(mat_data &data) const override
Writes a matrix to a matrix_data structure.
const value_type * get_blocks() const noexcept
Returns the pointer to the memory used for storing the block data.
Definition: jacobi.hpp:238
IndexType get_global_block_offset(IndexType block_id) const noexcept
Returns the offset of the block with the given ID.
Definition: jacobi.hpp:126
A LinOp implementing this interface can write its data to a matrix_data structure.
Definition: lin_op.hpp:619
size_type get_num_stored_elements() const noexcept
Returns the number of elements explicitly stored in the matrix.
Definition: jacobi.hpp:262
storage_optimization_type storage_optimization
The precisions to use for the blocks of the matrix.
Definition: jacobi.hpp:482
Defines the parameters of the interleaved block storage scheme used by block-Jacobi blocks.
Definition: jacobi.hpp:37
This mixin is used to enable a default Cloneable::clone() implementation and similar for objects that...
Definition: polymorphic_object.hpp:369
uint32 max_block_size
Maximal size of diagonal blocks.
Definition: jacobi.hpp:313
ConvertibleTo interface is used to mark that the implementer can be converted to the object of Result...
Definition: polymorphic_object.hpp:140
Jacobi(const Jacobi &other)
Copy-constructs a Jacobi preconditioner.
std::unique_ptr< LinOp > transpose() const override
Returns a LinOp representing the transpose of the Transposable object.
This class stores additional context for creating Ginkgo objects from configuration files.
Definition: registry.hpp:167
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
#define GKO_ENABLE_BUILD_METHOD(_factory_name)
Defines a build method for the factory, simplifying its construction by removing the repetitive typin...
Definition: abstract_factory.hpp:386
const block_interleaved_storage_scheme< index_type > & get_storage_scheme() const noexcept
Returns the storage scheme used for storing Jacobi blocks.
Definition: jacobi.hpp:221
#define GKO_CREATE_FACTORY_PARAMETERS(_parameters_name, _factory_name)
This Macro will generate a new type containing the parameters for the factory _factory_name.
Definition: abstract_factory.hpp:272
const value_type * get_const_data() const noexcept
Returns a constant pointer to the block of memory used to store the elements of the array.
Definition: array.hpp:696
#define GKO_FACTORY_PARAMETER_VECTOR(_name,...)
Creates a vector factory parameter in the factory parameters structure.
Definition: abstract_factory.hpp:453
constexpr int64 ceildiv(int64 num, int64 den)
Performs integer division with rounding up.
Definition: math.hpp:614
size_type compute_storage_space(size_type num_blocks) const noexcept
Computes the storage space required for the requested number of blocks.
Definition: jacobi.hpp:87
std::shared_ptr< const Executor > get_executor() const noexcept
Returns the Executor of the object.
Definition: polymorphic_object.hpp:62
size_type get_size() const noexcept
Returns the number of elements in the array.
Definition: array.hpp:670
const dim< 2 > & get_size() const noexcept
Returns the size of the operator.
Definition: lin_op.hpp:169
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:264
LinOp(const LinOp &)=default
Copy-constructs a LinOp.
IndexType get_block_offset(IndexType block_id) const noexcept
Returns the offset of the block with the given ID within its group.
Definition: jacobi.hpp:113