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,
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,
496 template <
typename MatrixType,
497 typename = std::enable_if_t<gko::detail::is_matrix_type_builder<
498 MatrixType, ValueType, LocalIndexType>::value>>
499 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
501 MatrixType matrix_template)
505 matrix_template.template create<ValueType, LocalIndexType>(exec));
536 template <
typename LocalMatrixType,
typename NonLocalMatrixType,
537 typename = std::enable_if_t<
538 gko::detail::is_matrix_type_builder<
539 LocalMatrixType, ValueType, LocalIndexType>::value &&
540 gko::detail::is_matrix_type_builder<
541 NonLocalMatrixType, ValueType, LocalIndexType>::value>>
544 LocalMatrixType local_matrix_template,
545 NonLocalMatrixType non_local_matrix_template)
549 local_matrix_template.template create<ValueType, LocalIndexType>(
551 non_local_matrix_template
552 .template create<ValueType, LocalIndexType>(exec));
569 static std::unique_ptr<Matrix>
create(
589 static std::unique_ptr<Matrix>
create(
606 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
608 std::shared_ptr<LinOp> local_linop);
629 "Please use the overload with an index_map instead.")]]
static std::
632 dim<2> size, std::shared_ptr<LinOp> local_linop,
633 std::shared_ptr<LinOp> non_local_linop,
634 std::vector<comm_index_type> recv_sizes,
635 std::vector<comm_index_type> recv_offsets,
651 static std::unique_ptr<Matrix>
create(
654 std::shared_ptr<LinOp> local_linop,
655 std::shared_ptr<LinOp> non_local_linop);
676 explicit Matrix(std::shared_ptr<const Executor> exec,
679 explicit Matrix(std::shared_ptr<const Executor> exec,
684 explicit Matrix(std::shared_ptr<const Executor> exec,
686 std::shared_ptr<LinOp> local_linop);
688 explicit Matrix(std::shared_ptr<const Executor> exec,
691 std::shared_ptr<LinOp> local_linop,
692 std::shared_ptr<LinOp> non_local_linop);
694 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
697 LinOp* x)
const override;
700 std::shared_ptr<RowGatherer<LocalIndexType>> row_gatherer_;
702 gko::detail::ScalarCache one_scalar_;
703 detail::GenericVectorCache recv_buffer_;
704 detail::GenericVectorCache host_recv_buffer_;
705 std::shared_ptr<LinOp> local_mtx_;
706 std::shared_ptr<LinOp> non_local_mtx_;
718 #endif // GKO_PUBLIC_CORE_DISTRIBUTED_MATRIX_HPP_