Shuffler#

using rapidsmpf::shuffler::PartID = std::uint32_t#

Partition ID, which goes from 0 to the total number of partitions.

The PartID is always referring to a partition globally.

inline std::ostream &rapidsmpf::shuffler::operator<<(
std::ostream &os,
detail::FinishCounter const &obj
)#

Overloads the stream insertion operator for the FinishCounter class.

This function allows a description of a FinishCounter to be written to an output stream.

Parameters:
  • os – The output stream to write to.

  • obj – The object to write.

Returns:

A reference to the modified output stream.

inline std::ostream &rapidsmpf::shuffler::operator<<(
std::ostream &os,
Shuffler const &obj
)#

Overloads the stream insertion operator for the Shuffler class.

This function allows a description of a Shuffler to be written to an output stream.

Parameters:
  • os – The output stream to write to.

  • obj – The object to write.

Returns:

A reference to the modified output stream.

class Shuffler#
#include <shuffler.hpp>

Shuffle service for all-to-all style communication of partitioned data.

The Shuffler class provides an interface for performing a shuffle operation on distributed data, using a partitioning scheme to distribute and collect data chunks across different ranks.

Public Types

using PartitionOwner = std::function<Rank(std::shared_ptr<Communicator> const&, PartID, PartID)>#

Function that given a Communicator, PartID, and total partition count, returns the rapidsmpf::Rank of the owning node.

using FinishedCallback = std::function<void()>#

Callback function type called when all partitions are finished and data can be extracted.

Warning

A callback must be fast and non-blocking. Ideally it should be used to signal a separate thread to do the actual processing.

Public Functions

Shuffler(
std::shared_ptr<Communicator> comm,
OpID op_id,
PartID total_num_partitions,
BufferResource *br,
FinishedCallback &&finished_callback,
PartitionOwner partition_owner = round_robin,
ReservationContext reservation_context = {}
)#

Construct a new shuffler for a single shuffle.

Note

It is safe to reuse the op_id as soon as wait has completed locally, unless it rethrew an error because the shuffle failed. After a failure, the op_id must not be reused on the communicator, since messages of the failed shuffle may still arrive. If communication was still in flight, destroying the shuffler also aborts the communicator (see Communicator::is_aborted()), which must then be replaced to communicate again. A failure before any communication was posted does not abort it. A failure is only reported on the rank where it happened: the other ranks are not notified. Those that need data from this rank block in wait until its timeout, if one is given, and destroying their unfinished shuffler blocks forever, since it waits for its progress function to finish.

Note

The caller promises that inserted buffers are stream-ordered with respect to their own stream, and extracted buffers are likewise guaranteed to be stream- ordered with respect to their own stream.

Parameters:
  • comm – The communicator to use.

  • op_id – The operation ID of the shuffle.

  • total_num_partitions – Total number of partitions in the shuffle.

  • br – Buffer resource used to allocate temporary and the shuffle result.

  • finished_callback – Callback to notify when all partitions are finished, or when the shuffle fails, in which case wait() and extract() rethrow the error.

  • partition_owner – Function to determine partition ownership.

  • reservation_context – Opaque telemetry attribution token for internal reservations.

inline Shuffler(
std::shared_ptr<Communicator> comm,
OpID op_id,
PartID total_num_partitions,
BufferResource *br,
PartitionOwner partition_owner = round_robin,
ReservationContext reservation_context = {}
)#

Construct a new shuffler for a single shuffle.

Note

The caller promises that inserted buffers are stream-ordered with respect to their own stream, and extracted buffers are likewise guaranteed to be stream- ordered with respect to their own stream.

Parameters:
  • comm – The communicator to use.

  • op_id – The operation ID of the shuffle. This ID is unique for this operation, and should not be reused until all nodes has called Shuffler::shutdown().

  • total_num_partitions – Total number of partitions in the shuffle.

  • br – Buffer resource used to allocate temporary and the shuffle result.

  • partition_owner – Function to determine partition ownership.

  • reservation_context – Opaque telemetry attribution token for internal reservations.

inline std::shared_ptr<Communicator> const &comm() const noexcept#

Gets the communicator associated with this Shuffler.

Returns:

Shared pointer to communicator.

void shutdown()#

Shutdown the shuffle, blocking until all inflight communication is done.

Throws:

std::logic_error – If the shuffler is already inactive.

void insert(std::unordered_map<PartID, PackedData> &&chunks)#

Insert a bunch of packed (serialized) chunks into the shuffle.

