Skip to content

Add communication modes to specialize send routines#30

Merged
cwpearson merged 35 commits intokokkos:developfrom
dssgabriel:comm-modes
May 8, 2024
Merged

Add communication modes to specialize send routines#30
cwpearson merged 35 commits intokokkos:developfrom
dssgabriel:comm-modes

Conversation

@dssgabriel
Copy link
Copy Markdown
Collaborator

This PR adds an enum to allow users to specify the communication mode of send routines (both blocking and non-blocking) as proposed by @cedricchevalier19 in #10. The CommMode template parameter is only used for the user-facing API: there are dedicated lean wrappers for each underlying MPI call in the Impl namespace (as suggested by @cwpearson, also in #10). Relevant unit tests have been added too.

The changes fulfill the requirements for supporting rsend and ssend from #10.

We do not support "Buffered" mode (at least for now), as it requires the user to manually attach a buffer using MPI_Buffer_attach (see documentation here).

@dssgabriel dssgabriel added the C-enhancement Category: an enhancement label Apr 11, 2024
@dssgabriel dssgabriel self-assigned this Apr 11, 2024
@dssgabriel dssgabriel linked an issue Apr 11, 2024 that may be closed by this pull request
9 tasks
@dssgabriel dssgabriel removed a link to an issue Apr 11, 2024
9 tasks
@dssgabriel
Copy link
Copy Markdown
Collaborator Author

We may want to draft this for now as I haven't updated the corresponding documentation yet.

Copy link
Copy Markdown
Member

@cedricchevalier19 cedricchevalier19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a quick look, but I think it makes more sense to group all the sendrecv tests in the same file.

You can define a function that take the comm "mode" as a template parameters and have tests that simplify set this parameter.

Comment thread unit_tests/test_irsendrecv.cpp Outdated
Comment thread unit_tests/test_rsendrecv.cpp Outdated
Comment thread src/KokkosComm_mode.hpp Outdated
Comment thread src/KokkosComm_mode.hpp Outdated
Comment thread src/KokkosComm.hpp Outdated
Comment thread src/KokkosComm.hpp Outdated
Comment thread src/KokkosComm.hpp Outdated
@dssgabriel dssgabriel marked this pull request as draft April 11, 2024 15:10
@dssgabriel dssgabriel marked this pull request as ready for review April 12, 2024 16:10
Comment thread docs/api/core.rst Outdated
Comment thread src/impl/KokkosComm_send.hpp Outdated
@dssgabriel
Copy link
Copy Markdown
Collaborator Author

The PR now does the communication mode dispatch in the Impl namespace to avoid code duplication.

It now also lets users override the default communication mode to alias CommMode::Synchronous instead of CommMode::Standard (mainly for debugging purposes) using the KOKKOSCOMM_FORCE_SYNCHRONOUS_SEND_MODE environment variable.

Comment thread docs/api/core.rst Outdated
Comment thread docs/api/core.rst Outdated
Comment thread docs/api/core.rst Outdated
Comment thread src/impl/KokkosComm_isend.hpp Outdated
Comment thread docs/api/core.rst Outdated
Comment thread docs/api/core.rst Outdated
Comment thread src/KokkosComm_comm_mode.hpp Outdated
Comment on lines +52 to 76
if constexpr (SendMode == CommMode::Standard) {
MPI_Isend(KCT::data_handle(args.view), args.count, args.datatype, dest,
tag, comm, &req.mpi_req());
} else if constexpr (SendMode == CommMode::Ready) {
MPI_Irsend(KCT::data_handle(args.view), args.count, args.datatype, dest,
tag, comm, &req.mpi_req());
} else if constexpr (SendMode == CommMode::Synchronous) {
MPI_Issend(KCT::data_handle(args.view), args.count, args.datatype, dest,
tag, comm, &req.mpi_req());
} else if constexpr (SendMode == CommMode::Default) {
#ifdef KOKKOSCOMM_FORCE_SYNCHRONOUS_MODE
MPI_Issend(KCT::data_handle(args.view), args.count, args.datatype, dest,
tag, comm, &req.mpi_req());
#else
MPI_Isend(KCT::data_handle(args.view), args.count, args.datatype, dest,
tag, comm, &req.mpi_req());
#endif
}
req.keep_until_wait(args.view);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather define a lambda so you don't have to repeat the logic for tyes that need packing or not.

Comment thread src/impl/KokkosComm_send.hpp
@dssgabriel
Copy link
Copy Markdown
Collaborator Author

@masterleinad Can you tell me if the lambda definitions look ok? Using auto everywhere seems to work, but I am not very proficient in C++ and not sure this is the best way to do it... 😅
Also, do I need to mark the lambdas as constexpr to ensure the path is correctly selected at compile-time?

Comment thread src/impl/KokkosComm_isend.hpp Outdated
masterleinad
masterleinad previously approved these changes Apr 19, 2024
Copy link
Copy Markdown
Collaborator

@masterleinad masterleinad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK to me.

dssgabriel and others added 11 commits April 19, 2024 17:06
MPI's `Buffered` mode requires the user to attach a buffer using `MPI_Buffer_attach`. We do not want to bother finding a way to support this cleanly for now, hence its removal.
Remove `static_assert` from unreachable path
Co-authored-by: Cédric Chevalier <cedric.chevalier019@proton.me>
Renamed the enum to `CommMode` to better reflect what it is.
Renamed the `Default` variant to `Standard` to match wording in the MPI spec.
Added comments to explain the semantics of each communication mode.
cwpearson and others added 9 commits April 19, 2024 17:12
If send operations do not specify a communication mode, use the default behavior.
If the `KokkosComm_FORCE_SYNCHRONOUS_MODE` is defined (through the pre-processor), the default behavior is to use `Synchronous` mode.
Otherwise, it defaults to `Standard` mode.
Co-authored-by: Daniel Arndt <arndtd@ornl.gov>
Removes reference-captures and adds explicit typing.
Comment thread unit_tests/test_isendrecv.cpp
@dssgabriel
Copy link
Copy Markdown
Collaborator Author

I rebased the latest commits from develop onto this branch.

After discussing with @cedricchevalier19, we believe it's simpler to skip tests for ready-mode send operations for now. We should merge this PR and open an issue to fix ready-send tests while we wait for #32 to be merged.

@cwpearson
Copy link
Copy Markdown
Collaborator

Works for me, sorry for the delay on #32. Open such an issue and then we will merge once conflicts are resolved!

@dssgabriel
Copy link
Copy Markdown
Collaborator Author

Issue #43 for the skipped tests is opened. I think we can merge this now 👍

@janciesko janciesko requested a review from devreal May 6, 2024 22:44
@cwpearson cwpearson merged commit 95045cf into kokkos:develop May 8, 2024
@dssgabriel dssgabriel deleted the comm-modes branch September 24, 2025 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-enhancement Category: an enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants