Skip to content

Commit

Permalink
Add base matrix copy async (elemental#91)
Browse files Browse the repository at this point in the history
* add dispatch for copy-async

* tick version
  • Loading branch information
benson31 authored and bvanessen committed Dec 10, 2019
1 parent e0c6137 commit aced0a7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ endif (__GIT_EXECUTABLE)
# This must be set because version tags
set(HYDROGEN_VERSION_MAJOR 1)
set(HYDROGEN_VERSION_MINOR 3)
set(HYDROGEN_VERSION_PATCH 0)
set(HYDROGEN_VERSION_PATCH 1)
set(HYDROGEN_VERSION_MAJOR_MINOR
"${HYDROGEN_VERSION_MAJOR}.${HYDROGEN_VERSION_MINOR}")
set(HYDROGEN_VERSION
Expand Down
69 changes: 53 additions & 16 deletions include/El/blas_like/level1/Copy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,54 +26,91 @@ using Expand = TypeList<X<Ts>...>;
// This is replaced by a generic multiple dispatch engine in
// DiHydrogen; this is a one-off use-case for now, so there's no need
// to backport a robust implementation.
template <typename LHSList, typename RHSList>
struct BaseCopy
template <typename FunctorT, typename LHSList, typename RHSList>
struct CopyDispatcher
{
static void Do(BaseDistMatrix const& src, BaseDistMatrix& tgt)
static void Do(FunctorT f,
BaseDistMatrix const& src, BaseDistMatrix& tgt)
{
using LHead = Head<LHSList>;
using LTail = Tail<LHSList>;
if (auto const* ptr = dynamic_cast<LHead const*>(&src))
return BaseCopy<LHSList, RHSList>::DoRHS(*ptr, tgt);
return CopyDispatcher<FunctorT, LHSList, RHSList>::DoRHS(
f, *ptr, tgt);
else
return BaseCopy<LTail, RHSList>::Do(src, tgt);
return CopyDispatcher<FunctorT, LTail, RHSList>::Do(f, src, tgt);
}

template <typename LHSType>
static void DoRHS(LHSType const& src, BaseDistMatrix& tgt)
static void DoRHS(FunctorT f, LHSType const& src, BaseDistMatrix& tgt)
{
using RHead = Head<RHSList>;
using RTail = Tail<RHSList>;
if (auto* ptr = dynamic_cast<RHead*>(&tgt))
return Copy(src, *ptr);
return f(src, *ptr);
else
return BaseCopy<LHSList, RTail>::DoRHS(src, tgt);
return CopyDispatcher<FunctorT, LHSList, RTail>::DoRHS(f, src, tgt);
}
};
};// struct CopyDispatcher

template <typename RHSList>
struct BaseCopy<TypeList<>, RHSList>
template <typename FunctorT, typename RHSList>
struct CopyDispatcher<FunctorT, TypeList<>, RHSList>
{
static void Do(BaseDistMatrix const& src, BaseDistMatrix& tgt)
static void Do(FunctorT const&,
BaseDistMatrix const&, BaseDistMatrix const&)
{
LogicError("Source matrix type not found.");
}
};

template <typename LHSList>
struct BaseCopy<LHSList, TypeList<>>
template <typename FunctorT, typename LHSList>
struct CopyDispatcher<FunctorT, LHSList, TypeList<>>
{
static void DoRHS(BaseDistMatrix const& src, BaseDistMatrix& tgt)
static void DoRHS(FunctorT const&,
BaseDistMatrix const&, BaseDistMatrix const&)
{
LogicError("Target matrix type not found.");
}
};

struct CopyFunctor
{
template <typename T, typename U>
void operator()(AbstractDistMatrix<T> const& src,
AbstractDistMatrix<U>& tgt) const
{
return Copy(src, tgt);
}
};// CopyFunctor

struct CopyAsyncFunctor
{
template <typename T, typename U>
void operator()(AbstractDistMatrix<T> const& src,
AbstractDistMatrix<U>& tgt) const
{
return CopyAsync(src, tgt);
}
};// CopyAsyncFunctor

}// namespace details

inline void Copy(BaseDistMatrix const& Source, BaseDistMatrix& Target)
{
using FunctorT = details::CopyFunctor;
using MatrixTs = details::Expand<AbstractDistMatrix, float, double>;
using Dispatcher = details::CopyDispatcher<FunctorT, MatrixTs, MatrixTs>;
details::CopyFunctor f;
return Dispatcher::Do(f, Source, Target);
}

inline void CopyAsync(BaseDistMatrix const& Source, BaseDistMatrix& Target)
{
using FunctorT = details::CopyAsyncFunctor;
using MatrixTs = details::Expand<AbstractDistMatrix, float, double>;
return details::BaseCopy<MatrixTs, MatrixTs>::Do(Source, Target);
using Dispatcher = details::CopyDispatcher<FunctorT, MatrixTs, MatrixTs>;
details::CopyAsyncFunctor f;
return Dispatcher::Do(f, Source, Target);
}

template <typename T>
Expand Down

0 comments on commit aced0a7

Please sign in to comment.