Skip to content

Commit a968a13

Browse files
authored
Merge pull request #109 from cwpearson/feature/transport
Reorganize for MPI / NCCL transport layers
2 parents 9ea2173 + 7856b43 commit a968a13

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1561
-946
lines changed

.github/workflows/docs-deploy.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# To get started with mdBook see: https://rust-lang.github.io/mdBook/index.html
44
#
55
name: Deploy sphinx site to Pages
6-
run-name: Deploy sphinx site to Pages
76

87
on:
98
# Runs on pushes targeting the default branch

.github/workflows/linux-compileonly.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@ jobs:
6666
cmake --build "$KOKKOS_BUILD" --parallel $(nproc) -t install
6767
- name: Build Kokkos Comm
6868
run: |
69-
cmake -S "$COMM_SRC" -B "$COMM_BUILD" -DCMAKE_CXX_COMPILER="$KOKKOS_SRC/bin/nvcc_wrapper" -DKokkos_ROOT="$KOKKOS_INSTALL" -DCMAKE_BUILD_TYPE=Release
69+
cmake -S "$COMM_SRC" -B "$COMM_BUILD" -DCMAKE_CXX_COMPILER="$KOKKOS_SRC/bin/nvcc_wrapper" -DKokkos_ROOT="$KOKKOS_INSTALL" -DCMAKE_BUILD_TYPE=Release -DKokkosComm_ENABLE_TESTS=ON -DKokkosComm_ENABLE_PERFTESTS=ON
7070
VERBOSE=1 cmake --build "$COMM_BUILD"

.github/workflows/linux.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
COMM_SRC: ${{ github.workspace }}
6363
COMM_BUILD: ${{ github.workspace }}/build
6464
runs-on: ubuntu-latest
65-
timeout-minutes: 5
65+
timeout-minutes: 10
6666
steps:
6767
- name: Install MPI
6868
run: |

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ project(KokkosComm VERSION 0.0.2)
66

77
option(KokkosComm_ENABLE_PERFTESTS "Build KokkosComm perf tests" OFF)
88
option(KokkosComm_ENABLE_TESTS "Build KokkosComm perf tests" OFF)
9+
option(KokkosComm_ENABLE_MPI "Build KokkosComm with MPI transport" ON)
910

1011

1112
## resolve options
1213
set(KOKKOSCOMM_ENABLE_PERFTESTS ${KokkosComm_ENABLE_PERFTESTS} CACHE BOOL "" FORCE)
1314
set(KOKKOSCOMM_ENABLE_TESTS ${KokkosComm_ENABLE_TESTS} CACHE BOOL "" FORCE)
15+
set(KOKKOSCOMM_ENABLE_MPI ${KokkosComm_ENABLE_MPI} CACHE BOOL "" FORCE)
1416

1517
find_package(Kokkos REQUIRED)
1618
find_package(MPI REQUIRED)

cmake/Config.cmake.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ include(CMakeFindDependencyMacro)
88
find_dependency(MPI)
99
find_dependency(Kokkos)
1010

