esiaccel 0.1.4.dev31__cp310-cp310-win_amd64.whl → 0.2.3.dev80__cp310-cp310-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- esiaccel/CosimBackend.dll +0 -0
- esiaccel/CosimBackend.lib +0 -0
- esiaccel/CosimRpc.dll +0 -0
- esiaccel/CosimRpc.lib +0 -0
- esiaccel/ESICppRuntime.dll +0 -0
- esiaccel/ESICppRuntime.lib +0 -0
- esiaccel/EsiCosimDpiServer.dll +0 -0
- esiaccel/EsiCosimDpiServer.lib +0 -0
- esiaccel/{lib/MtiPli.dll → MtiPli.dll} +0 -0
- esiaccel/{lib/MtiPli.lib → MtiPli.lib} +0 -0
- esiaccel/__init__.py +22 -4
- esiaccel/abseil_dll.dll +0 -0
- esiaccel/accelerator.py +37 -5
- esiaccel/cares.dll +0 -0
- esiaccel/cmake/esiaccelConfig.cmake +34 -0
- esiaccel/codegen.py +3 -3
- esiaccel/cosim/Cosim_CycleCount.sv +84 -0
- esiaccel/cosim/Cosim_Endpoint.sv +61 -32
- esiaccel/cosim/driver.cpp +6 -6
- esiaccel/cosim/driver.sv +14 -0
- esiaccel/cosim/questa.py +141 -0
- esiaccel/cosim/simulator.py +383 -0
- esiaccel/cosim/verilator.py +92 -0
- esiaccel/esi-cosim.py +104 -0
- esiaccel/esiCppAccel.cp312-win_amd64.pyd +0 -0
- esiaccel/esiquery.exe +0 -0
- esiaccel/include/esi/Accelerator.h +14 -17
- esiaccel/include/esi/CLI.h +5 -5
- esiaccel/include/esi/Common.h +19 -2
- esiaccel/include/esi/Context.h +17 -9
- esiaccel/include/esi/Design.h +9 -4
- esiaccel/include/esi/Manifest.h +0 -2
- esiaccel/include/esi/Ports.h +230 -23
- esiaccel/include/esi/Services.h +92 -31
- esiaccel/include/esi/Types.h +162 -10
- esiaccel/include/esi/Values.h +313 -0
- esiaccel/include/esi/backends/Cosim.h +5 -12
- esiaccel/include/esi/backends/RpcClient.h +97 -0
- esiaccel/include/esi/backends/RpcServer.h +21 -3
- esiaccel/libcrypto-3-x64.dll +0 -0
- esiaccel/libprotobuf.dll +0 -0
- esiaccel/libssl-3-x64.dll +0 -0
- esiaccel/re2.dll +0 -0
- esiaccel/types.py +66 -26
- esiaccel/utils.py +21 -3
- esiaccel/zlib1.dll +0 -0
- {esiaccel-0.1.4.dev31.dist-info → esiaccel-0.2.3.dev80.dist-info}/METADATA +1 -1
- esiaccel-0.2.3.dev80.dist-info/RECORD +58 -0
- esiaccel/bin/esi-cosim.py +0 -423
- esiaccel/bin/esiquery.exe +0 -0
- esiaccel/esiCppAccel.cp310-win_amd64.pyd +0 -0
- esiaccel/lib/EsiCosimDpiServer.dll +0 -0
- esiaccel/lib/EsiCosimDpiServer.lib +0 -0
- esiaccel-0.1.4.dev31.dist-info/RECORD +0 -43
- {esiaccel-0.1.4.dev31.dist-info → esiaccel-0.2.3.dev80.dist-info}/WHEEL +0 -0
- {esiaccel-0.1.4.dev31.dist-info → esiaccel-0.2.3.dev80.dist-info}/entry_points.txt +0 -0
- {esiaccel-0.1.4.dev31.dist-info → esiaccel-0.2.3.dev80.dist-info}/licenses/LICENSE +0 -0
- {esiaccel-0.1.4.dev31.dist-info → esiaccel-0.2.3.dev80.dist-info}/top_level.txt +0 -0
esiaccel/include/esi/Common.h
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
#include <cstdint>
|
|
21
21
|
#include <map>
|
|
22
22
|
#include <optional>
|
|
23
|
+
#include <span>
|
|
23
24
|
#include <stdexcept>
|
|
24
25
|
#include <string>
|
|
25
26
|
#include <vector>
|
|
@@ -42,6 +43,13 @@ struct AppID {
|
|
|
42
43
|
return name == other.name && idx == other.idx;
|
|
43
44
|
}
|
|
44
45
|
bool operator!=(const AppID &other) const { return !(*this == other); }
|
|
46
|
+
friend std::ostream &operator<<(std::ostream &os, const AppID &id);
|
|
47
|
+
|
|
48
|
+
std::string toString() const {
|
|
49
|
+
if (idx.has_value())
|
|
50
|
+
return name + "[" + std::to_string(idx.value()) + "]";
|
|
51
|
+
return name;
|
|
52
|
+
}
|
|
45
53
|
};
|
|
46
54
|
bool operator<(const AppID &a, const AppID &b);
|
|
47
55
|
|
|
@@ -49,8 +57,10 @@ class AppIDPath : public std::vector<AppID> {
|
|
|
49
57
|
public:
|
|
50
58
|
using std::vector<AppID>::vector;
|
|
51
59
|
|
|
52
|
-
AppIDPath operator+(const AppIDPath &b);
|
|
60
|
+
AppIDPath operator+(const AppIDPath &b) const;
|
|
61
|
+
AppIDPath parent() const;
|
|
53
62
|
std::string toStr() const;
|
|
63
|
+
friend std::ostream &operator<<(std::ostream &os, const AppIDPath &path);
|
|
54
64
|
};
|
|
55
65
|
bool operator<(const AppIDPath &a, const AppIDPath &b);
|
|
56
66
|
|
|
@@ -104,6 +114,8 @@ class MessageData {
|
|
|
104
114
|
public:
|
|
105
115
|
/// Adopts the data vector buffer.
|
|
106
116
|
MessageData() = default;
|
|
117
|
+
MessageData(std::span<const uint8_t> data)
|
|
118
|
+
: data(data.data(), data.data() + data.size()) {}
|
|
107
119
|
MessageData(std::vector<uint8_t> &data) : data(std::move(data)) {}
|
|
108
120
|
MessageData(std::vector<uint8_t> &&data) : data(std::move(data)) {}
|
|
109
121
|
MessageData(const uint8_t *data, size_t size) : data(data, data + size) {}
|
|
@@ -114,11 +126,17 @@ public:
|
|
|
114
126
|
/// Get the data as a vector of bytes.
|
|
115
127
|
const std::vector<uint8_t> &getData() const { return data; }
|
|
116
128
|
|
|
129
|
+
/// Implicit conversion to a vector/span of bytes, to play nice with other
|
|
130
|
+
/// APIs that accept bytearray-like things.
|
|
131
|
+
operator const std::vector<uint8_t> &() const { return data; }
|
|
132
|
+
operator std::span<const uint8_t>() const { return data; }
|
|
133
|
+
|
|
117
134
|
/// Move the data out of this object.
|
|
118
135
|
std::vector<uint8_t> takeData() { return std::move(data); }
|
|
119
136
|
|
|
120
137
|
/// Get the size of the data in bytes.
|
|
121
138
|
size_t getSize() const { return data.size(); }
|
|
139
|
+
size_t size() const { return getSize(); }
|
|
122
140
|
|
|
123
141
|
/// Returns true if this message contains no data.
|
|
124
142
|
bool empty() const { return data.empty(); }
|
|
@@ -151,7 +169,6 @@ private:
|
|
|
151
169
|
} // namespace esi
|
|
152
170
|
|
|
153
171
|
std::ostream &operator<<(std::ostream &, const esi::ModuleInfo &);
|
|
154
|
-
std::ostream &operator<<(std::ostream &, const esi::AppID &);
|
|
155
172
|
|
|
156
173
|
//===----------------------------------------------------------------------===//
|
|
157
174
|
// Functions which should be in the standard library.
|
esiaccel/include/esi/Context.h
CHANGED
|
@@ -20,23 +20,30 @@
|
|
|
20
20
|
#include "esi/Types.h"
|
|
21
21
|
|
|
22
22
|
#include <exception>
|
|
23
|
+
#include <map>
|
|
23
24
|
#include <memory>
|
|
24
|
-
#include <
|
|
25
|
+
#include <vector>
|
|
25
26
|
|
|
26
27
|
namespace esi {
|
|
27
28
|
class AcceleratorConnection;
|
|
28
29
|
|
|
29
30
|
/// AcceleratorConnections, Accelerators, and Manifests must all share a
|
|
30
|
-
/// context. It owns all the types, uniquifying them.
|
|
31
|
+
/// context. It owns all the types, uniquifying them. It also owns the
|
|
32
|
+
/// connections (which own the Accelerators). When it is destroyed, all
|
|
33
|
+
/// connections are disconnected and the objects are destroyed.
|
|
31
34
|
class Context {
|
|
32
35
|
public:
|
|
33
|
-
Context()
|
|
34
|
-
Context(std::unique_ptr<Logger> logger)
|
|
36
|
+
Context();
|
|
37
|
+
Context(std::unique_ptr<Logger> logger);
|
|
38
|
+
~Context();
|
|
39
|
+
|
|
40
|
+
/// Disconnect from all accelerators associated with this context.
|
|
41
|
+
void disconnectAll();
|
|
35
42
|
|
|
36
43
|
/// Create a context with a specific logger type.
|
|
37
44
|
template <typename T, typename... Args>
|
|
38
|
-
static Context withLogger(Args &&...args) {
|
|
39
|
-
return Context(std::make_unique<T>(args...));
|
|
45
|
+
static std::unique_ptr<Context> withLogger(Args &&...args) {
|
|
46
|
+
return std::make_unique<Context>(std::make_unique<T>(args...));
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
/// Resolve a type id to the type.
|
|
@@ -49,9 +56,9 @@ public:
|
|
|
49
56
|
/// Register a type with the context. Takes ownership of the pointer type.
|
|
50
57
|
void registerType(Type *type);
|
|
51
58
|
|
|
52
|
-
/// Connect to an accelerator backend.
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
/// Connect to an accelerator backend. Retains ownership internally and
|
|
60
|
+
/// returns a non-owning pointer.
|
|
61
|
+
AcceleratorConnection *connect(std::string backend, std::string connection);
|
|
55
62
|
|
|
56
63
|
/// Register a logger with the accelerator. Assumes ownership of the logger.
|
|
57
64
|
void setLogger(std::unique_ptr<Logger> logger) {
|
|
@@ -63,6 +70,7 @@ public:
|
|
|
63
70
|
|
|
64
71
|
private:
|
|
65
72
|
std::unique_ptr<Logger> logger;
|
|
73
|
+
std::vector<std::unique_ptr<AcceleratorConnection>> connections;
|
|
66
74
|
|
|
67
75
|
private:
|
|
68
76
|
using TypeCache = std::map<Type::ID, std::unique_ptr<Type>>;
|
esiaccel/include/esi/Design.h
CHANGED
|
@@ -45,11 +45,15 @@ class Service;
|
|
|
45
45
|
|
|
46
46
|
/// Represents either the top level or an instance of a hardware module.
|
|
47
47
|
class HWModule {
|
|
48
|
+
public:
|
|
49
|
+
HWModule(const HWModule &) = delete;
|
|
50
|
+
HWModule &operator=(const HWModule &) = delete;
|
|
51
|
+
|
|
48
52
|
protected:
|
|
49
53
|
HWModule(std::optional<ModuleInfo> info,
|
|
50
54
|
std::vector<std::unique_ptr<Instance>> children,
|
|
51
55
|
std::vector<services::Service *> services,
|
|
52
|
-
std::vector<std::unique_ptr<BundlePort>>
|
|
56
|
+
std::vector<std::unique_ptr<BundlePort>> &&ports);
|
|
53
57
|
|
|
54
58
|
public:
|
|
55
59
|
virtual ~HWModule() = default;
|
|
@@ -112,11 +116,12 @@ public:
|
|
|
112
116
|
Instance(AppID id, std::optional<ModuleInfo> info,
|
|
113
117
|
std::vector<std::unique_ptr<Instance>> children,
|
|
114
118
|
std::vector<services::Service *> services,
|
|
115
|
-
std::vector<std::unique_ptr<BundlePort>>
|
|
116
|
-
: HWModule(info, std::move(children), services, ports),
|
|
119
|
+
std::vector<std::unique_ptr<BundlePort>> &&ports)
|
|
120
|
+
: HWModule(info, std::move(children), services, std::move(ports)),
|
|
121
|
+
id(id) {}
|
|
117
122
|
|
|
118
123
|
/// Get the instance's ID, which it will always have.
|
|
119
|
-
|
|
124
|
+
AppID getID() const { return id; }
|
|
120
125
|
|
|
121
126
|
protected:
|
|
122
127
|
const AppID id;
|
esiaccel/include/esi/Manifest.h
CHANGED
|
@@ -65,8 +65,6 @@ private:
|
|
|
65
65
|
|
|
66
66
|
} // namespace esi
|
|
67
67
|
|
|
68
|
-
std::ostream &operator<<(std::ostream &os, const esi::AppID &id);
|
|
69
|
-
std::ostream &operator<<(std::ostream &, const esi::AppIDPath &);
|
|
70
68
|
std::ostream &operator<<(std::ostream &, const esi::ModuleInfo &);
|
|
71
69
|
|
|
72
70
|
#endif // ESI_MANIFEST_H
|
esiaccel/include/esi/Ports.h
CHANGED
|
@@ -35,13 +35,81 @@ using PortMap = std::map<std::string, ChannelPort &>;
|
|
|
35
35
|
/// but used by higher level APIs which add types.
|
|
36
36
|
class ChannelPort {
|
|
37
37
|
public:
|
|
38
|
-
ChannelPort(const Type *type)
|
|
38
|
+
ChannelPort(const Type *type);
|
|
39
39
|
virtual ~ChannelPort() {}
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
struct ConnectOptions {
|
|
42
|
+
/// The buffer size is optional and should be considered merely a hint.
|
|
43
|
+
/// Individual implementations use it however they like. The unit is number
|
|
44
|
+
/// of messages of the port type.
|
|
45
|
+
std::optional<unsigned> bufferSize = std::nullopt;
|
|
46
|
+
|
|
47
|
+
/// If the type of this port is a window, translate the incoming/outgoing
|
|
48
|
+
/// data into its underlying ('into') type. For 'into' types without lists,
|
|
49
|
+
/// just re-arranges the data fields from the lowered type to the 'into'
|
|
50
|
+
/// type.
|
|
51
|
+
///
|
|
52
|
+
/// If this option is false, no translation is done and the data is
|
|
53
|
+
/// passed through as-is. Same is true for non-windowed types.
|
|
54
|
+
///
|
|
55
|
+
/// For messages with lists, only two types are supported:
|
|
56
|
+
/// 1) Parallel encoding includes any 'header' data with each frame. Said
|
|
57
|
+
/// header data is the same across all frames, so this encoding is
|
|
58
|
+
/// inefficient but is commonly used for on-chip streaming interfaces.
|
|
59
|
+
/// Each frame contains a 'last' field to indicate the end of the list.
|
|
60
|
+
/// In cases where 'numItems' is greater than 1, a field named
|
|
61
|
+
/// '<listField>_size' indicates the number of valid items in that
|
|
62
|
+
/// frame.
|
|
63
|
+
/// 2) Serial (bulk transfer) encoding, where a 'header' frame precedes
|
|
64
|
+
/// the list data frame. Said header frame contains a 'count' field
|
|
65
|
+
/// indicating the number of items in the list. Importantly, the
|
|
66
|
+
/// header frame is always re-transmitted after the specified number of
|
|
67
|
+
/// list items have been sent. If the 'count' field is zero, the end of
|
|
68
|
+
/// the list has been reached. If it is non-zero, the message has not
|
|
69
|
+
/// been completely transmitted and reading should continue until a
|
|
70
|
+
/// 'count' of zero is received.
|
|
71
|
+
///
|
|
72
|
+
/// In both cases, the host-side MessageData contains the complete header
|
|
73
|
+
/// followed by the list data. In other words, header data is not duplicated
|
|
74
|
+
/// in the returned message. So for a windowed type with header fields and
|
|
75
|
+
/// a list of (x,y) coordinates, the host memory layout would be:
|
|
76
|
+
/// ```
|
|
77
|
+
/// struct ExampleList {
|
|
78
|
+
/// uint32_t headerField2; // SystemVerilog ordering
|
|
79
|
+
/// uint32_t headerField1;
|
|
80
|
+
/// size_t list_length; // Number list items
|
|
81
|
+
/// struct { uint16_t y, x; } list_data[];
|
|
82
|
+
/// }
|
|
83
|
+
/// ```
|
|
84
|
+
///
|
|
85
|
+
/// In a parallel encoding, each frame's wire format (from hardware) is:
|
|
86
|
+
/// ```
|
|
87
|
+
/// struct ExampleListFrame {
|
|
88
|
+
/// uint8_t list_last; // Non-zero indicates last item in list
|
|
89
|
+
/// struct { uint16_t y, x; } list_data[numItems]; // SV field ordering
|
|
90
|
+
/// uint32_t headerField2; // SV struct ordering (reversed)
|
|
91
|
+
/// uint32_t headerField1;
|
|
92
|
+
/// }
|
|
93
|
+
/// ```
|
|
94
|
+
///
|
|
95
|
+
/// Important note: for consistency, preserves SystemVerilog struct field
|
|
96
|
+
/// ordering! So it's the opposite of C struct ordering.
|
|
97
|
+
///
|
|
98
|
+
/// Implementation status:
|
|
99
|
+
/// - Only parallel list encoding is supported.
|
|
100
|
+
/// - Fields must be byte-aligned.
|
|
101
|
+
///
|
|
102
|
+
/// See the CIRCT documentation (or td files) for more details on windowed
|
|
103
|
+
/// messages.
|
|
104
|
+
bool translateMessage = true;
|
|
105
|
+
|
|
106
|
+
ConnectOptions(std::optional<unsigned> bufferSize = std::nullopt,
|
|
107
|
+
bool translateMessage = true)
|
|
108
|
+
: bufferSize(bufferSize), translateMessage(translateMessage) {}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/// Set up a connection to the accelerator.
|
|
112
|
+
virtual void connect(const ConnectOptions &options = ConnectOptions()) = 0;
|
|
45
113
|
virtual void disconnect() = 0;
|
|
46
114
|
virtual bool isConnected() const = 0;
|
|
47
115
|
|
|
@@ -64,13 +132,74 @@ public:
|
|
|
64
132
|
protected:
|
|
65
133
|
const Type *type;
|
|
66
134
|
|
|
135
|
+
/// Instructions for translating windowed types. Precomputes and optimizes a
|
|
136
|
+
/// list of copy operations.
|
|
137
|
+
struct TranslationInfo {
|
|
138
|
+
TranslationInfo(const WindowType *windowType) : windowType(windowType) {}
|
|
139
|
+
|
|
140
|
+
/// Precompute and optimize the copy operations for translating frames.
|
|
141
|
+
void precomputeFrameInfo();
|
|
142
|
+
|
|
143
|
+
/// The window type being translated.
|
|
144
|
+
const WindowType *windowType;
|
|
145
|
+
|
|
146
|
+
/// A copy operation for translating between frame data and the translation.
|
|
147
|
+
/// Run this during the translation.
|
|
148
|
+
struct CopyOp {
|
|
149
|
+
/// Offset in the incoming/outgoing frame data.
|
|
150
|
+
size_t frameOffset;
|
|
151
|
+
/// Offset in the translation buffer.
|
|
152
|
+
size_t bufferOffset;
|
|
153
|
+
/// Number of bytes to copy.
|
|
154
|
+
size_t size;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/// Information about a list field within a frame (for parallel encoding).
|
|
158
|
+
/// Note: Currently only numItems == 1 is supported (one list element per
|
|
159
|
+
/// frame).
|
|
160
|
+
struct ListFieldInfo {
|
|
161
|
+
/// Name of the list field.
|
|
162
|
+
std::string fieldName;
|
|
163
|
+
/// Offset of the list data array in the frame.
|
|
164
|
+
size_t dataOffset;
|
|
165
|
+
/// Size of each list element in bytes.
|
|
166
|
+
size_t elementSize;
|
|
167
|
+
/// Offset of the 'last' field in the frame.
|
|
168
|
+
size_t lastFieldOffset;
|
|
169
|
+
/// Offset in the translation buffer where list length is stored.
|
|
170
|
+
size_t listLengthBufferOffset;
|
|
171
|
+
/// Offset in the translation buffer where list data starts.
|
|
172
|
+
size_t listDataBufferOffset;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/// Information about each frame in the windowed type.
|
|
176
|
+
struct FrameInfo {
|
|
177
|
+
/// The total size of a frame in bytes.
|
|
178
|
+
size_t expectedSize;
|
|
179
|
+
/// Precomputed copy operations for translating this frame (non-list
|
|
180
|
+
/// fields).
|
|
181
|
+
std::vector<CopyOp> copyOps;
|
|
182
|
+
/// Information about list fields in this frame (parallel encoding).
|
|
183
|
+
/// Currently only one list field per frame is supported.
|
|
184
|
+
std::optional<ListFieldInfo> listField;
|
|
185
|
+
};
|
|
186
|
+
/// Precomputed information about each frame.
|
|
187
|
+
std::vector<FrameInfo> frames;
|
|
188
|
+
/// Size of the 'into' type in bytes (for fixed-size types).
|
|
189
|
+
/// For types with lists, this is the size of the fixed header portion.
|
|
190
|
+
size_t intoTypeBytes = 0;
|
|
191
|
+
/// True if the window contains a list field (variable-size message).
|
|
192
|
+
bool hasListField = false;
|
|
193
|
+
};
|
|
194
|
+
std::unique_ptr<TranslationInfo> translationInfo;
|
|
195
|
+
|
|
67
196
|
/// Method called by poll() to actually poll the channel if the channel is
|
|
68
197
|
/// connected.
|
|
69
198
|
virtual bool pollImpl() { return false; }
|
|
70
199
|
|
|
71
200
|
/// Called by all connect methods to let backends initiate the underlying
|
|
72
201
|
/// connections.
|
|
73
|
-
virtual void connectImpl(
|
|
202
|
+
virtual void connectImpl(const ConnectOptions &options) {}
|
|
74
203
|
};
|
|
75
204
|
|
|
76
205
|
/// A ChannelPort which sends data to the accelerator.
|
|
@@ -78,9 +207,11 @@ class WriteChannelPort : public ChannelPort {
|
|
|
78
207
|
public:
|
|
79
208
|
using ChannelPort::ChannelPort;
|
|
80
209
|
|
|
81
|
-
virtual void
|
|
82
|
-
|
|
83
|
-
|
|
210
|
+
virtual void connect(const ConnectOptions &options = {}) override {
|
|
211
|
+
translateMessages = options.translateMessage && translationInfo;
|
|
212
|
+
if (translateMessages)
|
|
213
|
+
translationInfo->precomputeFrameInfo();
|
|
214
|
+
connectImpl(options);
|
|
84
215
|
connected = true;
|
|
85
216
|
}
|
|
86
217
|
virtual void disconnect() override { connected = false; }
|
|
@@ -88,12 +219,72 @@ public:
|
|
|
88
219
|
|
|
89
220
|
/// A very basic blocking write API. Will likely change for performance
|
|
90
221
|
/// reasons.
|
|
91
|
-
|
|
222
|
+
void write(const MessageData &data) {
|
|
223
|
+
if (translateMessages) {
|
|
224
|
+
assert(translationBuffer.empty() &&
|
|
225
|
+
"Cannot call write() with pending translated messages");
|
|
226
|
+
translateOutgoing(data);
|
|
227
|
+
for (auto &msg : translationBuffer)
|
|
228
|
+
writeImpl(msg);
|
|
229
|
+
translationBuffer.clear();
|
|
230
|
+
} else {
|
|
231
|
+
writeImpl(data);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/// A basic non-blocking write API. Returns true if any of the data was queued
|
|
236
|
+
/// and/or sent. If the data type is a window a 'true' return does not
|
|
237
|
+
/// indicate that the message has been completely written. The 'flush' method
|
|
238
|
+
/// can be used to check that the entire buffer has been written. It is
|
|
239
|
+
/// invalid for backends to always return false (i.e. backends must eventually
|
|
240
|
+
/// ensure that writes may succeed).
|
|
241
|
+
bool tryWrite(const MessageData &data) {
|
|
242
|
+
if (translateMessages) {
|
|
243
|
+
// Do not accept a new message if there are pending messages to flush.
|
|
244
|
+
if (!flush())
|
|
245
|
+
return false;
|
|
246
|
+
assert(translationBuffer.empty() &&
|
|
247
|
+
"Translation buffer should be empty after successful flush");
|
|
248
|
+
translateOutgoing(data);
|
|
249
|
+
flush();
|
|
250
|
+
return true;
|
|
251
|
+
} else {
|
|
252
|
+
return tryWriteImpl(data);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/// Flush any buffered data. Returns true if all data was flushed.
|
|
256
|
+
///
|
|
257
|
+
/// If `translateMessages` is false, calling `flush()` will immediately return
|
|
258
|
+
/// true and perform no action, as there is no buffered data to flush.
|
|
259
|
+
bool flush() {
|
|
260
|
+
while (translationBufferIdx < translationBuffer.size()) {
|
|
261
|
+
if (!tryWriteImpl(translationBuffer[translationBufferIdx]))
|
|
262
|
+
return false;
|
|
263
|
+
++translationBufferIdx;
|
|
264
|
+
}
|
|
265
|
+
translationBuffer.clear();
|
|
266
|
+
translationBufferIdx = 0;
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
92
269
|
|
|
93
|
-
|
|
94
|
-
///
|
|
95
|
-
|
|
96
|
-
|
|
270
|
+
protected:
|
|
271
|
+
/// Implementation for write(). Subclasses must implement this.
|
|
272
|
+
virtual void writeImpl(const MessageData &) = 0;
|
|
273
|
+
|
|
274
|
+
/// Implementation for tryWrite(). Subclasses must implement this.
|
|
275
|
+
virtual bool tryWriteImpl(const MessageData &data) = 0;
|
|
276
|
+
|
|
277
|
+
/// Whether to translate outgoing data if the port type is a window type. Set
|
|
278
|
+
/// by the connect() method.
|
|
279
|
+
bool translateMessages = false;
|
|
280
|
+
/// If tryWrite cannot write all the messages of a windowed type at once, it
|
|
281
|
+
/// stores them here and writes them out one by one on subsequent calls.
|
|
282
|
+
std::vector<MessageData> translationBuffer;
|
|
283
|
+
/// Index of the next message to write in translationBuffer.
|
|
284
|
+
size_t translationBufferIdx = 0;
|
|
285
|
+
/// Translate outgoing data if the port type is a window type. Append the new
|
|
286
|
+
/// message 'chunks' to translationBuffer.
|
|
287
|
+
void translateOutgoing(const MessageData &data);
|
|
97
288
|
|
|
98
289
|
private:
|
|
99
290
|
volatile bool connected = false;
|
|
@@ -105,15 +296,18 @@ public:
|
|
|
105
296
|
UnknownWriteChannelPort(const Type *type, std::string errmsg)
|
|
106
297
|
: WriteChannelPort(type), errmsg(errmsg) {}
|
|
107
298
|
|
|
108
|
-
void connect(
|
|
299
|
+
void connect(const ConnectOptions &options = {}) override {
|
|
109
300
|
throw std::runtime_error(errmsg);
|
|
110
301
|
}
|
|
111
|
-
|
|
112
|
-
|
|
302
|
+
|
|
303
|
+
protected:
|
|
304
|
+
void writeImpl(const MessageData &) override {
|
|
305
|
+
throw std::runtime_error(errmsg);
|
|
306
|
+
}
|
|
307
|
+
bool tryWriteImpl(const MessageData &) override {
|
|
113
308
|
throw std::runtime_error(errmsg);
|
|
114
309
|
}
|
|
115
310
|
|
|
116
|
-
protected:
|
|
117
311
|
std::string errmsg;
|
|
118
312
|
};
|
|
119
313
|
|
|
@@ -143,7 +337,7 @@ public:
|
|
|
143
337
|
//===--------------------------------------------------------------------===//
|
|
144
338
|
|
|
145
339
|
virtual void connect(std::function<bool(MessageData)> callback,
|
|
146
|
-
|
|
340
|
+
const ConnectOptions &options = {});
|
|
147
341
|
|
|
148
342
|
//===--------------------------------------------------------------------===//
|
|
149
343
|
// Polling mode methods: To use futures or blocking reads, connect without any
|
|
@@ -154,8 +348,7 @@ public:
|
|
|
154
348
|
static constexpr uint64_t DefaultMaxDataQueueMsgs = 32;
|
|
155
349
|
|
|
156
350
|
/// Connect to the channel in polling mode.
|
|
157
|
-
virtual void
|
|
158
|
-
connect(std::optional<unsigned> bufferSize = std::nullopt) override;
|
|
351
|
+
virtual void connect(const ConnectOptions &options = {}) override;
|
|
159
352
|
|
|
160
353
|
/// Asynchronous read.
|
|
161
354
|
virtual std::future<MessageData> readAsync();
|
|
@@ -184,6 +377,20 @@ protected:
|
|
|
184
377
|
/// Backends call this callback when new data is available.
|
|
185
378
|
std::function<bool(MessageData)> callback;
|
|
186
379
|
|
|
380
|
+
/// Window translation support.
|
|
381
|
+
std::vector<uint8_t> translationBuffer;
|
|
382
|
+
/// Index of the next expected frame (for multi-frame windows).
|
|
383
|
+
size_t nextFrameIndex = 0;
|
|
384
|
+
/// For list fields: accumulated list data across frames.
|
|
385
|
+
std::vector<uint8_t> listDataBuffer;
|
|
386
|
+
/// Flag to track whether we're in the middle of accumulating list data.
|
|
387
|
+
bool accumulatingListData = false;
|
|
388
|
+
/// Reset translation state buffers and indices.
|
|
389
|
+
void resetTranslationState();
|
|
390
|
+
/// Translate incoming data if the port type is a window type. Returns true if
|
|
391
|
+
/// the message has been completely received.
|
|
392
|
+
bool translateIncoming(MessageData &data);
|
|
393
|
+
|
|
187
394
|
//===--------------------------------------------------------------------===//
|
|
188
395
|
// Polling mode members.
|
|
189
396
|
//===--------------------------------------------------------------------===//
|
|
@@ -206,10 +413,10 @@ public:
|
|
|
206
413
|
: ReadChannelPort(type), errmsg(errmsg) {}
|
|
207
414
|
|
|
208
415
|
void connect(std::function<bool(MessageData)> callback,
|
|
209
|
-
|
|
416
|
+
const ConnectOptions &options = ConnectOptions()) override {
|
|
210
417
|
throw std::runtime_error(errmsg);
|
|
211
418
|
}
|
|
212
|
-
void connect(
|
|
419
|
+
void connect(const ConnectOptions &options = ConnectOptions()) override {
|
|
213
420
|
throw std::runtime_error(errmsg);
|
|
214
421
|
}
|
|
215
422
|
std::future<MessageData> readAsync() override {
|