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>
263 :
public EnableLinOp<Matrix<ValueType, LocalIndexType, GlobalIndexType>>,
265 Matrix<next_precision<ValueType>, LocalIndexType, GlobalIndexType>>,
266 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
267 public ConvertibleTo<Matrix<next_precision<ValueType, 2>, LocalIndexType,
270 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
271 public ConvertibleTo<Matrix<next_precision<ValueType, 3>, LocalIndexType,
279 GKO_ASSERT_SUPPORTED_VALUE_AND_DIST_INDEX_TYPE;
282 using value_type = ValueType;
283 using index_type = GlobalIndexType;
284 using local_index_type = LocalIndexType;
285 using global_index_type = GlobalIndexType;
293 GlobalIndexType>>::convert_to;
295 GlobalIndexType>>::move_to;
298 global_index_type>* result)
const override;
301 global_index_type>* result)
override;
303 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
307 global_index_type>>::convert_to;
309 global_index_type>>::move_to;
312 global_index_type>* result)
const override;
315 global_index_type>* result)
override;
318 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
322 global_index_type>>::convert_to;
324 global_index_type>>::move_to;
327 global_index_type>* result)
const override;
330 global_index_type>* result)
override;
427 return non_local_mtx_;
473 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
489 static std::unique_ptr<Matrix>
create(
490 std::shared_ptr<const Executor> exec,
492 row_gatherer_template);
514 template <
typename MatrixType,
515 typename = std::enable_if_t<gko::detail::is_matrix_type_builder<
516 MatrixType, ValueType, LocalIndexType>::value>>
517 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
519 MatrixType matrix_template)
523 matrix_template.template create<ValueType, LocalIndexType>(exec));
554 template <
typename LocalMatrixType,
typename NonLocalMatrixType,
555 typename = std::enable_if_t<
556 gko::detail::is_matrix_type_builder<
557 LocalMatrixType, ValueType, LocalIndexType>::value &&
558 gko::detail::is_matrix_type_builder<
559 NonLocalMatrixType, ValueType, LocalIndexType>::value>>
562 LocalMatrixType local_matrix_template,
563 NonLocalMatrixType non_local_matrix_template)
567 local_matrix_template.template create<ValueType, LocalIndexType>(
569 non_local_matrix_template
570 .template create<ValueType, LocalIndexType>(exec));
587 static std::unique_ptr<Matrix>
create(
607 static std::unique_ptr<Matrix>
create(
624 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
626 std::shared_ptr<LinOp> local_linop);
647 "Please use the overload with an index_map instead.")]]
static std::
650 dim<2> size, std::shared_ptr<LinOp> local_linop,
651 std::shared_ptr<LinOp> non_local_linop,
652 std::vector<comm_index_type> recv_sizes,
653 std::vector<comm_index_type> recv_offsets,
669 static std::unique_ptr<Matrix>
create(
672 std::shared_ptr<LinOp> local_linop,
673 std::shared_ptr<LinOp> non_local_linop);
694 explicit Matrix(std::shared_ptr<const Executor> exec,
697 explicit Matrix(std::shared_ptr<const Executor> exec,
699 row_gatherer_template,
703 explicit Matrix(std::shared_ptr<const Executor> exec,
705 std::shared_ptr<LinOp> local_linop);
707 explicit Matrix(std::shared_ptr<const Executor> exec,
710 std::shared_ptr<LinOp> local_linop,
711 std::shared_ptr<LinOp> non_local_linop);
713 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
716 LinOp* x)
const override;
719 std::shared_ptr<RowGatherer<LocalIndexType>> row_gatherer_;
721 gko::detail::ScalarCache one_scalar_;
722 detail::GenericVectorCache recv_buffer_;
723 detail::GenericVectorCache host_recv_buffer_;
724 std::shared_ptr<LinOp> local_mtx_;
725 std::shared_ptr<LinOp> non_local_mtx_;
737 #endif // GKO_PUBLIC_CORE_DISTRIBUTED_MATRIX_HPP_