5 #ifndef GKO_PUBLIC_CORE_DISTRIBUTED_MATRIX_HPP_
6 #define GKO_PUBLIC_CORE_DISTRIBUTED_MATRIX_HPP_
9 #include <ginkgo/config.hpp>
15 #include <ginkgo/core/base/dense_cache.hpp>
16 #include <ginkgo/core/base/lin_op.hpp>
17 #include <ginkgo/core/base/mpi.hpp>
18 #include <ginkgo/core/base/std_extensions.hpp>
19 #include <ginkgo/core/distributed/base.hpp>
20 #include <ginkgo/core/distributed/index_map.hpp>
21 #include <ginkgo/core/distributed/row_gatherer.hpp>
22 #include <ginkgo/core/distributed/vector_cache.hpp>
29 template <
typename ValueType,
typename IndexType>
39 template <
typename ValueType,
typename IndexType>
42 template <
typename ValueType,
typename IndexType>
56 template <
typename Builder,
typename ValueType,
typename IndexType,
58 struct is_matrix_type_builder : std::false_type {};
61 template <
typename Builder,
typename ValueType,
typename IndexType>
62 struct is_matrix_type_builder<
63 Builder, ValueType, IndexType,
65 decltype(std::declval<Builder>().template create<ValueType, IndexType>(
66 std::declval<std::shared_ptr<const Executor>>()))>>
70 template <
template <
typename,
typename>
class MatrixType,
71 typename... CreateArgs>
72 struct MatrixTypeBuilderFromValueAndIndex {
73 template <
typename ValueType,
typename IndexType, std::size_t... I>
74 auto create_impl(std::shared_ptr<const Executor> exec,
75 std::index_sequence<I...>)
77 return MatrixType<ValueType, IndexType>::create(
78 exec, std::get<I>(create_args)...);
82 template <
typename ValueType,
typename IndexType>
83 auto create(std::shared_ptr<const Executor> exec)
86 static constexpr
auto size =
sizeof...(CreateArgs);
87 return create_impl<ValueType, IndexType>(
88 std::move(exec), std::make_index_sequence<size>{});
91 std::tuple<CreateArgs...> create_args;
129 template <
template <
typename,
typename>
class MatrixType,
typename... Args>
132 return detail::MatrixTypeBuilderFromValueAndIndex<MatrixType, Args...>{
133 std::forward_as_tuple(create_args...)};
137 namespace experimental {
138 namespace distributed {
153 template <
typename LocalIndexType,
typename GlobalIndexType>
155 template <
typename ValueType>
264 typename LocalIndexType =
int32,
typename GlobalIndexType =
int64>
268 Matrix<ValueType, LocalIndexType, GlobalIndexType>>,
270 Matrix<next_precision<ValueType>, LocalIndexType, GlobalIndexType>>,
271 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
272 public ConvertibleTo<Matrix<next_precision<ValueType, 2>, LocalIndexType,
275 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
276 public ConvertibleTo<Matrix<next_precision<ValueType, 3>, LocalIndexType,
287 GKO_ASSERT_SUPPORTED_VALUE_AND_DIST_INDEX_TYPE;
290 using value_type = ValueType;
291 using index_type = GlobalIndexType;
292 using local_index_type = LocalIndexType;
293 using global_index_type = GlobalIndexType;
301 GlobalIndexType>>::convert_to;
303 GlobalIndexType>>::move_to;
306 global_index_type>* result)
const override;
309 global_index_type>* result)
override;
311 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
315 global_index_type>>::convert_to;
317 global_index_type>>::move_to;
320 global_index_type>* result)
const override;
323 global_index_type>* result)
override;
326 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
330 global_index_type>>::convert_to;
332 global_index_type>>::move_to;
335 global_index_type>* result)
const override;
338 global_index_type>* result)
override;
452 return off_diag_mtx_;
468 return row_gatherer_;
474 GKO_DEPRECATED(
"use get_diag_matrix() instead")
483 GKO_DEPRECATED(
"use get_off_diag_matrix() instead")
532 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
548 static std::unique_ptr<Matrix>
create(
549 std::shared_ptr<const Executor> exec,
551 row_gatherer_template);
573 template <
typename MatrixType,
574 typename = std::enable_if_t<gko::detail::is_matrix_type_builder<
575 MatrixType, ValueType, LocalIndexType>::value>>
576 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
578 MatrixType matrix_template)
582 matrix_template.template create<ValueType, LocalIndexType>(exec));
614 template <
typename DiagMatrixType,
typename OffDiagMatrixType,
615 typename = std::enable_if_t<
616 gko::detail::is_matrix_type_builder<DiagMatrixType, ValueType,
617 LocalIndexType>::value &&
618 gko::detail::is_matrix_type_builder<
619 OffDiagMatrixType, ValueType, LocalIndexType>::value>>
622 DiagMatrixType diag_matrix_template,
623 OffDiagMatrixType off_diag_matrix_template)
627 diag_matrix_template.template create<ValueType, LocalIndexType>(
629 off_diag_matrix_template.template create<ValueType, LocalIndexType>(
647 static std::unique_ptr<Matrix>
create(
667 static std::unique_ptr<Matrix>
create(
684 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
686 std::shared_ptr<LinOp> diag_linop);
707 "Please use the overload with an index_map instead.")]]
static std::
710 dim<2> size, std::shared_ptr<LinOp> diag_linop,
711 std::shared_ptr<LinOp> off_diag_linop,
712 std::vector<comm_index_type> recv_sizes,
713 std::vector<comm_index_type> recv_offsets,
729 static std::unique_ptr<Matrix>
create(
732 std::shared_ptr<LinOp> diag_linop,
733 std::shared_ptr<LinOp> off_diag_linop);
754 explicit Matrix(std::shared_ptr<const Executor> exec,
757 explicit Matrix(std::shared_ptr<const Executor> exec,
759 row_gatherer_template,
763 explicit Matrix(std::shared_ptr<const Executor> exec,
765 std::shared_ptr<LinOp> diag_linop);
767 explicit Matrix(std::shared_ptr<const Executor> exec,
770 std::shared_ptr<LinOp> diag_linop,
771 std::shared_ptr<LinOp> off_diag_linop);
773 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
776 LinOp* x)
const override;
779 std::shared_ptr<RowGatherer<LocalIndexType>> row_gatherer_;
781 gko::detail::ScalarCache one_scalar_;
782 detail::GenericVectorCache recv_buffer_;
783 detail::GenericVectorCache host_recv_buffer_;
784 std::shared_ptr<LinOp> diag_mtx_;
785 std::shared_ptr<LinOp> off_diag_mtx_;
797 #endif // GKO_PUBLIC_CORE_DISTRIBUTED_MATRIX_HPP_