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>
45 template <
typename ValueType,
typename IndexType>
59 template <
typename Builder,
typename ValueType,
typename IndexType,
61 struct is_matrix_type_builder : std::false_type {};
64 template <
typename Builder,
typename ValueType,
typename IndexType>
65 struct is_matrix_type_builder<
66 Builder, ValueType, IndexType,
68 decltype(std::declval<Builder>().template create<ValueType, IndexType>(
69 std::declval<std::shared_ptr<const Executor>>()))>>
73 template <
template <
typename,
typename>
class MatrixType,
74 typename... CreateArgs>
75 struct MatrixTypeBuilderFromValueAndIndex {
76 template <
typename ValueType,
typename IndexType, std::size_t... I>
77 auto create_impl(std::shared_ptr<const Executor> exec,
78 std::index_sequence<I...>)
80 return MatrixType<ValueType, IndexType>::create(
81 exec, std::get<I>(create_args)...);
85 template <
typename ValueType,
typename IndexType>
86 auto create(std::shared_ptr<const Executor> exec)
89 static constexpr
auto size =
sizeof...(CreateArgs);
90 return create_impl<ValueType, IndexType>(
91 std::move(exec), std::make_index_sequence<size>{});
94 std::tuple<CreateArgs...> create_args;
132 template <
template <
typename,
typename>
class MatrixType,
typename... Args>
135 return detail::MatrixTypeBuilderFromValueAndIndex<MatrixType, Args...>{
136 std::forward_as_tuple(create_args...)};
140 namespace experimental {
141 namespace distributed {
156 template <
typename LocalIndexType,
typename GlobalIndexType>
158 template <
typename ValueType>
267 typename LocalIndexType =
int32,
typename GlobalIndexType =
int64>
271 Matrix<ValueType, LocalIndexType, GlobalIndexType>>,
273 Matrix<next_precision<ValueType>, LocalIndexType, GlobalIndexType>>,
274 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
275 public ConvertibleTo<Matrix<next_precision<ValueType, 2>, LocalIndexType,
278 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
279 public ConvertibleTo<Matrix<next_precision<ValueType, 3>, LocalIndexType,
291 GKO_ASSERT_SUPPORTED_VALUE_AND_DIST_INDEX_TYPE;
294 using value_type = ValueType;
295 using index_type = GlobalIndexType;
296 using local_index_type = LocalIndexType;
297 using global_index_type = GlobalIndexType;
305 GlobalIndexType>>::convert_to;
307 GlobalIndexType>>::move_to;
310 global_index_type>* result)
const override;
313 global_index_type>* result)
override;
315 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
319 global_index_type>>::convert_to;
321 global_index_type>>::move_to;
324 global_index_type>* result)
const override;
327 global_index_type>* result)
override;
330 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
334 global_index_type>>::convert_to;
336 global_index_type>>::move_to;
339 global_index_type>* result)
const override;
342 global_index_type>* result)
override;
458 return off_diag_mtx_;
474 return row_gatherer_;
480 GKO_DEPRECATED(
"use get_diag_matrix() instead")
489 GKO_DEPRECATED(
"use get_off_diag_matrix() instead")
500 std::shared_ptr<const Partition<local_index_type, global_index_type>>
580 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
596 static std::unique_ptr<Matrix>
create(
597 std::shared_ptr<const Executor> exec,
599 row_gatherer_template);
621 template <
typename MatrixType,
622 typename = std::enable_if_t<gko::detail::is_matrix_type_builder<
623 MatrixType, ValueType, LocalIndexType>::value>>
624 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
626 MatrixType matrix_template)
630 matrix_template.template create<ValueType, LocalIndexType>(exec));
662 template <
typename DiagMatrixType,
typename OffDiagMatrixType,
663 typename = std::enable_if_t<
664 gko::detail::is_matrix_type_builder<DiagMatrixType, ValueType,
665 LocalIndexType>::value &&
666 gko::detail::is_matrix_type_builder<
667 OffDiagMatrixType, ValueType, LocalIndexType>::value>>
670 DiagMatrixType diag_matrix_template,
671 OffDiagMatrixType off_diag_matrix_template)
675 diag_matrix_template.template create<ValueType, LocalIndexType>(
677 off_diag_matrix_template.template create<ValueType, LocalIndexType>(
695 static std::unique_ptr<Matrix>
create(
715 static std::unique_ptr<Matrix>
create(
732 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
734 std::shared_ptr<LinOp> diag_linop);
755 "Please use the overload with an index_map instead.")]]
static std::
758 dim<2> size, std::shared_ptr<LinOp> diag_linop,
759 std::shared_ptr<LinOp> off_diag_linop,
760 std::vector<comm_index_type> recv_sizes,
761 std::vector<comm_index_type> recv_offsets,
777 static std::unique_ptr<Matrix>
create(
780 std::shared_ptr<LinOp> diag_linop,
781 std::shared_ptr<LinOp> off_diag_linop);
802 explicit Matrix(std::shared_ptr<const Executor> exec,
805 explicit Matrix(std::shared_ptr<const Executor> exec,
807 row_gatherer_template,
811 explicit Matrix(std::shared_ptr<const Executor> exec,
813 std::shared_ptr<LinOp> diag_linop);
815 explicit Matrix(std::shared_ptr<const Executor> exec,
818 std::shared_ptr<LinOp> diag_linop,
819 std::shared_ptr<LinOp> off_diag_linop);
821 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
824 LinOp* x)
const override;
827 std::shared_ptr<RowGatherer<LocalIndexType>> row_gatherer_;
829 std::shared_ptr<const Partition<local_index_type, global_index_type>>
831 gko::detail::ScalarCache one_scalar_;
832 detail::GenericVectorCache recv_buffer_;
833 detail::GenericVectorCache host_recv_buffer_;
834 std::shared_ptr<LinOp> diag_mtx_;
835 std::shared_ptr<LinOp> off_diag_mtx_;
847 #endif // GKO_PUBLIC_CORE_DISTRIBUTED_MATRIX_HPP_