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>
53 template <
typename Builder,
typename ValueType,
typename IndexType,
55 struct is_matrix_type_builder : std::false_type {};
58 template <
typename Builder,
typename ValueType,
typename IndexType>
59 struct is_matrix_type_builder<
60 Builder, ValueType, IndexType,
62 decltype(std::declval<Builder>().template create<ValueType, IndexType>(
63 std::declval<std::shared_ptr<const Executor>>()))>>
67 template <
template <
typename,
typename>
class MatrixType,
68 typename... CreateArgs>
69 struct MatrixTypeBuilderFromValueAndIndex {
70 template <
typename ValueType,
typename IndexType, std::size_t... I>
71 auto create_impl(std::shared_ptr<const Executor> exec,
72 std::index_sequence<I...>)
74 return MatrixType<ValueType, IndexType>::create(
75 exec, std::get<I>(create_args)...);
79 template <
typename ValueType,
typename IndexType>
80 auto create(std::shared_ptr<const Executor> exec)
83 static constexpr
auto size =
sizeof...(CreateArgs);
84 return create_impl<ValueType, IndexType>(
85 std::move(exec), std::make_index_sequence<size>{});
88 std::tuple<CreateArgs...> create_args;
126 template <
template <
typename,
typename>
class MatrixType,
typename... Args>
129 return detail::MatrixTypeBuilderFromValueAndIndex<MatrixType, Args...>{
130 std::forward_as_tuple(create_args...)};
134 namespace experimental {
135 namespace distributed {
150 template <
typename LocalIndexType,
typename GlobalIndexType>
152 template <
typename ValueType>
261 typename LocalIndexType =
int32,
typename GlobalIndexType =
int64>
265 Matrix<ValueType, LocalIndexType, GlobalIndexType>>,
267 Matrix<next_precision<ValueType>, LocalIndexType, GlobalIndexType>>,
268 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
269 public ConvertibleTo<Matrix<next_precision<ValueType, 2>, LocalIndexType,
272 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
273 public ConvertibleTo<Matrix<next_precision<ValueType, 3>, LocalIndexType,
283 GKO_ASSERT_SUPPORTED_VALUE_AND_DIST_INDEX_TYPE;
286 using value_type = ValueType;
287 using index_type = GlobalIndexType;
288 using local_index_type = LocalIndexType;
289 using global_index_type = GlobalIndexType;
297 GlobalIndexType>>::convert_to;
299 GlobalIndexType>>::move_to;
302 global_index_type>* result)
const override;
305 global_index_type>* result)
override;
307 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
311 global_index_type>>::convert_to;
313 global_index_type>>::move_to;
316 global_index_type>* result)
const override;
319 global_index_type>* result)
override;
322 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
326 global_index_type>>::convert_to;
328 global_index_type>>::move_to;
331 global_index_type>* result)
const override;
334 global_index_type>* result)
override;
448 return off_diag_mtx_;
454 GKO_DEPRECATED(
"use get_diag_matrix() instead")
463 GKO_DEPRECATED(
"use get_off_diag_matrix() instead")
512 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
528 static std::unique_ptr<Matrix>
create(
529 std::shared_ptr<const Executor> exec,
531 row_gatherer_template);
553 template <
typename MatrixType,
554 typename = std::enable_if_t<gko::detail::is_matrix_type_builder<
555 MatrixType, ValueType, LocalIndexType>::value>>
556 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
558 MatrixType matrix_template)
562 matrix_template.template create<ValueType, LocalIndexType>(exec));
593 template <
typename DiagMatrixType,
typename OffDiagMatrixType,
594 typename = std::enable_if_t<
595 gko::detail::is_matrix_type_builder<DiagMatrixType, ValueType,
596 LocalIndexType>::value &&
597 gko::detail::is_matrix_type_builder<
598 OffDiagMatrixType, ValueType, LocalIndexType>::value>>
601 DiagMatrixType diag_matrix_template,
602 OffDiagMatrixType off_diag_matrix_template)
606 diag_matrix_template.template create<ValueType, LocalIndexType>(
608 off_diag_matrix_template.template create<ValueType, LocalIndexType>(
626 static std::unique_ptr<Matrix>
create(
646 static std::unique_ptr<Matrix>
create(
663 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
665 std::shared_ptr<LinOp> diag_linop);
686 "Please use the overload with an index_map instead.")]]
static std::
689 dim<2> size, std::shared_ptr<LinOp> diag_linop,
690 std::shared_ptr<LinOp> off_diag_linop,
691 std::vector<comm_index_type> recv_sizes,
692 std::vector<comm_index_type> recv_offsets,
708 static std::unique_ptr<Matrix>
create(
711 std::shared_ptr<LinOp> diag_linop,
712 std::shared_ptr<LinOp> off_diag_linop);
733 explicit Matrix(std::shared_ptr<const Executor> exec,
736 explicit Matrix(std::shared_ptr<const Executor> exec,
738 row_gatherer_template,
742 explicit Matrix(std::shared_ptr<const Executor> exec,
744 std::shared_ptr<LinOp> diag_linop);
746 explicit Matrix(std::shared_ptr<const Executor> exec,
749 std::shared_ptr<LinOp> diag_linop,
750 std::shared_ptr<LinOp> off_diag_linop);
752 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
755 LinOp* x)
const override;
758 std::shared_ptr<RowGatherer<LocalIndexType>> row_gatherer_;
760 gko::detail::ScalarCache one_scalar_;
761 detail::GenericVectorCache recv_buffer_;
762 detail::GenericVectorCache host_recv_buffer_;
763 std::shared_ptr<LinOp> diag_mtx_;
764 std::shared_ptr<LinOp> off_diag_mtx_;
776 #endif // GKO_PUBLIC_CORE_DISTRIBUTED_MATRIX_HPP_