Public Member Functions | Static Public Member Functions | List of all members
rapidsmpf::streaming::Context Class Reference

Context for actors (coroutines) in rapidsmpf. More...

#include <context.hpp>

Public Member Functions

 Context (config::Options options, std::shared_ptr< Communicator::Logger > logger, std::shared_ptr< CoroThreadPoolExecutor > executor, std::shared_ptr< BufferResource > br)
 Full constructor for the Context. More...
 
 Context (config::Options options, std::shared_ptr< Communicator::Logger > logger, std::shared_ptr< BufferResource > br)
 Convenience constructor using the provided configuration options. More...
 
 Context (Context const &)=delete
 
Contextoperator= (Context const &)=delete
 
 Context (Context &&)=delete
 
Contextoperator= (Context &&)=delete
 
void shutdown () noexcept
 Shut down the context. More...
 
config::Options options () const noexcept
 Returns the configuration options. More...
 
std::shared_ptr< Communicator::Logger > const & logger () const noexcept
 
std::shared_ptr< CoroThreadPoolExecutor > const & executor () const noexcept
 Returns the coroutine executor. More...
 
std::shared_ptr< BufferResource > const & br () const noexcept
 Returns the buffer resource. More...
 
std::shared_ptr< MemoryReserveOrWait > const & memory (MemoryType mem_type) const noexcept
 Get the handle for memory reservations for a given memory type. More...
 
std::shared_ptr< Statisticsstatistics () const noexcept
 Returns the statistics collector. More...
 
std::shared_ptr< Channelcreate_channel () const noexcept
 Create a new channel associated with this context. More...
 
std::shared_ptr< SpillableMessages > const & spillable_messages () const noexcept
 Returns the spillable messages collection. More...
 
std::shared_ptr< BoundedQueuecreate_bounded_queue (std::size_t buffer_size) const noexcept
 Create a new bounded queue associated with this context. More...
 
std::size_t uid () const noexcept
 Return a unique identifier for this context. More...
 

Static Public Member Functions

static std::shared_ptr< Contextfrom_options (RmmResourceAdaptor *mr, std::shared_ptr< Communicator::Logger > logger, config::Options options)
 Create a Context based on configuration options. More...
 

Detailed Description

Context for actors (coroutines) in rapidsmpf.

The context owns shared resources used during execution, including the coroutine executor and memory reservation infrastructure.

Warning
Shutdown of the context must be initiated from the same thread that created it. Calling shutdown() from a different thread results in program termination. Since the destructor implicitly calls shutdown(), destroying the context from a different thread also results in termination unless the executor has already been shut down explicitly.

A recommended usage pattern is to create a single Context instance up front on the main thread and reuse it throughout the lifetime of the program. This reduces overhead and avoids issues related to destruction on a different thread.

Definition at line 41 of file context.hpp.

Constructor & Destructor Documentation

◆ Context() [1/2]

rapidsmpf::streaming::Context::Context ( config::Options  options,
std::shared_ptr< Communicator::Logger logger,
std::shared_ptr< CoroThreadPoolExecutor executor,
std::shared_ptr< BufferResource br 
)

Full constructor for the Context.

All provided pointers must be non-null.

Parameters
optionsConfiguration options.
loggerShared pointer to a logger.
executorShared pointer to a coroutine executor.
brShared pointer to a buffer resource.

◆ Context() [2/2]

rapidsmpf::streaming::Context::Context ( config::Options  options,
std::shared_ptr< Communicator::Logger logger,
std::shared_ptr< BufferResource br 
)

Convenience constructor using the provided configuration options.

Parameters
optionsConfiguration options.
loggerShared pointer to a logger.
brBuffer resource used to reserve host memory and perform data movement.

Member Function Documentation

◆ br()

std::shared_ptr<BufferResource> const& rapidsmpf::streaming::Context::br ( ) const
noexcept

Returns the buffer resource.

Returns
Shared pointer to the buffer resource.

◆ create_bounded_queue()