11+
set(KOKKOSCOMM_ENABLE_MPI @KOKKOSCOMM_ENABLE_MPI@)
12+
1113
## FIXME: do we need this?
1214
set(KokkosComm_INCLUDE_DIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@" )
1315
set(KokkosComm_DATA_DIR "@CMAKE_INSTALL_PREFIX@/@RELATIVE_DATA_INSTALL_DIR@" )

cmake/KokkosComm_config.hpp.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@
1919
#define KOKKOSCOMM_VERSION_MAJOR @KOKKOSCOMM_VERSION_MAJOR@
2020
#define KOKKOSCOMM_VERSION_MINOR @KOKKOSCOMM_VERSION_MINOR@
2121
#define KOKKOSCOMM_VERSION_PATCH @KOKKOSCOMM_VERSION_PATCH@
22+
23+
#cmakedefine KOKKOSCOMM_ENABLE_MPI

docs/CONTRIBUTING.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Alternatively, you can use docker/podman: (expects $PWD to be the kokkos-comm tr
2727
.. code-block:: bash
2828
2929
shopt -s globstar
30-
podman run -v $PWD:/src xianpengshen/clang-tools:14 clang-format -i {src,unit_tests,perf_tests}/**/*.[ch]pp
30+
podman run --rm -v ${PWD}:/src ghcr.io/cwpearson/clang-format-14 clang-format -i {src,unit_tests,perf_tests}/**/*.[ch]pp
3131
3232
Site-Specific Documentation
3333
---------------------------

docs/api/core.rst

Lines changed: 73 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,162 +1,118 @@
11
Core
22
====
33

4-
.. list-table:: MPI API Support
5-
:widths: 40 30 15
6-
:header-rows: 1
7-
8-
* - MPI
9-
- ``KokkosComm::``
10-
- ``Kokkos::View``
11-
* - ``MPI_Send``
12-
- ``send`` or ``send(KokkosComm::DefaultCommMode{}, ...)``
13-
- ✓
14-
* - ``MPI_Rsend``
15-
- ``send(KokkosComm::ReadyCommMode{}, ...)``
16-
- ✓
17-
* - ``MPI_Recv``
18-
- ``recv``
19-
- ✓
20-
* - ``MPI_Ssend``
21-
- ``send(KokkosComm::SynchronousCommMode{}, ...)``
22-
- ✓
23-
* - ``MPI_Isend``
24-
- ``isend`` or ``isend(KokkosComm::DefaultCommMode{}, ...)``
25-
- ✓
26-
* - ``MPI_Irsend``
27-
- ``isend(KokkosComm::ReadyCommMode{}, ...)``
28-
- ✓
29-
* - ``MPI_Issend``
30-
- ``isend(KokkosComm::SynchronousCommMode{}, ...)``
31-
- ✓
32-
* - ``MPI_Reduce``
33-
- ``reduce``
34-
- ✓
35-
364
Point-to-point
375
--------------
386

39-
.. cpp:function:: template <CommunicationMode SendMode, KokkosExecutionSpace ExecSpace, KokkosView SendView> \
40-
Req KokkosComm::isend(const ExecSpace &space, const SendView &sv, int dest, int tag, MPI_Comm comm)
7+
.. cpp:namespace:: KokkosComm
418

42-
Wrapper for ``MPI_Isend``, ``MPI_Irsend`` and ``MPI_Issend``.
9+
.. cpp:function:: template <KokkosView SendView, KokkosExecutionSpace ExecSpace = Kokkos::DefaultExecutionSpace, Transport TRANSPORT = DefaultTransport> Req<TRANSPORT> send(Handle<ExecSpace, TRANSPORT> &h, SendView &sv, int dest)
4310

44-
:param mode: The communication mode to use
45-
:param space: The execution space to operate in
46-
:param sv: The data to send
47-
:param dest: the destination rank
48-
:param tag: the MPI tag
49-
:param comm: the MPI communicator
50-
:tparam IsendMode: A communication mode to use, one of: ``KokkosComm::DefaultCommMode``, ``KokkosComm::StandardCommMode``, ``KokkosComm::SynchronousCommMode`` or ``KokkosComm::ReadyCommMode`` (modeled with the ``KokkosComm::CommunicationMode`` concept)
51-
:tparam SendView: A Kokkos::View to send
52-
:tparam ExecSpace: A Kokkos execution space to operate in
53-
:returns: A KokkosComm::Req representing the asynchronous communication and any lifetime-extended views.
11+
Initiates a non-blocking send operation.
5412

55-
.. cpp:function:: template <typename SendMode, KokkosExecutionSpace ExecSpace, KokkosView SendView> \
56-
void KokkosComm::send(const ExecSpace &space, const SendView &sv, int dest, int tag, MPI_Comm comm)
13+
.. warning::
14+
This is not a blocking operation despite being named like ``MPI_Send``.
5715

58-
Wrapper for ``MPI_Send``, ``MPI_Rsend`` and ``MPI_Ssend``.
16+
:tparam SendView: The type of the Kokkos view to send.
17+
:tparam ExecSpace: The execution space to use. Defaults to Kokkos::DefaultExecutionSpace.
18+
:tparam TRANSPORT: The transport mechanism to use. Defaults to DefaultTransport.
5919

60-
:param mode: The communication mode to use
61-
:param space: The execution space to operate in
62-
:param sv: The data to send
63-
:param dest: the destination rank
64-
:param tag: the MPI tag
65-
:param comm: the MPI communicator
66-
:tparam SendMode: A communication mode to use, one of: ``KokkosComm::DefaultCommMode``, ``KokkosComm::StandardCommMode``, ``KokkosComm::SynchronousCommMode`` or ``KokkosComm::ReadyCommMode`` (modeled with the ``KokkosComm::CommunicationMode`` concept)
67-
:tparam SendView: A Kokkos::View to send
68-
:tparam ExecSpace: A Kokkos execution space to operate in
20+
:param h: A handle to the execution space and transport mechanism.
21+
:param sv: The Kokkos view to send.
22+
:param dest: The destination rank.
6923

70-
.. cpp:function:: template <KokkosExecutionSpace ExecSpace, KokkosView RecvView> \
71-
void KokkosComm::recv(const ExecSpace &space, RecvView &rv, int src, int tag, MPI_Comm comm)
24+
:return: A request object for the non-blocking send operation.
7225

73-
MPI_Recv wrapper
26+
.. cpp:function:: template <KokkosView SendView, KokkosExecutionSpace ExecSpace = Kokkos::DefaultExecutionSpace, Transport TRANSPORT = DefaultTransport> Req<TRANSPORT> send(SendView &sv, int dest)
7427

75-
:param space: The execution space to operate in
76-
:param srv: The data to recv
77-
:param src: the source rank
78-
:param tag: the MPI tag
79-
:param comm: the MPI communicator
80-
:tparam Recv: A Kokkos::View to send
81-
:tparam ExecSpace: A Kokkos execution space to operate in
28+
Initiates a non-blocking send operation using a default handle.
8229

30+
.. warning::
31+
This is not a blocking operation despite being named like ``MPI_Send``.
8332

84-
Collective
85-
----------
33+
:tparam SendView: The type of the Kokkos view to send.
34+
:tparam ExecSpace: The execution space to use. Defaults to Kokkos::DefaultExecutionSpace.
35+
:tparam TRANSPORT: The transport mechanism to use. Defaults to DefaultTransport.
8636

87-
.. cpp:function:: template <KokkosExecutionSpace ExecSpace, KokkosView SendView, KokkosView RecvView> \
88-
void KokkosComm::reduce(const ExecSpace &space, const SendView &sv, const RecvView &rv, MPI_Op op, int root, MPI_Comm comm)
37+
:param sv: The Kokkos view to send.
38+
:param dest: The destination rank.
8939

90-
MPI_Reduce wrapper
40+
:return: A request object for the non-blocking send operation.
9141

92-
:param space: The execution space to operate in
93-
:param sv: The data to send
94-
:param rv: The view to receive into
95-
:param op: The MPI_Op to use in the reduction
96-
:param root: The root rank for the reduction
97-
:param comm: the MPI communicator
98-
:tparam SendView: A Kokkos::View to send
99-
:tparam RecvView: A Kokkos::View to recv
100-
:tparam ExecSpace: A Kokkos execution space to operate in
42+
Example usage:
10143

44+
.. literalinclude:: core_send.cpp
45+
:language: cpp
10246

103-
.. cpp:function:: template <KokkosExecutionSpace ExecSpace, KokkosView SendView, KokkosView RecvView> \
104-
void KokkosComm::allgather(const ExecSpace &space, const SendView &sv, const RecvView &rv, MPI_Comm comm)
10547

106-
MPI_Allgather wrapper
10748

108-
:param space: The execution space to operate in
109-
:param sv: The data to send
110-
:param rv: The view to receive into
111-
:param comm: the MPI communicator
112-
:tparam SendView: A Kokkos::View to send. Contiguous and rank less than 2.
113-
:tparam RecvView: A Kokkos::View to recv. Contiguous and rank 1.
114-
:tparam ExecSpace: A Kokkos execution space to operate in
49+
.. cpp:function:: template <KokkosView RecvView, KokkosExecutionSpace ExecSpace = Kokkos::DefaultExecutionSpace, Transport TRANSPORT = DefaultTransport> Req<TRANSPORT> recv(Handle<ExecSpace, TRANSPORT> &h, RecvView &rv, int src)
11550

116-
If ``sv`` is a rank-0 view, the value from the jth rank will be placed in index j of ``rv``.
51+
Initiates a non-blocking receive operation.
11752

118-
Related Types
119-
-------------
53+
.. warning::
54+
This is not a blocking operation despite being named like ``MPI_Recv``.
55+
56+
:tparam RecvView: The type of the Kokkos view for receiving data.
57+
:tparam ExecSpace: The execution space where the operation will be performed. Defaults to `Kokkos::DefaultExecutionSpace`.
58+
:tparam TRANSPORT: The transport mechanism to be used. Defaults to `DefaultTransport`.
59+
60+
:param h: A handle to the execution space and transport mechanism.
61+
:param rv: The Kokkos view where the received data will be stored.
62+
:param src: The source rank from which to receive data.
63+
64+
:return: A request object of type `Req<TRANSPORT>` representing the non-blocking receive operation.
65+
66+
This function initiates a non-blocking receive operation using the specified execution space and transport mechanism. The data will be received into the provided view from the specified source rank and message tag. The function returns a request object that can be used to check the status of the receive operation or to wait for its completion.
12067

121-
Communication Modes
122-
^^^^^^^^^^^^^^^^^^^
68+
Example usage:
12369

124-
Structures to specify the mode of an operation. Buffered mode is not supported.
70+
.. literalinclude:: core_recv.cpp
71+
:language: cpp
12572

126-
.. cpp:struct:: KokkosComm::StandardCommMode
12773

128-
Let the MPI implementation decide whether outgoing messages will be buffered. Send operations can be started whether or not a matching receive has been started. They may complete before a matching receive begins. Standard mode is non-local: successful completion of the send operation may depend on the occurrence of a matching receive.
12974

130-
.. cpp:struct:: KokkosComm::SynchronousCommMode
13175

132-
Send operations complete successfully only if a matching receive is started, and the receive operation has started to receive the message sent.
13376

134-
.. cpp:struct:: KokkosComm::ReadyCommMode
77+
.. cpp:function:: template <KokkosView RecvView, KokkosExecutionSpace ExecSpace = Kokkos::DefaultExecutionSpace, Transport TRANSPORT = DefaultTransport> Req<TRANSPORT> recv(RecvView &rv, int src)
13578

136-
Send operations may be started only if the matching receive is already started.
79+
Initiates a non-blocking receive operation using a default handle.
13780

138-
.. cpp:struct:: KokkosComm::DefaultCommMode
81+
.. warning::
82+
This is not a blocking operation despite being named like ``MPI_Recv``.
13983

140-
The default mode is aliased as ``Standard`` but lets users override the behavior of operations at compile-time using the ``KOKKOSCOMM_FORCE_SYNCHRONOUS_MODE`` pre-processor definition. The latter forces ``Synchronous`` mode for all "default-mode" operations, which can be helpful for debugging purposes, e.g., asserting that the communication scheme is correct.
84+
:tparam RecvView: The type of the Kokkos view for receiving data.
85+
:tparam ExecSpace: The execution space where the operation will be performed. Defaults to `Kokkos::DefaultExecutionSpace`.
86+
:tparam TRANSPORT: The transport mechanism to be used. Defaults to `DefaultTransport`.
14187

88+
:param rv: The Kokkos view where the received data will be stored.
89+
:param src: The source rank from which to receive data.
14290

143-
Requests
144-
^^^^^^^^
91+
:return: A request object of type `Req<TRANSPORT>` representing the non-blocking receive operation.
14592

146-
.. cpp:class:: KokkosComm::Req
14793

148-
A wrapper around an MPI_Request that can also extend the lifetime of Views.
94+
Collective
95+
----------
96+
97+
.. cpp:namespace:: KokkosComm
98+
99+
.. cpp:function:: template <KokkosExecutionSpace ExecSpace = Kokkos::DefaultExecutionSpace, Transport TRANSPORT = DefaultTransport> void barrier(Handle<ExecSpace, TRANSPORT> &&h)
100+
101+
A function to create a barrier using the given execution space and transport handle.
149102

150-
.. cpp:function:: MPI_Request &KokkosComm::Req::mpi_req()
103+
:tparam ExecSpace: The execution space to be used. Defaults to `Kokkos::DefaultExecutionSpace`.
104+
:tparam TRANSPORT: The transport mechanism to be used. Defaults to `DefaultTransport`.
105+
:param h: A handle of type `Handle<ExecSpace, TRANSPORT>` to be forwarded to the barrier implementation.
151106

152-
Retrieve a reference to the held MPI_Request.
153107

154-
.. cpp:function:: void KokkosComm::Req::wait()
155108

156-
Call MPI_Wait on the held MPI_Request and drop copies of any previous arguments to Req::keep_until_wait().
109+
Related Types
110+
-------------
111+
112+
.. cpp:namespace:: KokkosComm
113+
114+
.. cpp:class:: template <Transport TRANSPORT = DefaultTransport> Req
157115

158-
.. cpp:function:: template<typename View> \
159-
void KokkosComm::Req::keep_until_wait(const View &v)
116+
A template class to handle requests with different transport types.
160117

161-
Extend the lifetime of v at least until Req::wait() is called.
162-
This is useful to prevent a View from being destroyed during an asynchronous MPI operation.
118+
:tparam TRANSPORT: The type of transport. Defaults to :cpp:enumerator:`KokkosComm::DefaultTransport`.

docs/api/core_recv.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Handle<> handle;
2+
Kokkos::View<double*> recv_view("recv_view", 100);
3+
auto req = recv(handle, recv_view, 1/*src*/);
4+
KokkosComm::wait(req);

docs/api/core_send.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <Kokkos_Comm.hpp>
2+
3+
// Define the execution space and transport
4+
using ExecSpace = Kokkos::DefaultExecutionSpace;
5+
using Transport = DefaultTransport;
6+
7+
// Create a Kokkos view
8+
Kokkos::View<double*> data("data", 100);
9+
10+
// Fill the view with some data
11+
Kokkos::parallel_for("fill_data", Kokkos::RangePolicy<ExecSpace>(0, 100), KOKKOS_LAMBDA(int i) {
12+
data(i) = static_cast<double>(i);
13+
});
14+
15+
// Destination rank and message tag
16+
int dest = 1;
17+
18+
// Create a handle
19+
KokkosComm::Handle<> handle; // Same as Handle<Execspace, Transport>
20+
21+
// Initiate a non-blocking send with a handle
22+
auto req1 = send(handle, data, dest);
23+
24+
// Initiate a non-blocking send with a default handle
25+
auto req2 = send(data, dest);
26+
27+
// Wait for the requests to complete (assuming a wait function exists)
28+
KokkosComm::wait(req1);
29+
KokkosComm::wait(req2);

0 commit comments

Comments
 (0)