Chunks for partitions owned by another rank that are not in a memory type that can be sent, such as disk-backed chunks, are moved with BufferResource::ensure_memory_type() first, which may block.

Note

Concurrent insertion by multiple threads is supported, the caller must ensure that insert_finished() is called after all insert() calls have completed.

Parameters:

chunks – A map of partition IDs and their packed chunks. Successfully inserted and empty entries are erased. If moving a remote entry to sendable memory throws, the map contains that intact entry and entries not yet processed, so it can be retried.

Throws:

rapidsmpf::reservation_error – If a chunk must be moved, no memory is available, and overbooking is not allowed.

void insert_finished()#

Signal that no more data will be inserted into the shuffle.

This informs the shuffler that this rank has finished inserting data. Must be called exactly once.

Note

If multiple threads are insert()ing, you must establish a happens-before relationship between the completion of all insert()s and the final call to insert_finished().

std::vector<PackedData> extract(PartID pid)#

Extract all chunks belonging to the specified partition.

It is valid to extract a partition that has not yet been fully received. In such cases, only the chunks received so far are returned.

To ensure the partition is complete, use wait() or another appropriate synchronization mechanism beforehand.

Note

When the buffer resource has a disk resource, chunks spilled under memory pressure may be stored on disk, so extracted chunks may be disk-backed. Use unspill_partitions() to move them back to device memory.

Parameters:

pid – The ID of the partition to extract.

Throws:

Rethrows – the exception raised on the progress thread on behalf of this shuffler, if any. Once that happened, every subsequent call rethrows it.

Returns:

A vector of PackedData chunks associated with the partition.

bool finished() const#

Check if all partitions are finished.

Throws:

Rethrows – the exception raised on the progress thread on behalf of this shuffler, if any, so that polling for completion fails instead of spinning forever. Once that happened, every subsequent call rethrows it.

Returns:

True if all partitions are finished, otherwise False.

void wait(std::optional<std::chrono::milliseconds> timeout = {})#

Wait for all partitions to finish (blocking).

Parameters:

timeout – Optional timeout (ms) to wait.

Throws:
  • std::runtime_error – if the timeout is reached.

  • Rethrows – the exception raised on the progress thread on behalf of this shuffler, if any. Once that happened, every subsequent call rethrows it.

std::size_t spill(std::size_t amount, MemoryType mem_type)#

Spills at least amount bytes from the given memory type, if possible.

Parameters:
  • amount – The amount of memory to spill, in bytes.

  • mem_type – The memory type to spill from.

Returns:

The amount of memory actually spilled.

std::string str() const#

Returns a description of this instance.

Returns:

The description.

std::span<PartID const> local_partitions() const#

Returns the local partition IDs owned by the shuffler.

Returns:

A span of partition IDs owned by the shuffler.

Public Members

PartID const total_num_partitions#

Total number of partition in the shuffle.

PartitionOwner const partition_owner#

Function to determine partition ownership.

Public Static Functions

static inline Rank round_robin(
std::shared_ptr<Communicator> const &comm,
PartID pid,
PartID total_num_partitions
)#

A PartitionOwner that distributes partitions using round robin assignment.

Parameters:
  • comm – The communicator to use.

  • pid – The partition ID to query.

  • total_num_partitions – Total number of partitions (unused).

Returns:

The rank owning the partition.

static inline Rank contiguous(
std::shared_ptr<Communicator> const &comm,
PartID pid,
PartID total_num_partitions
)#

A PartitionOwner that assigns contiguous partition ID ranges to ranks.

Rank 0 gets [0, k), rank 1 gets [k, 2k), etc. Use for sort so that each rank’s local_partitions() are adjacent and in order.

Parameters:
  • comm – The communicator to use.

  • pid – The partition ID to query.

  • total_num_partitions – Total number of partitions (must match the shuffle).

Returns:

The rank owning the partition.

static std::vector<PartID> local_partitions(
std::shared_ptr<Communicator> const &comm,
PartID total_num_partitions,
PartitionOwner partition_owner
)#

Returns the local partition IDs owned by the current node.

Parameters:
  • comm – The communicator to use.

  • total_num_partitions – Total number of partitions in the shuffle.

  • partition_owner – Function that determines partition ownership.

Returns:

A vector of partition IDs owned by the current node.

static inline constexpr Rank extract_rank(detail::ChunkID cid)#

Extract the rank from a chunk ID.

Parameters:

cid – The chunk ID.

Returns:

The rank.

Public Static Attributes

static constexpr int chunk_id_counter_bits = 38#

The number of bits used to store the counter in a chunk ID.