CIRCT  19.0.0git
Ports.h
Go to the documentation of this file.
1 //===- Ports.h - ESI communication channels ---------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // DO NOT EDIT!
10 // This file is distributed as part of an ESI package. The source for this file
11 // should always be modified within CIRCT.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 // NOLINTNEXTLINE(llvm-header-guard)
16 #ifndef ESI_PORTS_H
17 #define ESI_PORTS_H
18 
19 #include "esi/Common.h"
20 #include "esi/Types.h"
21 
22 #include <future>
23 
24 namespace esi {
25 
26 /// Unidirectional channels are the basic communication primitive between the
27 /// host and accelerator. A 'ChannelPort' is the host side of a channel. It can
28 /// be either read or write but not both. At this level, channels are untyped --
29 /// just streams of bytes. They are not intended to be used directly by users
30 /// but used by higher level APIs which add types.
31 class ChannelPort {
32 public:
33  ChannelPort(const Type *type) : type(type) {}
34  virtual ~ChannelPort() = default;
35 
36  virtual void connect() {}
37  virtual void disconnect() {}
38 
39  const Type *getType() const { return type; }
40 
41 private:
42  const Type *type;
43 };
44 
45 /// A ChannelPort which sends data to the accelerator.
46 class WriteChannelPort : public ChannelPort {
47 public:
49 
50  /// A very basic write API. Will likely change for performance reasons.
51  virtual void write(const MessageData &) = 0;
52 };
53 
54 /// A ChannelPort which reads data from the accelerator.
55 class ReadChannelPort : public ChannelPort {
56 public:
58 
59  /// Specify a buffer to read into. Non-blocking. Returns true if message
60  /// successfully recieved. Basic API, will likely change for performance
61  /// and functionality reasons.
62  virtual bool read(MessageData &) = 0;
63 
64  /// Asynchronous read. Returns a future which will be set when the message is
65  /// recieved. Could this subsume the synchronous read API?
66  /// The default implementation of this is really bad and should be overridden.
67  /// It simply polls `read` in a loop.
68  virtual std::future<MessageData> readAsync();
69 };
70 
71 /// Services provide connections to 'bundles' -- collections of named,
72 /// unidirectional communication channels. This class provides access to those
73 /// ChannelPorts.
74 class BundlePort {
75 public:
76  /// Compute the direction of a channel given the bundle direction and the
77  /// bundle port's direction.
78  static bool isWrite(BundleType::Direction bundleDir) {
79  return bundleDir == BundleType::Direction::To;
80  }
81 
82  /// Construct a port.
83  BundlePort(AppID id, std::map<std::string, ChannelPort &> channels);
84  virtual ~BundlePort() = default;
85 
86  /// Get the ID of the port.
87  AppID getID() const { return id; }
88 
89  /// Get access to the raw byte streams of a channel. Intended for internal
90  /// usage and binding to other languages (e.g. Python) which have their own
91  /// message serialization code. Exposed publicly as an escape hatch, but
92  /// ordinary users should not use. You have been warned.
93  WriteChannelPort &getRawWrite(const std::string &name) const;
94  ReadChannelPort &getRawRead(const std::string &name) const;
95  const std::map<std::string, ChannelPort &> &getChannels() const {
96  return channels;
97  }
98 
99 private:
101  std::map<std::string, ChannelPort &> channels;
102 };
103 
104 } // namespace esi
105 
106 #endif // ESI_PORTS_H
Services provide connections to 'bundles' – collections of named, unidirectional communication channe...
Definition: Ports.h:74
virtual ~BundlePort()=default
std::map< std::string, ChannelPort & > channels
Definition: Ports.h:101
ReadChannelPort & getRawRead(const std::string &name) const
Definition: Ports.cpp:36
WriteChannelPort & getRawWrite(const std::string &name) const
Get access to the raw byte streams of a channel.
Definition: Ports.cpp:26
AppID id
Definition: Ports.h:100
const std::map< std::string, ChannelPort & > & getChannels() const
Definition: Ports.h:95
static bool isWrite(BundleType::Direction bundleDir)
Compute the direction of a channel given the bundle direction and the bundle port's direction.
Definition: Ports.h:78
BundlePort(AppID id, std::map< std::string, ChannelPort & > channels)
Construct a port.
Definition: Ports.cpp:23
AppID getID() const
Get the ID of the port.
Definition: Ports.h:87
Unidirectional channels are the basic communication primitive between the host and accelerator.
Definition: Ports.h:31
virtual void disconnect()
Definition: Ports.h:37
ChannelPort(const Type *type)
Definition: Ports.h:33
const Type * type
Definition: Ports.h:42
virtual ~ChannelPort()=default
virtual void connect()
Definition: Ports.h:36
const Type * getType() const
Definition: Ports.h:39
A logical chunk of data representing serialized data.
Definition: Common.h:85
A ChannelPort which reads data from the accelerator.
Definition: Ports.h:55
virtual std::future< MessageData > readAsync()
Asynchronous read.
Definition: Ports.cpp:46
virtual bool read(MessageData &)=0
Specify a buffer to read into.
Root class of the ESI type system.
Definition: Types.h:27
A ChannelPort which sends data to the accelerator.
Definition: Ports.h:46
virtual void write(const MessageData &)=0
A very basic write API. Will likely change for performance reasons.
Definition: esi.py:1