Consumer Class Reference

HiCR: HiCR::channel::fixedSize::SPSC::Consumer Class Reference
HiCR
HiCR::channel::fixedSize::SPSC::Consumer Class Referencefinal

#include <consumer.hpp>

Inheritance diagram for HiCR::channel::fixedSize::SPSC::Consumer:
HiCR::channel::fixedSize::Base HiCR::channel::Base

Public Member Functions

 Consumer (CommunicationManager &communicationManager, const std::shared_ptr< GlobalMemorySlot > &tokenBuffer, const std::shared_ptr< LocalMemorySlot > &internalCoordinationBuffer, std::shared_ptr< GlobalMemorySlot > producerCoordinationBuffer, const size_t tokenSize, const size_t capacity)
 
__INLINE__ size_t peek (const size_t pos=0)
 
__INLINE__ void pop (const size_t n=1)
 
__INLINE__ void updateDepth ()
 
__INLINE__ std::shared_ptr< GlobalMemorySlotgetTokenBuffer () const
 
- Public Member Functions inherited from HiCR::channel::Base
__INLINE__ size_t getTokenSize () const noexcept
 
__INLINE__ size_t getDepth () const noexcept
 
__INLINE__ bool isFull () const noexcept
 
__INLINE__ bool isEmpty () const noexcept
 
__INLINE__ auto getCircularBuffer () const noexcept
 

Additional Inherited Members

- Static Public Member Functions inherited from HiCR::channel::Base
static __INLINE__ size_t getCoordinationBufferSize () noexcept
 
static __INLINE__ void initializeCoordinationBuffer (const std::shared_ptr< LocalMemorySlot > &coordinationBuffer)
 
static __INLINE__ size_t getTokenBufferSize (const size_t tokenSize, const size_t capacity) noexcept
 
- Protected Member Functions inherited from HiCR::channel::fixedSize::Base
 Base (CommunicationManager &communicationManager, const std::shared_ptr< LocalMemorySlot > &coordinationBuffer, const size_t tokenSize, const size_t capacity)
 
- Protected Member Functions inherited from HiCR::channel::Base
 Base (CommunicationManager &communicationManager, const std::shared_ptr< LocalMemorySlot > &coordinationBuffer, const size_t tokenSize, const size_t capacity)
 
__INLINE__ CommunicationManagergetCommunicationManager () const
 
__INLINE__ auto getCoordinationBuffer () const
 

Detailed Description

Class definition for a HiCR Consumer Channel

It exposes the functionality to be expected for a consumer channel

Constructor & Destructor Documentation

◆ Consumer()

HiCR::channel::fixedSize::SPSC::Consumer::Consumer ( CommunicationManager communicationManager,
const std::shared_ptr< GlobalMemorySlot > &  tokenBuffer,
const std::shared_ptr< LocalMemorySlot > &  internalCoordinationBuffer,
std::shared_ptr< GlobalMemorySlot producerCoordinationBuffer,
const size_t  tokenSize,
const size_t  capacity 
)
inline

The constructor of the consumer channel class.

It requires the user to provide the allocated memory slots for the exchange (data) and coordination buffers.

Parameters
[in]communicationManagerThe backend to facilitate communication between the producer and consumer sides
[in]tokenBufferThe memory slot pertaining to the token buffer. The producer will push new tokens into this buffer, while there is enough space. This buffer should be big enough to hold at least one token.
[in]internalCoordinationBufferThis is a small buffer to hold the internal (loca) state of the channel's circular buffer
[in]producerCoordinationBufferA global reference to the producer channel's internal coordination buffer, used for remote updates on pop()
[in]tokenSizeThe size of each token.
[in]capacityThe maximum number of tokens that will be held by this channel

Member Function Documentation

◆ getTokenBuffer()

__INLINE__ std::shared_ptr< GlobalMemorySlot > HiCR::channel::fixedSize::SPSC::Consumer::getTokenBuffer ( ) const
inline

Function to recover the token buffer This is useful to recover access to the data after the reference to the original memory slot is lost

Returns
The reference to the internal token buffer

◆ peek()

__INLINE__ size_t HiCR::channel::fixedSize::SPSC::Consumer::peek ( const size_t  pos = 0)
inline

Peeks in the local received queue and returns a pointer to the current token.

This is a one-sided blocking call that need not be made collectively.

Parameters
[in]posThe token position required. pos = 0 indicates earliest token that is currently present in the buffer. pos = getDepth()-1 indicates the latest token to have arrived.
Returns
A value representing the relative position within the token buffer where the required element can be found.

This is a getter function that should complete in $ \Theta(1) $ time. This function has no side-effects.

An exception will occur if you do attempt to peek and no

See also
queryDepth to determine whether the channel has an item to pop.
Note
While this function does not modify the state of the channel, the contents of the token may be modified by the caller.

◆ pop()

__INLINE__ void HiCR::channel::fixedSize::SPSC::Consumer::pop ( const size_t  n = 1)
inline

Removes the current token from the channel, and moves to the next token (or to an empty channel state).

This is a one-sided blocking call that need not be made collectively.

Parameters
[in]nHow many tokens to pop. Optional; default is one.

In case there are less than n tokens in the channel, no tokens will be popped.

See also
queryDepth to determine whether the channel has an item to pop before calling this function.

◆ updateDepth()

__INLINE__ void HiCR::channel::fixedSize::SPSC::Consumer::updateDepth ( )
inline

In this implementation of SPSC, updateDepth for the consumer is a NOP. Any push by the producer leads the producer to update the consumer head index in a one-sided manner. This implementation has some advantages for MPSC using SPSC.


The documentation for this class was generated from the following file:
  • /home/runner/work/HiCR/HiCR/include/hicr/frontends/channel/fixedSize/spsc/consumer.hpp