Consumer Class Reference
HiCR
|
#include <consumer.hpp>

Public Member Functions | |
Consumer (CommunicationManager &communicationManager, std::shared_ptr< GlobalMemorySlot > payloadBuffer, std::shared_ptr< GlobalMemorySlot > tokenBuffer, const std::shared_ptr< LocalMemorySlot > &internalCoordinationBufferForCounts, const std::shared_ptr< LocalMemorySlot > &internalCoordinationBufferForPayloads, const std::shared_ptr< GlobalMemorySlot > &producerCoordinationBufferForCounts, std::shared_ptr< GlobalMemorySlot > producerCoordinationBufferForPayloads, const size_t payloadCapacity, const size_t capacity) | |
__INLINE__ size_t | basePeek (const size_t pos=0) |
__INLINE__ std::array< size_t, 2 > | peek (const size_t pos=0) |
size_t | getOldPayloadBytes (size_t n) |
size_t | getNewPayloadBytes (size_t n) |
__INLINE__ void | pop (const size_t n=1) |
__INLINE__ void | updateDepth () |
size_t | getDepth () |
size_t | getPayloadDepth () |
bool | isEmpty () |
std::shared_ptr< GlobalMemorySlot > | getPayloadBufferMemorySlot () const |
![]() | |
__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 __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 |
![]() | |
Base (CommunicationManager &communicationManager, const std::shared_ptr< LocalMemorySlot > &coordinationBufferForCounts, const std::shared_ptr< LocalMemorySlot > &coordinationBufferForPayloads, const size_t capacity, const size_t payloadCapacity) | |
__INLINE__ auto | getCircularBufferForCounts () const |
__INLINE__ auto | getCircularBufferForPayloads () const |
__INLINE__ auto | getCoordinationBufferForCounts () const |
__INLINE__ auto | getCoordinationBufferForPayloads () const |
![]() | |
Base (CommunicationManager &communicationManager, const std::shared_ptr< LocalMemorySlot > &coordinationBuffer, const size_t tokenSize, const size_t capacity) | |
__INLINE__ CommunicationManager * | getCommunicationManager () const |
__INLINE__ auto | getCoordinationBuffer () const |
Detailed Description
Class definition for a HiCR Consumer Channel
It exposes the functionality to be expected for a variable-size consumer channel
Constructor & Destructor Documentation
◆ Consumer()
|
inline |
The constructor of the variable-sized consumer channel class.
It requires the user to provide the allocated memory slots for the exchange (data) and coordination buffers.
- Parameters
-
[in] communicationManager The backend to facilitate communication between the producer and consumer sides [in] payloadBuffer The memory slot pertaining to the payload buffer. The producer will push new tokens into this buffer, while there is enough space (in bytes). This buffer should be big enough to hold at least the largest message of the variable-sized messages to be pushed. [in] tokenBuffer The memory slot pertaining to the token buffer. This buffer is only used to exchange internal metadata about the sizes of the individual messages being sent. [in] internalCoordinationBufferForCounts This is a small buffer to hold the internal (local) state of the channel's circular buffer message counts [in] internalCoordinationBufferForPayloads This is a small buffer to hold the internal (local) state of the channel's circular buffer payload sizes (in bytes) [in] producerCoordinationBufferForCounts A global reference to the producer channel's internal coordination buffer for message counts, used for remote updates on pop() [in] producerCoordinationBufferForPayloads A global reference to the producer channel's internal coordination buffer for payload sizes (in bytes), used for remote updates on pop() [in] payloadCapacity The capacity (in bytes) of the buffer for variable-sized messages [in] capacity The maximum number of tokens that will be held by this channel
- Note
- : The token size in var-size channels is used only internally, and is passed as having a type size_t (with size sizeof(size_t))
Member Function Documentation
◆ basePeek()
|
inline |
Returns a pointer to the current token, which holds the payload size metadata here.
This is a one-sided blocking call that need not be made collectively.
- Parameters
-
[in] pos The 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
An exception will occur if you do attempt to peek and no
- Note
- While this function does not modify the state of the channel, the contents of the token may be modified by the caller.
◆ getDepth()
|
inline |
Get depth of variable-size consumer. Since we have 2 buffers - one for counts, and one for payloads, we need to be careful. Because the current implementation first receives the payload (phase 1) before receiving the message counts (phase 2), returning this depth should guarantee we already have received the payloads
- Note
- This is not a thread-safe call
This is a getter function that should complete in
- Returns
- The number of elements in variable-size consumer channel
◆ getNewPayloadBytes()
|
inline |
This function inspects the newest
variable-sized elements in the token buffer to find how many bytes they occupy in the payload buffer
- Parameters
-
[in] n element count to inspect, starting from newest, in the token buffer
- Returns
- total byte size that the newest
elements take in payload buffer
◆ getOldPayloadBytes()
|
inline |
This function inspects the oldest
variable-sized elements in the token buffer to find how many bytes they occupy in the payload buffer
- Parameters
-
[in] n element count to inspect, starting from oldest, in the token buffer
- Returns
- total byte size that the oldest
elements take in payload buffer
◆ getPayloadBufferMemorySlot()
|
inline |
Retrieves the pointer to the channel's payload buffer
- Returns
- The pointer to the payload buffer
◆ getPayloadDepth()
|
inline |
Returns the current depth of the channel holding the payloads
- Note
- This is not a thread-safe call
This is a getter function that should complete in
- Returns
- The number of total bytes in the payloads channel
◆ isEmpty()
|
inline |
This function can be used to quickly check whether the channel is empty.
It does not affects the internal state of the channel
- Returns
- true, if both message count and payload buffers are empty
- false, if one of the buffers is not empty
◆ peek()
|
inline |
This function gets the (starting position, size) pair for a given element in the consumer channel
- Parameters
-
[in] pos The payload position required. pos
= 0 indicates earliest payload that is currently present in the buffer.pos
= getDepth()-1 indicates the latest payload to have arrived.
- Returns
- A 2-element array:
- the first value is the starting position in bytes of element
pos
in the payload buffer (in relation to starting address of payload buffer) - the second value is the size in bytes of element
pos
in the payload buffer.
- the first value is the starting position in bytes of element
◆ pop()
|
inline |
Removes the last
variable-sized elements from the payload buffer, and the associated metadata in the token buffer. This is a one-sided blocking call that need not be made collectively.
- Parameters
-
[in] n How many variable-sized elements to pop. Optional; default is one.
In case there are less than n elements in the channel, no elements will be popped.
◆ 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. The consumer does not need to update the depth for this case.
The documentation for this class was generated from the following file:
- /home/runner/work/HiCR/HiCR/include/hicr/frontends/channel/variableSize/spsc/consumer.hpp
Generated by