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
71 public ConvertibleTo<Vector<next_precision<next_precision<ValueType>>>>,
73 public EnableAbsoluteComputation<remove_complex<Vector<ValueType>>>,
74 public DistributedBase {
75 friend class EnablePolymorphicObject<Vector,
LinOp>;
78 friend class Vector<previous_precision<ValueType>>;
79 friend class detail::VectorCache<ValueType>;
84 using ConvertibleTo<Vector<next_precision<ValueType>>>::convert_to;
85 using ConvertibleTo<Vector<next_precision<ValueType>>>::move_to;
87 using value_type = ValueType;
88 using absolute_type = remove_complex<Vector>;
89 using real_type = absolute_type;
90 using complex_type = Vector<to_complex<value_type>>;
100 ptr_param<const Vector> other);
115 ptr_param<const Vector> other, std::shared_ptr<const Executor> exec);
130 ptr_param<const Vector> other, std::shared_ptr<const Executor> exec,
131 const dim<2>& global_size,
const dim<2>& local_size,
size_type stride);
148 ptr_param<
const Partition<int64, int64>> partition);
151 ptr_param<
const Partition<int32, int64>> partition);
154 ptr_param<
const Partition<int32, int32>> partition);
166 ptr_param<
const Partition<int64, int64>> partition);
169 ptr_param<
const Partition<int32, int64>> partition);
172 ptr_param<
const Partition<int32, int32>> partition);
174 void convert_to(Vector<next_precision<ValueType>>* result)
const override;
176 void move_to(Vector<next_precision<ValueType>>* result)
override;
178 #if GINKGO_ENABLE_HALF
179 friend class Vector<previous_precision<previous_precision<ValueType>>>;
181 Vector<next_precision<next_precision<ValueType>>>>::convert_to;
183 Vector<next_precision<next_precision<ValueType>>>>::move_to;
185 void convert_to(Vector<
next_precision<next_precision<ValueType>>>* result)
189 Vector<
next_precision<next_precision<ValueType>>>* result)
override;
207 void make_complex(ptr_param<complex_type> result)
const;
213 std::unique_ptr<real_type>
get_real()
const;
218 void get_real(ptr_param<real_type> result)
const;
224 std::unique_ptr<real_type>
get_imag()
const;
230 void get_imag(ptr_param<real_type> result)
const;
237 void fill(ValueType value);
248 void scale(ptr_param<const LinOp> alpha);
259 void inv_scale(ptr_param<const LinOp> alpha);
270 void add_scaled(ptr_param<const LinOp> alpha, ptr_param<const LinOp> b);
280 void sub_scaled(ptr_param<const LinOp> alpha, ptr_param<const LinOp> b);
291 void compute_dot(ptr_param<const LinOp> b, ptr_param<LinOp> result)
const;
305 void compute_dot(ptr_param<const LinOp> b, ptr_param<LinOp> result,
306 array<char>& tmp)
const;
318 ptr_param<LinOp> result)
const;
333 array<char>& tmp)
const;
379 void compute_norm2(ptr_param<LinOp> result, array<char>& tmp)
const;
401 void compute_norm1(ptr_param<LinOp> result, array<char>& tmp)
const;
424 void compute_mean(ptr_param<LinOp> result, array<char>& tmp)
const;
514 static std::unique_ptr<Vector>
create(std::shared_ptr<const Executor> exec,
515 mpi::communicator comm,
516 dim<2> global_size, dim<2> local_size,
530 static std::unique_ptr<Vector>
create(std::shared_ptr<const Executor> exec,
531 mpi::communicator comm,
532 dim<2> global_size = {},
533 dim<2> local_size = {});
552 static std::unique_ptr<Vector>
create(
553 std::shared_ptr<const Executor> exec, mpi::communicator comm,
554 dim<2> global_size, std::unique_ptr<local_vector_type> local_vector);
574 static std::unique_ptr<Vector>
create(
575 std::shared_ptr<const Executor> exec, mpi::communicator comm,
576 std::unique_ptr<local_vector_type> local_vector);
591 std::shared_ptr<const Executor> exec, mpi::communicator comm,
593 std::unique_ptr<const local_vector_type> local_vector);
608 std::shared_ptr<const Executor> exec, mpi::communicator comm,
609 std::unique_ptr<const local_vector_type> local_vector);
612 Vector(std::shared_ptr<const Executor> exec, mpi::communicator comm,
613 dim<2> global_size, dim<2> local_size,
size_type stride);
615 explicit Vector(std::shared_ptr<const Executor> exec,
616 mpi::communicator comm, dim<2> global_size = {},
617 dim<2> local_size = {});
619 Vector(std::shared_ptr<const Executor> exec, mpi::communicator comm,
620 dim<2> global_size, std::unique_ptr<local_vector_type> local_vector);
622 Vector(std::shared_ptr<const Executor> exec, mpi::communicator comm,
623 std::unique_ptr<local_vector_type> local_vector);
625 void resize(dim<2> global_size, dim<2> local_size);
627 template <
typename LocalIndexType,
typename GlobalIndexType>
628 void read_distributed_impl(
629 const device_matrix_data<ValueType, GlobalIndexType>& data,
630 const Partition<LocalIndexType, GlobalIndexType>* partition);
632 void apply_impl(
const LinOp*,
LinOp*)
const override;
635 LinOp*)
const override;
643 virtual std::unique_ptr<Vector> create_with_same_config()
const;
657 virtual std::unique_ptr<Vector> create_with_type_of_impl(
658 std::shared_ptr<const Executor> exec,
const dim<2>& global_size,
659 const dim<2>& local_size,
size_type stride)
const;
662 local_vector_type local_;
663 ::gko::detail::DenseCache<ValueType> host_reduction_buffer_;
664 ::gko::detail::DenseCache<remove_complex<ValueType>> host_norm_buffer_;
675 template <
typename TargetType>
676 struct conversion_target_helper;
688 template <
typename ValueType>
689 struct conversion_target_helper<experimental::distributed::Vector<ValueType>> {
690 using target_type = experimental::distributed::Vector<ValueType>;
692 experimental::distributed::Vector<previous_precision<ValueType>>;
694 static std::unique_ptr<target_type> create_empty(
const source_type* source)
696 return target_type::create(source->get_executor(),
697 source->get_communicator());
703 static std::unique_ptr<target_type> create_empty(
const target_type* source)
705 return target_type::create(source->get_executor(),
706 source->get_communicator());
709 #if GINKGO_ENABLE_HALF
710 using snd_source_type = experimental::distributed::Vector<
711 previous_precision<previous_precision<ValueType>>>;
713 static std::unique_ptr<target_type> create_empty(
714 const snd_source_type* source)
716 return target_type::create(source->get_executor(),
717 source->get_communicator());
727 #endif // GINKGO_BUILD_MPI
730 #endif // GKO_PUBLIC_CORE_DISTRIBUTED_VECTOR_HPP_