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,
282 GKO_ASSERT_SUPPORTED_VALUE_AND_DIST_INDEX_TYPE;
285 using value_type = ValueType;
286 using index_type = GlobalIndexType;
287 using local_index_type = LocalIndexType;
288 using global_index_type = GlobalIndexType;
296 GlobalIndexType>>::convert_to;
298 GlobalIndexType>>::move_to;
301 global_index_type>* result)
const override;
304 global_index_type>* result)
override;
306 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
310 global_index_type>>::convert_to;
312 global_index_type>>::move_to;
315 global_index_type>* result)
const override;
318 global_index_type>* result)
override;
321 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
325 global_index_type>>::convert_to;
327 global_index_type>>::move_to;
330 global_index_type>* result)
const override;
333 global_index_type>* result)
override;
436 return off_diag_mtx_;
442 GKO_DEPRECATED(
"use get_diag_matrix() instead")
451 GKO_DEPRECATED(
"use get_off_diag_matrix() instead")
500 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
516 static std::unique_ptr<Matrix>
create(
517 std::shared_ptr<const Executor> exec,
519 row_gatherer_template);
541 template <
typename MatrixType,
542 typename = std::enable_if_t<gko::detail::is_matrix_type_builder<
543 MatrixType, ValueType, LocalIndexType>::value>>
544 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
546 MatrixType matrix_template)
550 matrix_template.template create<ValueType, LocalIndexType>(exec));
581 template <
typename DiagMatrixType,
typename OffDiagMatrixType,
582 typename = std::enable_if_t<
583 gko::detail::is_matrix_type_builder<DiagMatrixType, ValueType,
584 LocalIndexType>::value &&
585 gko::detail::is_matrix_type_builder<
586 OffDiagMatrixType, ValueType, LocalIndexType>::value>>
589 DiagMatrixType diag_matrix_template,
590 OffDiagMatrixType off_diag_matrix_template)
594 diag_matrix_template.template create<ValueType, LocalIndexType>(
596 off_diag_matrix_template.template create<ValueType, LocalIndexType>(
614 static std::unique_ptr<Matrix>
create(
634 static std::unique_ptr<Matrix>
create(
651 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
653 std::shared_ptr<LinOp> diag_linop);
674 "Please use the overload with an index_map instead.")]]
static std::
677 dim<2> size, std::shared_ptr<LinOp> diag_linop,
678 std::shared_ptr<LinOp> off_diag_linop,
679 std::vector<comm_index_type> recv_sizes,
680 std::vector<comm_index_type> recv_offsets,
696 static std::unique_ptr<Matrix>
create(
699 std::shared_ptr<LinOp> diag_linop,
700 std::shared_ptr<LinOp> off_diag_linop);
721 explicit Matrix(std::shared_ptr<const Executor> exec,
724 explicit Matrix(std::shared_ptr<const Executor> exec,
726 row_gatherer_template,
730 explicit Matrix(std::shared_ptr<const Executor> exec,
732 std::shared_ptr<LinOp> diag_linop);
734 explicit Matrix(std::shared_ptr<const Executor> exec,
737 std::shared_ptr<LinOp> diag_linop,
738 std::shared_ptr<LinOp> off_diag_linop);
740 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
743 LinOp* x)
const override;
746 std::shared_ptr<RowGatherer<LocalIndexType>> row_gatherer_;
748 gko::detail::ScalarCache one_scalar_;
749 detail::GenericVectorCache recv_buffer_;
750 detail::GenericVectorCache host_recv_buffer_;
751 std::shared_ptr<LinOp> diag_mtx_;
752 std::shared_ptr<LinOp> off_diag_mtx_;
764 #endif // GKO_PUBLIC_CORE_DISTRIBUTED_MATRIX_HPP_