Skip to content

Commit

Permalink
Fix missed moves to gko::experimental::mpi
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzgoebel committed Nov 29, 2023
1 parent 8671d1a commit 93478c3
Showing 1 changed file with 143 additions and 2 deletions.
145 changes: 143 additions & 2 deletions include/ginkgo/core/distributed/matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,147 @@ auto with_matrix_type(Args&&... create_args)
}


namespace experimental {
namespace distributed {

#include <ginkgo/config.hpp>


#if GINKGO_BUILD_MPI


#include <ginkgo/core/base/dense_cache.hpp>
#include <ginkgo/core/base/mpi.hpp>
#include <ginkgo/core/distributed/base.hpp>
#include <ginkgo/core/distributed/lin_op.hpp>


namespace gko {
namespace matrix {


template <typename ValueType, typename IndexType>
class Csr;


}


namespace detail {


/**
#include <ginkgo/config.hpp>
#if GINKGO_BUILD_MPI
#include <ginkgo/core/base/dense_cache.hpp>
#include <ginkgo/core/base/mpi.hpp>
#include <ginkgo/core/distributed/base.hpp>
#include <ginkgo/core/distributed/lin_op.hpp>
namespace gko {
namespace matrix {
template <typename ValueType, typename IndexType>
class Csr;
}
namespace detail {
/**
* Helper struct to test if the Builder type has a function create<ValueType,
* IndexType>(std::shared_ptr<const Executor>).
*/
template <typename Builder, typename ValueType, typename IndexType,
typename = void>
struct is_matrix_type_builder : std::false_type {};


template <typename Builder, typename ValueType, typename IndexType>
struct is_matrix_type_builder<
Builder, ValueType, IndexType,
gko::xstd::void_t<
decltype(std::declval<Builder>().template create<ValueType, IndexType>(
std::declval<std::shared_ptr<const Executor>>()))>>
: std::true_type {};


template <template <typename, typename> class MatrixType,
typename... CreateArgs>
struct MatrixTypeBuilderFromValueAndIndex {
template <typename ValueType, typename IndexType, std::size_t... I>
auto create_impl(std::shared_ptr<const Executor> exec,
std::index_sequence<I...>)
{
return MatrixType<ValueType, IndexType>::create(
exec, std::get<I>(create_args)...);
}


template <typename ValueType, typename IndexType>
auto create(std::shared_ptr<const Executor> exec)
{
// with c++17 we could use std::apply
static constexpr auto size = sizeof...(CreateArgs);
return create_impl<ValueType, IndexType>(
std::move(exec), std::make_index_sequence<size>{});
}

std::tuple<CreateArgs...> create_args;
};


} // namespace detail


/**
* This function returns a type that delays a call to MatrixType::create.
*
* It can be used to set the used value and index type, as well as the executor
* at a later stage.
*
* For example, the following code creates first a temporary object, which is
* then used later to construct an operator of the previously defined base type:
* ```
* auto type = gko::with_matrix_type<gko::matrix::Csr>();
* ...
* std::unique_ptr<LinOp> concrete_op
* if(flag1){
* concrete_op = type.template create<double, int>(exec);
* } else {
* concrete_op = type.template create<float, int>(exec);
* }
* ```
*
* @note This is mainly a helper function to specify the local matrix type for a
* gko::experimental::distributed::Matrix more easily.
*
* @tparam MatrixType A template type that accepts two types, the first one
* will be set to the value type, the second one to the
* index type.
* @tparam Args Types of the arguments passed to MatrixType::create.
*
* @param create_args arguments that will be forwarded to MatrixType::create
*
* @return A type with a function `create<value_type, index_type>(executor)`.
*/
template <template <typename, typename> class MatrixType, typename... Args>
auto with_matrix_type(Args&&... create_args)
{
return detail::MatrixTypeBuilderFromValueAndIndex<MatrixType, Args...>{
std::forward_as_tuple(create_args...)};
}


namespace experimental {
namespace distributed {

Expand Down Expand Up @@ -359,8 +500,8 @@ class Matrix
gko::matrix::Dense<ValueType>* get_recv_buffer() const
{
auto exec = this->get_executor();
auto use_host_buffer =
exec->get_master() != exec && !gko::mpi::is_gpu_aware();
auto use_host_buffer = exec->get_master() != exec &&
!gko::experimental::mpi::is_gpu_aware();
if (use_host_buffer) {
recv_buffer_->copy_from(host_recv_buffer_.get());
}
Expand Down

0 comments on commit 93478c3

Please sign in to comment.