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>
68 :
public EnableLinOp<Vector<ValueType>>,
69 public ConvertibleTo<Vector<next_precision<ValueType>>>,
70 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
71 public ConvertibleTo<Vector<next_precision<ValueType, 2>>>,
73 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
74 public ConvertibleTo<Vector<next_precision<ValueType, 3>>>,
76 public EnableAbsoluteComputation<remove_complex<Vector<ValueType>>>,
77 public DistributedBase {
78 friend class EnablePolymorphicObject<Vector,
LinOp>;
82 friend class detail::VectorCache<ValueType>;
87 using ConvertibleTo<Vector<next_precision<ValueType>>>::convert_to;
88 using ConvertibleTo<Vector<next_precision<ValueType>>>::move_to;
90 using value_type = ValueType;
91 using absolute_type = remove_complex<Vector>;
92 using real_type = absolute_type;
93 using complex_type = Vector<to_complex<value_type>>;
103 ptr_param<const Vector> other);
118 ptr_param<const Vector> other, std::shared_ptr<const Executor> exec);
133 ptr_param<const Vector> other, std::shared_ptr<const Executor> exec,
134 const dim<2>& global_size,
const dim<2>& local_size,
size_type stride);
151 ptr_param<
const Partition<int64, int64>> partition);
154 ptr_param<
const Partition<int32, int64>> partition);
157 ptr_param<
const Partition<int32, int32>> partition);
169 ptr_param<
const Partition<int64, int64>> partition);
172 ptr_param<
const Partition<int32, int64>> partition);
175 ptr_param<
const Partition<int32, int32>> partition);
177 void convert_to(Vector<next_precision<ValueType>>* result)
const override;
179 void move_to(Vector<next_precision<ValueType>>* result)
override;
181 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
183 using ConvertibleTo<Vector<next_precision<ValueType, 2>>>::convert_to;
184 using ConvertibleTo<Vector<next_precision<ValueType, 2>>>::move_to;
187 Vector<next_precision<ValueType, 2>>* result)
const override;
189 void move_to(Vector<next_precision<ValueType, 2>>* result)
override;
192 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
194 using ConvertibleTo<Vector<next_precision<ValueType, 3>>>::convert_to;
195 using ConvertibleTo<Vector<next_precision<ValueType, 3>>>::move_to;
198 Vector<next_precision<ValueType, 3>>* result)
const override;
200 void move_to(Vector<next_precision<ValueType, 3>>* result)
override;
218 void make_complex(ptr_param<complex_type> result)
const;
224 std::unique_ptr<real_type>
get_real()
const;
229 void get_real(ptr_param<real_type> result)
const;
235 std::unique_ptr<real_type>
get_imag()
const;
241 void get_imag(ptr_param<real_type> result)
const;
248 void fill(ValueType value);
259 void scale(ptr_param<const LinOp> alpha);
270 void inv_scale(ptr_param<const LinOp> alpha);
281 void add_scaled(ptr_param<const LinOp> alpha, ptr_param<const LinOp> b);
291 void sub_scaled(ptr_param<const LinOp> alpha, ptr_param<const LinOp> b);
302 void compute_dot(ptr_param<const LinOp> b, ptr_param<LinOp> result)
const;
316 void compute_dot(ptr_param<const LinOp> b, ptr_param<LinOp> result,
317 array<char>& tmp)
const;
329 ptr_param<LinOp> result)
const;
344 array<char>& tmp)
const;
390 void compute_norm2(ptr_param<LinOp> result, array<char>& tmp)
const;
412 void compute_norm1(ptr_param<LinOp> result, array<char>& tmp)
const;
435 void compute_mean(ptr_param<LinOp> result, array<char>& tmp)
const;
525 static std::unique_ptr<Vector>
create(std::shared_ptr<const Executor> exec,
526 mpi::communicator comm,
527 dim<2> global_size, dim<2> local_size,
541 static std::unique_ptr<Vector>
create(std::shared_ptr<const Executor> exec,
542 mpi::communicator comm,
543 dim<2> global_size = {},
544 dim<2> local_size = {});
563 static std::unique_ptr<Vector>
create(
564 std::shared_ptr<const Executor> exec, mpi::communicator comm,
565 dim<2> global_size, std::unique_ptr<local_vector_type> local_vector);
585 static std::unique_ptr<Vector>
create(
586 std::shared_ptr<const Executor> exec, mpi::communicator comm,
587 std::unique_ptr<local_vector_type> local_vector);
602 std::shared_ptr<const Executor> exec, mpi::communicator comm,
604 std::unique_ptr<const local_vector_type> local_vector);
619 std::shared_ptr<const Executor> exec, mpi::communicator comm,
620 std::unique_ptr<const local_vector_type> local_vector);
623 Vector(std::shared_ptr<const Executor> exec, mpi::communicator comm,
624 dim<2> global_size, dim<2> local_size,
size_type stride);
626 explicit Vector(std::shared_ptr<const Executor> exec,
627 mpi::communicator comm, dim<2> global_size = {},
628 dim<2> local_size = {});
630 Vector(std::shared_ptr<const Executor> exec, mpi::communicator comm,
631 dim<2> global_size, std::unique_ptr<local_vector_type> local_vector);
633 Vector(std::shared_ptr<const Executor> exec, mpi::communicator comm,
634 std::unique_ptr<local_vector_type> local_vector);
636 void resize(dim<2> global_size, dim<2> local_size);
638 template <
typename LocalIndexType,
typename GlobalIndexType>
639 void read_distributed_impl(
640 const device_matrix_data<ValueType, GlobalIndexType>& data,
641 const Partition<LocalIndexType, GlobalIndexType>* partition);
643 void apply_impl(
const LinOp*,
LinOp*)
const override;
646 LinOp*)
const override;
654 virtual std::unique_ptr<Vector> create_with_same_config()
const;
668 virtual std::unique_ptr<Vector> create_with_type_of_impl(
669 std::shared_ptr<const Executor> exec,
const dim<2>& global_size,
670 const dim<2>& local_size,
size_type stride)
const;
673 local_vector_type local_;
674 ::gko::detail::DenseCache<ValueType> host_reduction_buffer_;
675 ::gko::detail::DenseCache<remove_complex<ValueType>> host_norm_buffer_;
686 template <
typename TargetType>
687 struct conversion_target_helper;
699 template <
typename ValueType>
700 struct conversion_target_helper<experimental::distributed::Vector<ValueType>> {
701 using target_type = experimental::distributed::Vector<ValueType>;
703 experimental::distributed::Vector<previous_precision<ValueType>>;
705 static std::unique_ptr<target_type> create_empty(
const source_type* source)
707 return target_type::create(source->get_executor(),
708 source->get_communicator());
714 static std::unique_ptr<target_type> create_empty(
const target_type* source)
716 return target_type::create(source->get_executor(),
717 source->get_communicator());
720 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
721 using snd_source_type =
722 experimental::distributed::Vector<previous_precision<ValueType, 2>>;
724 static std::unique_ptr<target_type> create_empty(
725 const snd_source_type* source)
727 return target_type::create(source->get_executor(),
728 source->get_communicator());
731 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
732 using trd_source_type =
733 experimental::distributed::Vector<previous_precision<ValueType, 3>>;
735 static std::unique_ptr<target_type> create_empty(
736 const trd_source_type* source)
738 return target_type::create(source->get_executor(),
739 source->get_communicator());
749 #endif // GINKGO_BUILD_MPI
752 #endif // GKO_PUBLIC_CORE_DISTRIBUTED_VECTOR_HPP_