Skip to content

Commit 901ccc7

Browse files
refactor!: add more requirements to the CommunicationSpace concept (#188)
* refactor!: rework & improve communication space concept Signed-off-by: Gabriel Dos Santos <[email protected]> * chore: format + fix CommSpace typo in unit test Signed-off-by: Gabriel Dos Santos <[email protected]> * Fix missing MpiSpace Signed-off-by: Cedric Chevalier <[email protected]> * Fix format Signed-off-by: Cedric Chevalier <[email protected]> * Update documentation Signed-off-by: Cedric Chevalier <[email protected]> --------- Signed-off-by: Gabriel Dos Santos <[email protected]> Signed-off-by: Cedric Chevalier <[email protected]> Co-authored-by: Cédric Chevalier <[email protected]>
1 parent 785c85a commit 901ccc7

29 files changed

+149
-133
lines changed

docs/dev/impl_comm_space.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ For example, for the MPI communication space, we define the following:
2020
2121
namespace KokkosComm {
2222
23-
struct Mpi {
24-
static auto world_size() noexcept -> int { /* ... */ }
25-
static auto world_rank() noexcept -> int { /* ... */ }
23+
struct MpiSpace {
24+
...
2625
};
2726
2827
template <>
@@ -31,7 +30,6 @@ For example, for the MPI communication space, we define the following:
3130
} // end KokkosComm
3231
3332
34-
Notice that ``Mpi`` has two static methods, but that these methods are not required. The main point is that ``struct Mpi`` exists.
3533
To let core API functions know that your communication space is something KokkosComm can use to dispatch messages, you also need to declare the ``Impl::is_communication_space`` specialization using the ``CommunicationSpace`` concept.
3634

3735

@@ -71,7 +69,7 @@ For example, for the MPI communication space request, we define the following:
7169
namespace KokkosComm {
7270
7371
template <>
74-
class Req<Mpi> { /* ... */ };
72+
class Req<MpiSpace> { /* ... */ };
7573
7674
} // end KokkosComm
7775
@@ -103,7 +101,7 @@ For example, for the MPI communication space, we create a partial specialization
103101
namespace KokkosComm::Impl {
104102
105103
template <KokkosView RecvView, KokkosExecutionSpace ExecSpace>
106-
struct Recv<RecvView, ExecSpace, Mpi> { /* ... */ };
104+
struct Recv<RecvView, ExecSpace, MpiSpace> { /* ... */ };
107105
108106
} // end KokkosComm::Impl
109107

src/KokkosComm/concepts.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ template <typename T>
2727
concept KokkosExecutionSpace = Kokkos::is_execution_space_v<T>;
2828

2929
template <typename T>
30-
concept CommunicationSpace = KokkosComm::Impl::is_communication_space<T>::value;
30+
concept CommunicationSpace = requires {
31+
KokkosComm::Impl::is_communication_space<T>::value;
32+
typename T::communication_space;
33+
typename T::handle_type;
34+
typename T::request_type;
35+
typename T::datatype_type;
36+
typename T::reduction_op_type;
37+
typename T::rank_type;
38+
};
3139

3240
template <typename T>
3341
concept ReductionOperator = KokkosComm::Impl::is_reduction_operator<T>::value;

src/KokkosComm/fwd.hpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@
99

1010
namespace KokkosComm {
1111

12-
// NCCL backend also implicitly declares MPI
1312
#if defined(KOKKOSCOMM_ENABLE_NCCL)
1413
namespace Experimental {
15-
class Nccl;
16-
} // namespace Experimental
17-
class Mpi;
18-
using DefaultCommunicationSpace = Experimental::Nccl;
19-
using FallbackCommunicationSpace = Mpi;
14+
struct NcclSpace;
15+
}
16+
// NCCL backend also declares the MPI space as fallback
17+
struct MpiSpace;
18+
19+
using DefaultCommunicationSpace = Experimental::NcclSpace;
20+
using FallbackCommunicationSpace = MpiSpace;
2021
#elif defined(KOKKOSCOMM_ENABLE_MPI)
21-
class Mpi;
22-
using DefaultCommunicationSpace = Mpi;
23-
using FallbackCommunicationSpace = Mpi;
22+
struct MpiSpace;
23+
using DefaultCommunicationSpace = MpiSpace;
24+
using FallbackCommunicationSpace = MpiSpace;
2425
#else
2526
#error at least one communication space must be enabled
2627
#endif

src/KokkosComm/mpi/allgather.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
namespace KokkosComm::mpi {
1818

1919
template <KokkosExecutionSpace ExecSpace, KokkosView SView, KokkosView RView>
20-
auto iallgather(const ExecSpace &space, const SView sv, RView rv, MPI_Comm comm) -> Req<Mpi> {
20+
auto iallgather(const ExecSpace &space, const SView sv, RView rv, MPI_Comm comm) -> Req<MpiSpace> {
2121
using ST = typename SView::non_const_value_type;
2222
using RT = typename RView::non_const_value_type;
2323
static_assert(std::is_same_v<ST, RT>, "KokkosComm::mpi::iallgather: View value types must be identical");
@@ -29,7 +29,7 @@ auto iallgather(const ExecSpace &space, const SView sv, RView rv, MPI_Comm comm)
2929
// Sync: Work in space may have been used to produce view data.
3030
space.fence("fence before non-blocking all-gather");
3131

32-
Req<Mpi> req;
32+
Req<MpiSpace> req;
3333
// All ranks send/recv same count
3434
MPI_Iallgather(data_handle(sv), span(sv), Impl::mpi_type_v<ST>, data_handle(rv), span(sv), Impl::mpi_type_v<RT>, comm,
3535
&req.mpi_request());

src/KokkosComm/mpi/alltoall.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
namespace KokkosComm::mpi {
1919

2020
template <KokkosExecutionSpace ExecSpace, KokkosView SView, KokkosView RView>
21-
auto ialltoall(const ExecSpace &space, const SView sv, RView rv, int count, MPI_Comm comm) -> Req<Mpi> {
21+
auto ialltoall(const ExecSpace &space, const SView sv, RView rv, int count, MPI_Comm comm) -> Req<MpiSpace> {
2222
using ST = typename SView::non_const_value_type;
2323
using RT = typename RView::non_const_value_type;
2424
static_assert(std::is_same_v<ST, RT>, "KokkosComm::mpi::ialltoall: View value types must be identical");
@@ -30,7 +30,7 @@ auto ialltoall(const ExecSpace &space, const SView sv, RView rv, int count, MPI_
3030
// Sync: Work in space may have been used to produce view data.
3131
space.fence("fence before non-blocking all-gather");
3232

33-
Req<Mpi> req;
33+
Req<MpiSpace> req;
3434
// All ranks send/recv same count
3535
MPI_Ialltoall(data_handle(sv), count, Impl::mpi_type_v<ST>, data_handle(rv), count, Impl::mpi_type_v<RT>, comm,
3636
&req.mpi_request());

src/KokkosComm/mpi/broadcast.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
namespace KokkosComm::mpi {
1818

1919
template <KokkosExecutionSpace ExecSpace, KokkosView View>
20-
auto ibroadcast(const ExecSpace& space, View& v, int root, MPI_Comm comm) -> Req<Mpi> {
20+
auto ibroadcast(const ExecSpace& space, View& v, int root, MPI_Comm comm) -> Req<MpiSpace> {
2121
using T = typename View::non_const_value_type;
2222
Kokkos::Tools::pushRegion("KokkosComm::mpi::ibroadcast");
2323
fail_if(!is_contiguous(v), "KokkosComm::mpi::ibroadcast: unimplemented for non-contiguous views");
2424

2525
// Sync: Work in space may have been used to produce view data.
2626
space.fence("fence before non-blocking broadcast");
2727

28-
Req<Mpi> req;
28+
Req<MpiSpace> req;
2929
MPI_Ibcast(data_handle(v), span(v), Impl::mpi_type_v<T>, root, comm, &req.mpi_request());
3030
req.extend_view_lifetime(v);
3131

src/KokkosComm/mpi/channel.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Channel {
5757

5858
void wait() {
5959
Kokkos::Tools::pushRegion("KokkosComm::Channel::wait");
60-
std::vector<Req<Mpi>> reqs;
60+
std::vector<Req<MpiSpace>> reqs;
6161
reqs.reserve(send_reqs_.size() + recv_reqs_.size());
6262
reqs.insert(reqs.end(), send_reqs_.begin(), send_reqs_.end());
6363
reqs.insert(reqs.end(), recv_reqs_.begin(), recv_reqs_.end());
@@ -66,12 +66,12 @@ class Channel {
6666
}
6767

6868
private:
69-
std::vector<Req<Mpi>> send_reqs_; // Queue for send requests
70-
std::vector<Req<Mpi>> recv_reqs_; // Queue for receive requests
71-
int dest_rank_; // Destination rank for send
72-
int src_rank_; // Source rank for receive
73-
int tag_; // MPI tag
74-
MPI_Comm comm_; // MPI communicator
69+
std::vector<Req<MpiSpace>> send_reqs_; // Queue for send requests
70+
std::vector<Req<MpiSpace>> recv_reqs_; // Queue for receive requests
71+
int dest_rank_; // Destination rank for send
72+
int src_rank_; // Source rank for receive
73+
int tag_; // MPI tag
74+
MPI_Comm comm_; // MPI communicator
7575
};
7676

7777
} // namespace KokkosComm

src/KokkosComm/mpi/handle.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ namespace KokkosComm {
2020
- post-wait
2121
*/
2222
template <KokkosExecutionSpace ExecSpace>
23-
class Handle<ExecSpace, Mpi> {
23+
class Handle<ExecSpace, MpiSpace> {
2424
public:
2525
using execution_space = ExecSpace;
26-
using transport_type = Mpi;
26+
using transport_type = MpiSpace;
2727
using size_type = int;
2828

2929
explicit Handle(const execution_space &space, MPI_Comm comm) : space_(space), comm_(comm) {}

src/KokkosComm/mpi/irecv.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ namespace Impl {
1818

1919
// Recv implementation for Mpi
2020
template <KokkosExecutionSpace ExecSpace, KokkosView RecvView>
21-
struct Recv<RecvView, ExecSpace, Mpi> {
22-
static Req<Mpi> execute(Handle<ExecSpace, Mpi> &h, const RecvView &rv, int src) {
21+
struct Recv<RecvView, ExecSpace, MpiSpace> {
22+
static Req<MpiSpace> execute(Handle<ExecSpace, MpiSpace> &h, const RecvView &rv, int src) {
2323
using KCPT = KokkosComm::PackTraits<RecvView>;
2424
using Packer = typename KCPT::packer_type;
2525
using Args = typename Packer::args_type;
2626

2727
const ExecSpace &space = h.space();
2828

29-
Req<Mpi> req;
29+
Req<MpiSpace> req;
3030
if (KokkosComm::is_contiguous(rv)) {
3131
space.fence("fence before irecv");
3232
MPI_Irecv(KokkosComm::data_handle(rv), KokkosComm::span(rv), mpi_type_v<typename RecvView::value_type>, src,

src/KokkosComm/mpi/isend.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace KokkosComm {
2020
namespace Impl {
2121

2222
template <KokkosExecutionSpace ExecSpace, KokkosView SendView, mpi::CommunicationMode SendMode>
23-
Req<Mpi> isend_impl(Handle<ExecSpace, Mpi> &h, const SendView &sv, int dest, int tag, SendMode) {
23+
Req<MpiSpace> isend_impl(Handle<ExecSpace, MpiSpace> &h, const SendView &sv, int dest, int tag, SendMode) {
2424
auto mpi_isend_fn = [](void *mpi_view, int mpi_count, MPI_Datatype mpi_datatype, int mpi_dest, int mpi_tag,
2525
MPI_Comm mpi_comm, MPI_Request *mpi_req) {
2626
if constexpr (std::is_same_v<SendMode, mpi::CommModeStandard>) {
@@ -34,7 +34,7 @@ Req<Mpi> isend_impl(Handle<ExecSpace, Mpi> &h, const SendView &sv, int dest, int
3434
}
3535
};
3636

37-
Req<Mpi> req;
37+
Req<MpiSpace> req;
3838
if (KokkosComm::is_contiguous(sv)) {
3939
h.space().fence("fence before isend");
4040
mpi_isend_fn(KokkosComm::data_handle(sv), KokkosComm::span(sv), mpi_type_v<typename SendView::value_type>, dest,
@@ -55,8 +55,8 @@ Req<Mpi> isend_impl(Handle<ExecSpace, Mpi> &h, const SendView &sv, int dest, int
5555

5656
// Implementation of KokkosComm::Send
5757
template <KokkosExecutionSpace ExecSpace, KokkosView SendView>
58-
struct Send<SendView, ExecSpace, Mpi> {
59-
static Req<Mpi> execute(Handle<ExecSpace, Mpi> &h, const SendView &sv, int dest) {
58+
struct Send<SendView, ExecSpace, MpiSpace> {
59+
static Req<MpiSpace> execute(Handle<ExecSpace, MpiSpace> &h, const SendView &sv, int dest) {
6060
return isend_impl<ExecSpace, SendView>(h, sv, dest, POINTTOPOINT_TAG, mpi::DefaultCommMode{});
6161
}
6262
};
@@ -65,12 +65,12 @@ struct Send<SendView, ExecSpace, Mpi> {
6565
namespace mpi {
6666

6767
template <KokkosExecutionSpace ExecSpace, KokkosView SendView, CommunicationMode SendMode>
68-
Req<Mpi> isend(Handle<ExecSpace, Mpi> &h, const SendView &sv, int dest, int tag, SendMode) {
68+
Req<MpiSpace> isend(Handle<ExecSpace, MpiSpace> &h, const SendView &sv, int dest, int tag, SendMode) {
6969
return KokkosComm::Impl::isend_impl<ExecSpace, SendView>(h, sv, dest, tag, SendMode{});
7070
}
7171

7272
template <KokkosExecutionSpace ExecSpace, KokkosView SendView>
73-
Req<Mpi> isend(Handle<ExecSpace, Mpi> &h, const SendView &sv, int dest, int tag) {
73+
Req<MpiSpace> isend(Handle<ExecSpace, MpiSpace> &h, const SendView &sv, int dest, int tag) {
7474
return isend<ExecSpace, SendView>(h, sv, dest, tag, DefaultCommMode{});
7575
}
7676

0 commit comments

Comments
 (0)