std::shared_ptr<BoundedQueue> rapidsmpf::streaming::Context::create_bounded_queue ( std::size_t  buffer_size) const
noexcept

Create a new bounded queue associated with this context.

Parameters
buffer_sizeMaximum size of the queue.
Returns
A shared pointer to the newly created bounded queue.

◆ create_channel()

std::shared_ptr<Channel> rapidsmpf::streaming::Context::create_channel ( ) const
noexcept

Create a new channel associated with this context.

Returns
A shared pointer to the newly created channel.

◆ executor()

std::shared_ptr<CoroThreadPoolExecutor> const& rapidsmpf::streaming::Context::executor ( ) const
noexcept

Returns the coroutine executor.

Returns
Shared pointer to the executor.

◆ from_options()

static std::shared_ptr<Context> rapidsmpf::streaming::Context::from_options ( RmmResourceAdaptor mr,
std::shared_ptr< Communicator::Logger logger,
config::Options  options 
)
static

Create a Context based on configuration options.

This is a convenience factory that wires up a fully initialized and usable Context.

Note
The current CUDA device must be set prior to calling this function. Options that depend on device memory availability query the current device.
Parameters
mrDevice memory resource adaptor used by RapidsMPF. The adaptor must outlive the returned Context.
loggerThe logger to use.
optionsConfiguration options used to initialize the Context and its components.
Returns
A fully initialized Context.
Exceptions
std::invalid_argumentIf an option value is invalid.
std::out_of_rangeIf an option value exceeds the representable range.
Warning
Shutdown of the context must be initiated from the same thread that created it. Calling shutdown() from a different thread results in program termination. Since the destructor implicitly calls shutdown(), destroying the context from a different thread also results in termination unless the executor has already been shut down explicitly.

A recommended usage pattern is to create a single Context instance up front on the main thread and reuse it throughout the lifetime of the program. This reduces overhead and avoids issues related to destruction on a different thread.

◆ logger()

std::shared_ptr<Communicator::Logger> const& rapidsmpf::streaming::Context::logger ( ) const
noexcept
Returns
Shared pointer to the logger.

◆ memory()

std::shared_ptr<MemoryReserveOrWait> const& rapidsmpf::streaming::Context::memory ( MemoryType  mem_type) const
noexcept

Get the handle for memory reservations for a given memory type.

Returns an object that coordinates asynchronous memory reservation requests for the specified memory type. The returned instance provides backpressure and global progress guarantees, and should be used to reserve memory before performing operations that require memory.

A recommended usage pattern is to reserve all required memory up front as a single atomic reservation. This allows callers to co_await the reservation request and only start executing the operation once all required memory is available.

Parameters
mem_typeMemory type for which reservations are requested.
Returns
Shared pointer to the corresponding memory reservation coordinator.

◆ options()

config::Options rapidsmpf::streaming::Context::options ( ) const
noexcept

Returns the configuration options.

Returns
The Options instance.

◆ shutdown()

void rapidsmpf::streaming::Context::shutdown ( )
noexcept

Shut down the context.

This method is idempotent and only performs shutdown once. Subsequent calls have no effect.

Warning
Shutdown must be initiated from the same thread that constructed the executor. Calling this method from a different thread results in program termination.

◆ spillable_messages()

std::shared_ptr<SpillableMessages> const& rapidsmpf::streaming::Context::spillable_messages ( ) const
noexcept

Returns the spillable messages collection.

Returns
Shared pointer to the collection.

◆ statistics()

std::shared_ptr<Statistics> rapidsmpf::streaming::Context::statistics ( ) const
noexcept

Returns the statistics collector.

Returns
Shared pointer to the statistics instance.

◆ uid()

std::size_t rapidsmpf::streaming::Context::uid ( ) const
noexcept

Return a unique identifier for this context.

The returned value uniquely identifies this Context instance. No two Context objects, past or present, will ever have the same identifier within the same process.

Returns
A process-unique identifier for this Context.

The documentation for this class was generated from the following file: