29using PortMap = std::map<std::string, ChannelPort &>;
44 virtual void connect(std::optional<unsigned> bufferSize = std::nullopt) = 0;
73 virtual void connectImpl(std::optional<unsigned> bufferSize) {}
82 connect(std::optional<unsigned> bufferSize = std::nullopt)
override {
108 void connect(std::optional<unsigned> bufferSize = std::nullopt)
override {
109 throw std::runtime_error(
errmsg);
113 throw std::runtime_error(
errmsg);
146 std::optional<unsigned> bufferSize = std::nullopt);
158 connect(std::optional<unsigned> bufferSize = std::nullopt)
override;
161 virtual std::future<MessageData>
readAsync();
166 std::future<MessageData> f =
readAsync();
168 outData = std::move(f.get());
209 std::optional<unsigned> bufferSize = std::nullopt)
override {
210 throw std::runtime_error(
errmsg);
212 void connect(std::optional<unsigned> bufferSize = std::nullopt)
override {
213 throw std::runtime_error(
errmsg);
216 throw std::runtime_error(
errmsg);
253 template <
typename T>
255 return const_cast<T *
>(
dynamic_cast<const T *
>(
this));
263 result |= channel.second.poll();
Services provide connections to 'bundles' – collections of named, unidirectional communication channe...
virtual ~BundlePort()=default
T * getAs() const
Cast this Bundle port to a subclass which is actually useful.
ReadChannelPort & getRawRead(const std::string &name) const
WriteChannelPort & getRawWrite(const std::string &name) const
Get access to the raw byte streams of a channel.
const PortMap & getChannels() const
bool poll()
Calls poll on all channels in the bundle and returns true if any of them returned true.
static bool isWrite(BundleType::Direction bundleDir)
Compute the direction of a channel given the bundle direction and the bundle port's direction.
AppID getID() const
Get the ID of the port.
Bundles represent a collection of channels.
Unidirectional channels are the basic communication primitive between the host and accelerator.
const Type * getType() const
ChannelPort(const Type *type)
virtual void disconnect()=0
virtual void connect(std::optional< unsigned > bufferSize=std::nullopt)=0
Set up a connection to the accelerator.
virtual void connectImpl(std::optional< unsigned > bufferSize)
Called by all connect methods to let backends initiate the underlying connections.
virtual bool pollImpl()
Method called by poll() to actually poll the channel if the channel is connected.
bool poll()
Poll for incoming data.
virtual bool isConnected() const =0
A logical chunk of data representing serialized data.
A ChannelPort which reads data from the accelerator.
virtual std::future< MessageData > readAsync()
Asynchronous read.
virtual bool isConnected() const override
std::mutex pollingM
Mutex to protect the two queues used for polling.
virtual void connect(std::function< bool(MessageData)> callback, std::optional< unsigned > bufferSize=std::nullopt)
std::function< bool(MessageData)> callback
Backends call this callback when new data is available.
Mode
Indicates the current mode of the channel.
std::queue< MessageData > dataQueue
Store incoming data here if there are no outstanding promises to be fulfilled.
static constexpr uint64_t DefaultMaxDataQueueMsgs
Default max data queue size set at connect time.
std::queue< std::promise< MessageData > > promiseQueue
Promises to be fulfilled when data is available.
void setMaxDataQueueMsgs(uint64_t maxMsgs)
Set maximum number of messages to store in the dataQueue.
uint64_t maxDataQueueMsgs
Maximum number of messages to store in dataQueue. 0 means no limit.
virtual void disconnect() override
virtual void read(MessageData &outData)
Specify a buffer to read into.
ReadChannelPort(const Type *type)
Root class of the ESI type system.
Instantiated when a backend does not know how to create a read channel.
void connect(std::optional< unsigned > bufferSize=std::nullopt) override
Connect to the channel in polling mode.
void connect(std::function< bool(MessageData)> callback, std::optional< unsigned > bufferSize=std::nullopt) override
std::future< MessageData > readAsync() override
Asynchronous read.
UnknownReadChannelPort(const Type *type, std::string errmsg)
Instantiated when a backend does not know how to create a write channel.
void connect(std::optional< unsigned > bufferSize=std::nullopt) override
Set up a connection to the accelerator.
void write(const MessageData &) override
A very basic blocking write API.
bool tryWrite(const MessageData &) override
A basic non-blocking write API.
UnknownWriteChannelPort(const Type *type, std::string errmsg)
A ChannelPort which sends data to the accelerator.
virtual bool isConnected() const override
virtual void disconnect() override
virtual void write(const MessageData &)=0
A very basic blocking write API.
virtual bool tryWrite(const MessageData &data)=0
A basic non-blocking write API.
virtual void connect(std::optional< unsigned > bufferSize=std::nullopt) override
Set up a connection to the accelerator.
std::map< std::string, ChannelPort & > PortMap