5 #ifndef GKO_PUBLIC_CORE_DISTRIBUTED_VECTOR_HPP_
6 #define GKO_PUBLIC_CORE_DISTRIBUTED_VECTOR_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/distributed/base.hpp>
19 #include <ginkgo/core/matrix/dense.hpp>
23 namespace experimental {
24 namespace distributed {
28 template <
typename ValueType>
35 template <
typename LocalIndexType,
typename GlobalIndexType>
66 template <
typename ValueType =
double>
69 public EnableCloneable<Vector<ValueType>>,
70 public ConvertibleTo<Vector<next_precision<ValueType>>>,
71 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
72 public ConvertibleTo<Vector<next_precision<ValueType, 2>>>,
74 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
75 public ConvertibleTo<Vector<next_precision<ValueType, 3>>>,
77 public EnableAbsoluteComputation<remove_complex<Vector<ValueType>>>,
78 public DistributedBase {
79 friend class EnableCloneable<Vector>;
83 friend class detail::VectorCache<ValueType>;
84 GKO_ASSERT_SUPPORTED_VALUE_TYPE;
89 using ConvertibleTo<Vector<next_precision<ValueType>>>::convert_to;
90 using ConvertibleTo<Vector<next_precision<ValueType>>>::move_to;
92 using value_type = ValueType;
93 using absolute_type = remove_complex<Vector>;
94 using real_type = absolute_type;
95 using complex_type = Vector<to_complex<value_type>>;
105 ptr_param<const Vector> other);
120 ptr_param<const Vector> other, std::shared_ptr<const Executor> exec);
135 ptr_param<const Vector> other, std::shared_ptr<const Executor> exec,
136 const dim<2>& global_size,
const dim<2>& local_size,
size_type stride);
153 ptr_param<
const Partition<int64, int64>> partition);
156 ptr_param<
const Partition<int32, int64>> partition);
159 ptr_param<
const Partition<int32, int32>> partition);
171 ptr_param<
const Partition<int64, int64>> partition);
174 ptr_param<
const Partition<int32, int64>> partition);
177 ptr_param<
const Partition<int32, int32>> partition);
179 void convert_to(Vector<next_precision<ValueType>>* result)
const override;
181 void move_to(Vector<next_precision<ValueType>>* result)
override;
183 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
185 using ConvertibleTo<Vector<next_precision<ValueType, 2>>>::convert_to;
186 using ConvertibleTo<Vector<next_precision<ValueType, 2>>>::move_to;
189 Vector<next_precision<ValueType, 2>>* result)
const override;
191 void move_to(Vector<next_precision<ValueType, 2>>* result)
override;
194 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
196 using ConvertibleTo<Vector<next_precision<ValueType, 3>>>::convert_to;
197 using ConvertibleTo<Vector<next_precision<ValueType, 3>>>::move_to;
200 Vector<next_precision<ValueType, 3>>* result)
const override;
202 void move_to(Vector<next_precision<ValueType, 3>>* result)
override;
220 void make_complex(ptr_param<complex_type> result)
const;
226 std::unique_ptr<real_type>
get_real()
const;
231 void get_real(ptr_param<real_type> result)
const;
237 std::unique_ptr<real_type>
get_imag()
const;
243 void get_imag(ptr_param<real_type> result)
const;
250 void fill(ValueType value);
261 void scale(ptr_param<const LinOp> alpha);
272 void inv_scale(ptr_param<const LinOp> alpha);
283 void add_scaled(ptr_param<const LinOp> alpha, ptr_param<const LinOp> b);
293 void sub_scaled(ptr_param<const LinOp> alpha, ptr_param<const LinOp> b);
304 void compute_dot(ptr_param<const LinOp> b, ptr_param<LinOp> result)
const;
318 void compute_dot(ptr_param<const LinOp> b, ptr_param<LinOp> result,
319 array<char>& tmp)
const;
331 ptr_param<LinOp> result)
const;
346 array<char>& tmp)
const;
392 void compute_norm2(ptr_param<LinOp> result, array<char>& tmp)
const;
414 void compute_norm1(ptr_param<LinOp> result, array<char>& tmp)
const;
437 void compute_mean(ptr_param<LinOp> result, array<char>& tmp)
const;
540 static std::unique_ptr<Vector>
create(std::shared_ptr<const Executor> exec,
541 mpi::communicator comm,
542 dim<2> global_size, dim<2> local_size,
556 static std::unique_ptr<Vector>
create(std::shared_ptr<const Executor> exec,
557 mpi::communicator comm,
558 dim<2> global_size = {},
559 dim<2> local_size = {});
578 static std::unique_ptr<Vector>
create(
579 std::shared_ptr<const Executor> exec, mpi::communicator comm,
580 dim<2> global_size, std::unique_ptr<local_vector_type> local_vector);
600 static std::unique_ptr<Vector>
create(
601 std::shared_ptr<const Executor> exec, mpi::communicator comm,
602 std::unique_ptr<local_vector_type> local_vector);
617 std::shared_ptr<const Executor> exec, mpi::communicator comm,
619 std::unique_ptr<const local_vector_type> local_vector);
634 std::shared_ptr<const Executor> exec, mpi::communicator comm,
635 std::unique_ptr<const local_vector_type> local_vector);
638 Vector(std::shared_ptr<const Executor> exec, mpi::communicator comm,
639 dim<2> global_size, dim<2> local_size,
size_type stride);
641 explicit Vector(std::shared_ptr<const Executor> exec,
642 mpi::communicator comm, dim<2> global_size = {},
643 dim<2> local_size = {});
645 Vector(std::shared_ptr<const Executor> exec, mpi::communicator comm,
646 dim<2> global_size, std::unique_ptr<local_vector_type> local_vector);
648 Vector(std::shared_ptr<const Executor> exec, mpi::communicator comm,
649 std::unique_ptr<local_vector_type> local_vector);
651 void resize(dim<2> global_size, dim<2> local_size);
653 template <
typename LocalIndexType,
typename GlobalIndexType>
654 void read_distributed_impl(
655 const device_matrix_data<ValueType, GlobalIndexType>& data,
656 const Partition<LocalIndexType, GlobalIndexType>* partition);
658 void apply_impl(
const LinOp*,
LinOp*)
const override;
661 LinOp*)
const override;
669 virtual std::unique_ptr<Vector> create_with_same_config()
const;
683 virtual std::unique_ptr<Vector> create_with_type_of_impl(
684 std::shared_ptr<const Executor> exec,
const dim<2>& global_size,
685 const dim<2>& local_size,
size_type stride)
const;
690 virtual std::unique_ptr<Vector> create_submatrix_impl(local_span rows,
695 local_vector_type local_;
696 ::gko::detail::DenseCache<ValueType> host_reduction_buffer_;
697 ::gko::detail::DenseCache<remove_complex<ValueType>> host_norm_buffer_;
708 template <
typename TargetType>
709 struct conversion_target_helper;
721 template <
typename ValueType>
722 struct conversion_target_helper<experimental::distributed::Vector<ValueType>> {
723 using target_type = experimental::distributed::Vector<ValueType>;
725 experimental::distributed::Vector<previous_precision<ValueType>>;
727 static std::unique_ptr<target_type> create_empty(
const source_type* source)
729 return target_type::create(source->get_executor(),
730 source->get_communicator());
736 static std::unique_ptr<target_type> create_empty(
const target_type* source)
738 return target_type::create(source->get_executor(),
739 source->get_communicator());
742 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
743 using snd_source_type =
744 experimental::distributed::Vector<previous_precision<ValueType, 2>>;
746 static std::unique_ptr<target_type> create_empty(
747 const snd_source_type* source)
749 return target_type::create(source->get_executor(),
750 source->get_communicator());
753 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
754 using trd_source_type =
755 experimental::distributed::Vector<previous_precision<ValueType, 3>>;
757 static std::unique_ptr<target_type> create_empty(
758 const trd_source_type* source)
760 return target_type::create(source->get_executor(),
761 source->get_communicator());
771 #endif // GINKGO_BUILD_MPI
774 #endif // GKO_PUBLIC_CORE_DISTRIBUTED_VECTOR_HPP_