CIRCT  20.0.0git
Public Member Functions | Static Public Attributes | Protected Types | Protected Attributes | List of all members
esi::ReadChannelPort Class Reference

A ChannelPort which reads data from the accelerator. More...

#include <Ports.h>

Inheritance diagram for esi::ReadChannelPort:
Inheritance graph
[legend]
Collaboration diagram for esi::ReadChannelPort:
Collaboration graph
[legend]

Public Member Functions

 ReadChannelPort (const Type *type)
 
virtual void disconnect () override
 
virtual bool isConnected () const override
 
virtual void connect (std::function< bool(MessageData)> callback, std::optional< unsigned > bufferSize=std::nullopt)
 
virtual void connect (std::optional< unsigned > bufferSize=std::nullopt) override
 Connect to the channel in polling mode. More...
 
virtual std::future< MessageDatareadAsync ()
 Asynchronous read. More...
 
virtual void read (MessageData &outData)
 Specify a buffer to read into. More...
 
void setMaxDataQueueMsgs (uint64_t maxMsgs)
 Set maximum number of messages to store in the dataQueue. More...
 
- Public Member Functions inherited from esi::ChannelPort
 ChannelPort (const Type *type)
 
virtual ~ChannelPort ()
 
bool poll ()
 Poll for incoming data. More...
 
const TypegetType () const
 

Static Public Attributes

static constexpr uint64_t DefaultMaxDataQueueMsgs = 32
 Default max data queue size set at connect time. More...
 

Protected Types

enum  Mode { Disconnected , Callback , Polling }
 Indicates the current mode of the channel. More...
 

Protected Attributes

volatile Mode mode
 
std::function< bool(MessageData)> callback
 Backends call this callback when new data is available. More...
 
std::mutex pollingM
 Mutex to protect the two queues used for polling. More...
 
std::queue< MessageDatadataQueue
 Store incoming data here if there are no outstanding promises to be fulfilled. More...
 
uint64_t maxDataQueueMsgs
 Maximum number of messages to store in dataQueue. 0 means no limit. More...
 
std::queue< std::promise< MessageData > > promiseQueue
 Promises to be fulfilled when data is available. More...
 
- Protected Attributes inherited from esi::ChannelPort
const Typetype
 

Additional Inherited Members

- Protected Member Functions inherited from esi::ChannelPort
virtual bool pollImpl ()
 Method called by poll() to actually poll the channel if the channel is connected. More...
 
virtual void connectImpl (std::optional< unsigned > bufferSize)
 Called by all connect methods to let backends initiate the underlying connections. More...
 

Detailed Description

A ChannelPort which reads data from the accelerator.

It has two modes: Callback and Polling which cannot be used at the same time. The mode is set at connect() time. To change the mode, disconnect() and then connect() again.

Definition at line 103 of file Ports.h.

Member Enumeration Documentation

◆ Mode

Indicates the current mode of the channel.

Enumerator
Disconnected 
Callback 
Polling 

Definition at line 160 of file Ports.h.

Constructor & Destructor Documentation

◆ ReadChannelPort()

esi::ReadChannelPort::ReadChannelPort ( const Type type)
inline

Definition at line 106 of file Ports.h.

Member Function Documentation

◆ connect() [1/2]

void ReadChannelPort::connect ( std::function< bool(MessageData)>  callback,
std::optional< unsigned >  bufferSize = std::nullopt 
)
virtual

Definition at line 44 of file Ports.cpp.

References callback, esi::ChannelPort::connectImpl(), and mode.

◆ connect() [2/2]

void ReadChannelPort::connect ( std::optional< unsigned >  bufferSize = std::nullopt)
overridevirtual

Connect to the channel in polling mode.

Implements esi::ChannelPort.

Definition at line 53 of file Ports.cpp.

References assert(), callback, esi::ChannelPort::connectImpl(), dataQueue, DefaultMaxDataQueueMsgs, maxDataQueueMsgs, mode, pollingM, and promiseQueue.

◆ disconnect()

virtual void esi::ReadChannelPort::disconnect ( )
inlineoverridevirtual

Implements esi::ChannelPort.

Definition at line 108 of file Ports.h.

References mode.

◆ isConnected()

virtual bool esi::ReadChannelPort::isConnected ( ) const
inlineoverridevirtual

Implements esi::ChannelPort.

Definition at line 109 of file Ports.h.

References mode.

◆ read()

virtual void esi::ReadChannelPort::read ( MessageData outData)
inlinevirtual

Specify a buffer to read into.

Blocking. Basic API, will likely change for performance and functionality reasons.

Definition at line 144 of file Ports.h.

References readAsync().

◆ readAsync()

std::future< MessageData > ReadChannelPort::readAsync ( )
virtual

Asynchronous read.

Definition at line 77 of file Ports.cpp.

References assert(), dataQueue, mode, pollingM, and promiseQueue.

Referenced by PYBIND11_MODULE(), read(), sv2cCosimserverEpRegister(), and sv2cCosimserverEpTryGet().

◆ setMaxDataQueueMsgs()

void esi::ReadChannelPort::setMaxDataQueueMsgs ( uint64_t  maxMsgs)
inline

Set maximum number of messages to store in the dataQueue.

0 means no limit. This is only used in polling mode and is set to default of 32 upon connect. While it may seem redundant to have this and bufferSize, there may be (and are) backends which have a very small amount of memory which are accelerator accessible and want to move messages out as quickly as possible.

Definition at line 156 of file Ports.h.

References maxDataQueueMsgs.

Member Data Documentation

◆ callback

std::function<bool(MessageData)> esi::ReadChannelPort::callback
protected

Backends call this callback when new data is available.

Definition at line 164 of file Ports.h.

Referenced by connect().

◆ dataQueue

std::queue<MessageData> esi::ReadChannelPort::dataQueue
protected

Store incoming data here if there are no outstanding promises to be fulfilled.

Definition at line 174 of file Ports.h.

Referenced by connect(), and readAsync().

◆ DefaultMaxDataQueueMsgs

constexpr uint64_t esi::ReadChannelPort::DefaultMaxDataQueueMsgs = 32
staticconstexpr

Default max data queue size set at connect time.

Definition at line 133 of file Ports.h.

Referenced by connect().

◆ maxDataQueueMsgs

uint64_t esi::ReadChannelPort::maxDataQueueMsgs
protected

Maximum number of messages to store in dataQueue. 0 means no limit.

Definition at line 176 of file Ports.h.

Referenced by connect(), and setMaxDataQueueMsgs().

◆ mode

volatile Mode esi::ReadChannelPort::mode
protected

Definition at line 161 of file Ports.h.

Referenced by connect(), disconnect(), isConnected(), and readAsync().

◆ pollingM

std::mutex esi::ReadChannelPort::pollingM
protected

Mutex to protect the two queues used for polling.

Definition at line 171 of file Ports.h.

Referenced by connect(), and readAsync().

◆ promiseQueue

std::queue<std::promise<MessageData> > esi::ReadChannelPort::promiseQueue
protected

Promises to be fulfilled when data is available.

Definition at line 178 of file Ports.h.

Referenced by connect(), and readAsync().


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