Core¶
Point-to-point¶
Send¶
Warning
This is not a blocking operation despite being named like MPI_Send.
-
template<KokkosView SendView, KokkosExecutionSpace ExecSpace = Kokkos::DefaultExecutionSpace, CommunicationSpace CommSpace = DefaultCommunicationSpace>
auto send(Handle<ExecSpace, CommSpace> &h, SendView &sv, int dest) -> Request<CommSpace>¶ Initiates a non-blocking send operation.
- Template Parameters:
SendView – The type of the Kokkos view to send.
ExecSpace – The execution space to use. Defaults to
Kokkos::DefaultExecutionSpace.CommSpace – The communication backend to use. Defaults to
DefaultCommunicationSpace.
- Parameters:
h – A handle to the execution space and transport mechanism.
sv – The Kokkos view to send.
dest – The destination rank.
- Returns:
A request object of type
Request<CommSpace>representing the non-blocking send operation.
-
template<KokkosView SendView, KokkosExecutionSpace ExecSpace = Kokkos::DefaultExecutionSpace, CommunicationSpace CommSpace = DefaultCommunicationSpace>
auto send(SendView &sv, int dest) -> Request<CommSpace>¶ Initiates a non-blocking send operation using a default handle.
- Template Parameters:
SendView – The type of the Kokkos view to send.
ExecSpace – The execution space to use. Defaults to
Kokkos::DefaultExecutionSpace.CommSpace – The communication backend to use. Defaults to
DefaultCommunicationSpace.
- Parameters:
sv – The Kokkos view to send.
dest – The destination rank.
- Returns:
A request object of type
Request<CommSpace>representing the non-blocking send operation.
Example usage:
#include "KokkosComm/KokkosComm.hpp"
// Define the execution space and transport
using ExecSpace = Kokkos::DefaultExecutionSpace;
using CommSpace = DefaultCommunicationSpace;
// Create a Kokkos view
Kokkos::View<double*> data("data", 100);
// Fill the view with some data
Kokkos::parallel_for("fill_data", Kokkos::RangePolicy<ExecSpace>(0, 100), KOKKOS_LAMBDA(int i) {
data(i) = static_cast<double>(i);
});
// Destination rank
int dest = 1;
// Create a handle
KokkosComm::Handle<> handle; // Same as Handle<Execspace, CommSpace>
// Initiate a non-blocking send with a handle
auto req1 = send(handle, data, dest);
// Initiate a non-blocking send with a default handle
auto req2 = send(data, dest);
// Wait for the requests to complete (assuming a wait function exists)
KokkosComm::wait(req1);
KokkosComm::wait(req2);
Receive¶
Warning
This is not a blocking operation despite being named like MPI_Recv.
-
template<KokkosView RecvView, KokkosExecutionSpace ExecSpace = Kokkos::DefaultExecutionSpace, CommunicationSpace CommSpace = DefaultCommunicationSpace>
auto recv(Handle<ExecSpace, CommSpace> &h, RecvView &sv, int dest) -> Request<CommSpace>¶ Initiates a non-blocking receive operation.
- Template Parameters:
RecvView – The type of the Kokkos view for receiving data.
ExecSpace – The execution space where the operation will be performed. Defaults to
Kokkos::DefaultExecutionSpace.CommSpace – The communication backend to use. Defaults to
DefaultCommunicationSpace.
- Parameters:
h – A handle to the execution space and transport mechanism.
rv – The Kokkos view where the received data will be stored.
src – The source rank from which to receive data.
- Returns:
A request object of type
Request<CommSpace>representing the non-blocking receive operation.
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.
-
template<KokkosView RecvView, KokkosExecutionSpace ExecSpace = Kokkos::DefaultExecutionSpace, CommunicationSpace CommSpace = DefaultCommunicationSpace>
auto recv(RecvView &sv, int dest) -> Request<CommSpace>¶ Initiates a non-blocking receive operation using a default handle.
- Template Parameters:
RecvView – The type of the Kokkos view for receiving data.
ExecSpace – The execution space where the operation will be performed. Defaults to Kokkos::DefaultExecutionSpace.
CommSpace – The communication backend to use. Defaults to
DefaultCommunicationSpace.
- Parameters:
rv – The Kokkos view where the received data will be stored.
src – The source rank from which to receive data.
- Returns:
A request object of type
Request<CommSpace>representing the non-blocking receive operation.
Example usage:
#include "KokkosComm/KokkosComm.hpp"
// Define the execution space and transport
using ExecSpace = Kokkos::DefaultExecutionSpace;
using CommSpace = DefaultCommunicationSpace;
// Source rank
int src = 1;
// Create a handle
KokkosComm::Handle<> handle; // Same as Handle<Execspace, CommSpace>
// Allocate a view to receive the data
Kokkos::View<double*> data("recv_view", 100);
// Initiate a non-blocking receive with a handle
auto req1 = recv(handle, data, src);
// Initiate a non-blocking receive with a default handle
auto req2 = recv(data, src);
// Wait for the requests to complete (assuming a wait function exists)
KokkosComm::wait(req1);
KokkosComm::wait(req2);
Collectives¶
Important
Collective operations act element-wise on the input Views. Multi-dimensional Views are treated as a logically flattened sequence of values, and the reduction is applied over that sequence. All participating Views must have identical extents; mismatched shapes result in undefined behavior.
The reduction operator must be associative, but ordering of partial combinations is not guaranteed, and the operation is not required to be commutative.
-
template<KokkosExecutionSpace ExecSpace = Kokkos::DefaultExecutionSpace, CommunicationSpace CommSpace = DefaultCommunicationSpace>
auto barrier(Handle<ExecSpace, CommSpace> &&h) -> void¶ A function to create a barrier using the given execution space and transport handle.
- Template Parameters:
ExecSpace – The execution space where the operation will be performed. Defaults to
Kokkos::DefaultExecutionSpace.CommSpace – The communication backend to use. Defaults to
DefaultCommunicationSpace.
- Parameters:
h – A handle of type
Handle<ExecSpace, CommSpace>to be forwarded to the barrier implementation.
Utility¶
Warning
Non-system data types (i.e. the data types not natively supported by the communication space) are not convertible. This notably includes user-defined types.
-
template<CommunicationSpace C, typename T>
auto datatype() -> C::datatype_type¶ Converts a type
Tto its communication spaceCequivalent representation.When
Cis:MpiSpace, returns the correspondingMPI_Datatypetype.NcclSpace, returns the correspondingncclDataType_ttype.
- Template Parameters:
C – The target communication space backend to use for data type conversion.
T – The C++-native data type to convert from.
- Returns:
The communication space representation of the C++-native data type.
-
template<CommunicationSpace C, KokkosView V>
auto datatype_for([[maybe_unused]] const V &view) -> C::datatype_type¶ - Template Parameters:
C – The target communication space backend to use for data type conversion.
V – A Kokkos View type.
- Parameters:
view – The Kokkos View to convert the value type from.
- Returns:
The communication space representation of the Kokkos View value type.
-
template<CommunicationSpace C, KokkosView V>
auto datatype_for([[maybe_unused]] C &&comm, [[maybe_unused]] const V &view) -> C::datatype_type¶ - Template Parameters:
C – The target communication space backend to use for data type conversion.
V – A Kokkos View type.
- Parameters:
comm – A communication space object, immediately consumed.
view – The Kokkos View to convert the value type from.
- Returns:
The communication space representation of the Kokkos View value type.