Skip to content

Commit

Permalink
include typename
Browse files Browse the repository at this point in the history
  • Loading branch information
cwpearson committed Mar 12, 2024
1 parent 19dec10 commit 7e44e32
Show file tree
Hide file tree
Showing 21 changed files with 119 additions and 100 deletions.
12 changes: 5 additions & 7 deletions perf_tests/test_2dhalo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ void noop(benchmark::State, MPI_Comm) {}
template <typename Space, typename View>
void send_recv(benchmark::State &, MPI_Comm comm, const Space &space, int nx,
int ny, int rx, int ry, int rs, const View &v) {

// 2D index of nbrs in minus and plus direction (periodic)
const int xm1 = (rx + rs - 1) % rs;
const int ym1 = (ry + rs - 1) % rs;
Expand Down Expand Up @@ -72,13 +71,12 @@ void send_recv(benchmark::State &, MPI_Comm comm, const Space &space, int nx,
}

void benchmark_2dhalo(benchmark::State &state) {

using Scalar = double;
using Scalar = double;
using grid_type = Kokkos::View<Scalar ***, Kokkos::LayoutRight>;

// problem size per rank
int nx = 512;
int ny = 512;
int nx = 512;
int ny = 512;
int nprops = 3;

int rank, size;
Expand All @@ -100,12 +98,12 @@ void benchmark_2dhalo(benchmark::State &state) {
}
} else {
while (state.KeepRunning()) {
do_iteration(state, MPI_COMM_WORLD, noop); // do nothing...
do_iteration(state, MPI_COMM_WORLD, noop); // do nothing...
}
}

state.counters["active_ranks"] = rs * rs;
state.counters["nx"] = nx;
state.counters["nx"] = nx;
// clang-format off
state.SetBytesProcessed(
sizeof(Scalar)
Expand Down
3 changes: 1 addition & 2 deletions perf_tests/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// This reporter does nothing.
// We can use it to disable output from all but the root process
class NullReporter : public ::benchmark::BenchmarkReporter {
public:
public:
NullReporter() {}
virtual bool ReportContext(const Context &) { return true; }
virtual void ReportRuns(const std::vector<Run> &) {}
Expand All @@ -31,7 +31,6 @@ class NullReporter : public ::benchmark::BenchmarkReporter {
// The main is rewritten to allow for MPI initializing and for selecting a
// reporter according to the process rank
int main(int argc, char **argv) {

MPI_Init(&argc, &argv);

int rank;
Expand Down
2 changes: 1 addition & 1 deletion perf_tests/test_sendrecv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void benchmark_sendrecv(benchmark::State &state) {

using Scalar = double;

auto space = Kokkos::DefaultExecutionSpace();
auto space = Kokkos::DefaultExecutionSpace();
using view_type = Kokkos::View<Scalar *>;
view_type a("", 1000000);

Expand Down
3 changes: 1 addition & 2 deletions perf_tests/test_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
template <typename F, typename... Args>
void do_iteration(benchmark::State &state, MPI_Comm comm, F &&func,
Args... args) {

using Clock = std::chrono::steady_clock;
using Clock = std::chrono::steady_clock;
using Duration = std::chrono::duration<double>;

auto start = Clock::now();
Expand Down
2 changes: 1 addition & 1 deletion src/KokkosComm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ void recv(const ExecSpace &space, Recv &sv, int src, int tag, MPI_Comm comm) {
return Impl::recv(space, sv, src, tag, comm);
}

} // namespace KokkosComm
} // namespace KokkosComm
2 changes: 1 addition & 1 deletion src/KokkosComm_collective.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ void reduce(const ExecSpace &space, const SendView &sv, const RecvView &rv,
return Impl::reduce(space, sv, rv, op, root, comm);
}

} // namespace KokkosComm
} // namespace KokkosComm
15 changes: 8 additions & 7 deletions src/KokkosComm_pack_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@

namespace KokkosComm {

template <typename T> struct PackTraits {
template <typename T>
struct PackTraits {
static_assert(std::is_void_v<T>,
"KokkosComm::PackTraits not specialized for type");
};

/*! \brief This can be specialized to do custom behavior for a particular view*/
template <KokkosView View> struct PackTraits<View> {

template <KokkosView View>
struct PackTraits<View> {
using packer_type = Impl::Packer::DeepCopy<View>;

static bool needs_unpack(const View &v) {
Expand All @@ -48,8 +49,8 @@ template <KokkosView View> struct PackTraits<View> {

#if KOKKOSCOMM_ENABLE_MDSPAN

template <Mdspan Span> struct PackTraits<Span> {

template <Mdspan Span>
struct PackTraits<Span> {
using packer_type = Impl::Packer::MpiDatatype<Span>;

static bool needs_unpack(const Span &v) {
Expand All @@ -60,5 +61,5 @@ template <Mdspan Span> struct PackTraits<Span> {
}
};

#endif // KOKKOSCOMM_ENABLE_MDSPAN
} // namespace KokkosComm
#endif // KOKKOSCOMM_ENABLE_MDSPAN
} // namespace KokkosComm
15 changes: 8 additions & 7 deletions src/KokkosComm_request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
namespace KokkosComm {

class Req {

// a type-erased view. Request uses these to keep temporary views alive for
// the lifetime of "Immediate" MPI operations
struct ViewHolderBase {
virtual ~ViewHolderBase() {}
};
template <typename V> struct ViewHolder : ViewHolderBase {
template <typename V>
struct ViewHolder : ViewHolderBase {
ViewHolder(const V &v) : v_(v) {}
V v_;
};
Expand All @@ -40,24 +40,25 @@ class Req {
std::vector<std::shared_ptr<ViewHolderBase>> until_waits_;
};

public:
public:
Req() : record_(std::make_shared<Record>()) {}

MPI_Request &mpi_req() { return record_->req_; }

void wait() {
MPI_Wait(&(record_->req_), MPI_STATUS_IGNORE);
record_->until_waits_
.clear(); // drop any views we're keeping alive until wait()
.clear(); // drop any views we're keeping alive until wait()
}

// keep a reference to this view around until wait() is called
template <typename View> void keep_until_wait(const View &v) {
template <typename View>
void keep_until_wait(const View &v) {
record_->until_waits_.push_back(std::make_shared<ViewHolder<View>>(v));
}

private:
private:
std::shared_ptr<Record> record_;
};

} // namespace KokkosComm
} // namespace KokkosComm
21 changes: 10 additions & 11 deletions src/KokkosComm_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@

namespace KokkosComm {

template <typename T> struct Traits {
template <typename T>
struct Traits {
static_assert(std::is_void_v<T>,
"KokkosComm::Traits not specialized for type");
};

/*! \brief This can be specialized to do custom behavior for a particular view*/
template <KokkosView View> struct Traits<View> {

template <KokkosView View>
struct Traits<View> {
static bool is_contiguous(const View &v) { return v.span_is_contiguous(); }

static auto data_handle(const View &v) { return v.data(); }
Expand Down Expand Up @@ -65,12 +66,12 @@ template <KokkosView View> struct Traits<View> {
};
#if KOKKOSCOMM_ENABLE_MDSPAN

template <Mdspan Span> struct Traits<Span> {

template <Mdspan Span>
struct Traits<Span> {
static auto data_handle(const Span &v) { return v.data_handle(); }

using non_const_packed_view_type = std::vector<typename Span::value_type>;
using packed_view_type = std::vector<typename Span::value_type>;
using packed_view_type = std::vector<typename Span::value_type>;

static auto data_handle(non_const_packed_view_type &v) { return v.data(); }

Expand All @@ -81,7 +82,7 @@ template <Mdspan Span> struct Traits<Span> {
std::array<typename Span::index_type, rank()> first, last;
for (size_t i = 0; i < rank(); ++i) {
first[i] = 0;
last[i] = v.extents().extent(i) - 1;
last[i] = v.extents().extent(i) - 1;
}
return &v[last] - &v[first] + sizeof(typename Span::value_type);
}
Expand All @@ -97,7 +98,6 @@ template <Mdspan Span> struct Traits<Span> {
template <typename ExecSpace>
static void pack(const ExecSpace &space, non_const_packed_view_type &dst,
const Span &src) {

using md_index = std::array<typename Span::index_type, rank()>;

md_index index, ext;
Expand Down Expand Up @@ -137,7 +137,6 @@ template <Mdspan Span> struct Traits<Span> {
template <typename ExecSpace>
static void unpack(const ExecSpace &space, Span &dst,
const non_const_packed_view_type &src) {

using md_index = std::array<typename Span::index_type, rank()>;

md_index index, ext;
Expand Down Expand Up @@ -177,5 +176,5 @@ template <Mdspan Span> struct Traits<Span> {
static constexpr bool is_reference_counted() { return true; }
};

#endif // KOKKOSCOMM_ENABLE_MDSPAN
} // namespace KokkosComm
#endif // KOKKOSCOMM_ENABLE_MDSPAN
} // namespace KokkosComm
6 changes: 2 additions & 4 deletions src/impl/KokkosComm_allocate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ template <typename ExecSpace, KokkosView View>
typename KokkosComm::Traits<View>::non_const_packed_view_type
allocate_packed_for(const ExecSpace &space, const std::string &label,
const View &v) {

using KCT = KokkosComm::Traits<View>;

if constexpr (KCT::rank() == 1) {
Expand All @@ -46,7 +45,6 @@ template <typename ExecSpace, Mdspan View>
typename KokkosComm::Traits<View>::non_const_packed_view_type
allocate_packed_for(const ExecSpace &space, const std::string &label,
const View &v) {

using KCT = KokkosComm::Traits<View>;

if constexpr (KCT::rank() == 1) {
Expand All @@ -58,6 +56,6 @@ allocate_packed_for(const ExecSpace &space, const std::string &label,
"allocate_packed only supports rank-1 views");
}
}
#endif // KOKKOSCOMM_ENABLE_MDSPAN
#endif // KOKKOSCOMM_ENABLE_MDSPAN

} // namespace KokkosComm::Impl
} // namespace KokkosComm::Impl
8 changes: 5 additions & 3 deletions src/impl/KokkosComm_concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

namespace KokkosComm {

template <typename T> concept KokkosView = Kokkos::is_view_v<T>;
template <typename T>
concept KokkosView = Kokkos::is_view_v<T>;

#if KOKKOSCOMM_ENABLE_MDSPAN
template <typename T> concept Mdspan = is_mdspan_v<T>;
template <typename T>
concept Mdspan = is_mdspan_v<T>;
#endif

} // namespace KokkosComm
} // namespace KokkosComm
7 changes: 3 additions & 4 deletions src/impl/KokkosComm_isend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ KokkosComm::Req isend(const ExecSpace &space, const Span &ss, int dest, int tag,
MPI_Comm comm) {
KokkosComm::Req req;

using KCT = KokkosComm::Traits<Span>;
using KCT = KokkosComm::Traits<Span>;
using KCPT = KokkosComm::PackTraits<Span>;

if (KCPT::needs_pack(ss)) {

using Packer = typename KCPT::packer_type;
using Packer = typename KCPT::packer_type;
using MpiArgs = typename Packer::args_type;

MpiArgs args = Packer::pack(space, ss);
Expand All @@ -65,4 +64,4 @@ KokkosComm::Req isend(const ExecSpace &space, const Span &ss, int dest, int tag,
return req;
}

} // namespace KokkosComm::Impl
} // namespace KokkosComm::Impl
15 changes: 9 additions & 6 deletions src/impl/KokkosComm_mdspan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,31 @@
#if KOKKOSCOMM_EXPERIMENTAL_MDSPAN
#include <experimental/mdspan>
namespace KokkosComm::Impl {
template <typename... Args> using mdspan = std::experimental::mdspan<Args...>;
template <typename... Args>
using mdspan = std::experimental::mdspan<Args...>;

template <typename IndexType, std::size_t... Extents>
using extents = std::experimental::extents<IndexType, Extents...>;

template <typename IndexType, std::size_t Rank>
using dextents = std::experimental::dextents<IndexType, Rank>;
} // namespace KokkosComm::Impl
} // namespace KokkosComm::Impl
#else
#include <mdspan>
namespace KokkosComm::Impl {
template <typename... Args> using mdspan = std::mdspan<Args...>;
template <typename... Args>
using mdspan = std::mdspan<Args...>;

template <typename IndexType, std::size_t... Extents>
using extents = std::extents<IndexType, Extents...>;

template <typename IndexType, std::size_t Rank>
using dextents = std::dextents<IndexType, Rank>;
} // namespace KokkosComm::Impl
} // namespace KokkosComm::Impl
#endif

template <typename> struct is_mdspan : std::false_type {};
template <typename>
struct is_mdspan : std::false_type {};

template <typename... Args>
struct is_mdspan<KokkosComm::Impl::mdspan<Args...>> : std::true_type {};
Expand All @@ -54,4 +57,4 @@ static_assert(is_mdspan_v<KokkosComm::Impl::mdspan<
"");
static_assert(!is_mdspan_v<std::vector<char>>, "");

#endif // KOKKOSCOMM_ENABLE_MDSPAN
#endif // KOKKOSCOMM_ENABLE_MDSPAN
14 changes: 7 additions & 7 deletions src/impl/KokkosComm_packer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
namespace KokkosComm::Impl {
namespace Packer {

template <KokkosView View> struct MpiArgs {
template <KokkosView View>
struct MpiArgs {
View view;
MPI_Datatype datatype;
int count;
};

template <KokkosView View> struct DeepCopy {

template <KokkosView View>
struct DeepCopy {
using non_const_packed_view_type =
Kokkos::View<typename View::non_const_data_type, Kokkos::LayoutRight,
typename View::memory_space>;
Expand All @@ -24,7 +25,6 @@ template <KokkosView View> struct DeepCopy {
static args_type allocate_packed_for(const ExecSpace &space,
const std::string &label,
const View &src) {

using KCT = KokkosComm::Traits<View>;

if constexpr (KCT::rank() == 1) {
Expand All @@ -51,7 +51,7 @@ template <KokkosView View> struct DeepCopy {

template <typename ExecSpace>
static args_type pack(const ExecSpace &space, const View &src) {
using KCT = KokkosComm::Traits<non_const_packed_view_type>;
using KCT = KokkosComm::Traits<non_const_packed_view_type>;
args_type args = allocate_packed_for(space, "DeepCopy::pack", src);
Kokkos::deep_copy(space, args.view, src);
return args;
Expand All @@ -64,5 +64,5 @@ template <KokkosView View> struct DeepCopy {
}
};

} // namespace Packer
} // namespace KokkosComm::Impl
} // namespace Packer
} // namespace KokkosComm::Impl
Loading

0 comments on commit 7e44e32

Please sign in to comment.