esiaccel 0.2.3.dev49__cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.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.
Potentially problematic release.
This version of esiaccel might be problematic. Click here for more details.
- esiaccel/__init__.py +31 -0
- esiaccel/accelerator.py +134 -0
- esiaccel/bin/esi-cosim.py +104 -0
- esiaccel/bin/esiquery +0 -0
- esiaccel/cmake/esiaccelConfig.cmake +49 -0
- esiaccel/codegen.py +197 -0
- esiaccel/cosim/Cosim_CycleCount.sv +84 -0
- esiaccel/cosim/Cosim_DpiPkg.sv +85 -0
- esiaccel/cosim/Cosim_Endpoint.sv +218 -0
- esiaccel/cosim/Cosim_Manifest.sv +32 -0
- esiaccel/cosim/driver.cpp +131 -0
- esiaccel/cosim/driver.sv +74 -0
- esiaccel/cosim/questa.py +141 -0
- esiaccel/cosim/simulator.py +383 -0
- esiaccel/cosim/verilator.py +92 -0
- esiaccel/esiCppAccel.cpython-314-x86_64-linux-gnu.so +0 -0
- esiaccel/esiCppAccel.pyi +337 -0
- esiaccel/include/esi/Accelerator.h +229 -0
- esiaccel/include/esi/CLI.h +77 -0
- esiaccel/include/esi/Common.h +182 -0
- esiaccel/include/esi/Context.h +82 -0
- esiaccel/include/esi/Design.h +132 -0
- esiaccel/include/esi/Engines.h +124 -0
- esiaccel/include/esi/Logging.h +231 -0
- esiaccel/include/esi/Manifest.h +70 -0
- esiaccel/include/esi/Ports.h +482 -0
- esiaccel/include/esi/Services.h +467 -0
- esiaccel/include/esi/Types.h +334 -0
- esiaccel/include/esi/Utils.h +102 -0
- esiaccel/include/esi/Values.h +313 -0
- esiaccel/include/esi/backends/Cosim.h +78 -0
- esiaccel/include/esi/backends/RpcClient.h +97 -0
- esiaccel/include/esi/backends/RpcServer.h +73 -0
- esiaccel/include/esi/backends/Trace.h +87 -0
- esiaccel/lib/libCosimBackend.so +0 -0
- esiaccel/lib/libCosimRpc.so +0 -0
- esiaccel/lib/libESICppRuntime.so +0 -0
- esiaccel/lib/libEsiCosimDpiServer.so +0 -0
- esiaccel/lib/libMtiPli.so +0 -0
- esiaccel/types.py +565 -0
- esiaccel/utils.py +54 -0
- esiaccel-0.2.3.dev49.dist-info/METADATA +254 -0
- esiaccel-0.2.3.dev49.dist-info/RECORD +47 -0
- esiaccel-0.2.3.dev49.dist-info/WHEEL +6 -0
- esiaccel-0.2.3.dev49.dist-info/entry_points.txt +4 -0
- esiaccel-0.2.3.dev49.dist-info/licenses/LICENSE +234 -0
- esiaccel-0.2.3.dev49.dist-info/top_level.txt +1 -0
esiaccel/esiCppAccel.pyi
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
from collections.abc import Callable, Sequence
|
|
2
|
+
import enum
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Type:
|
|
6
|
+
def __init__(self, id: str) -> None: ...
|
|
7
|
+
|
|
8
|
+
@property
|
|
9
|
+
def id(self) -> str: ...
|
|
10
|
+
|
|
11
|
+
def __repr__(self) -> str: ...
|
|
12
|
+
|
|
13
|
+
class ChannelType(Type):
|
|
14
|
+
def __init__(self, id: str, inner: Type) -> None: ...
|
|
15
|
+
|
|
16
|
+
@property
|
|
17
|
+
def inner(self) -> Type: ...
|
|
18
|
+
|
|
19
|
+
class Direction(enum.Enum):
|
|
20
|
+
To = 0
|
|
21
|
+
|
|
22
|
+
From = 1
|
|
23
|
+
|
|
24
|
+
To: Direction = Direction.To
|
|
25
|
+
|
|
26
|
+
From: Direction = Direction.From
|
|
27
|
+
|
|
28
|
+
class BundleType(Type):
|
|
29
|
+
def __init__(self, id: str, channels: Sequence["std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, esi::BundleType::Direction, esi::Type const*>"]) -> None: ...
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def channels(self) -> list["std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, esi::BundleType::Direction, esi::Type const*>"]: ...
|
|
33
|
+
|
|
34
|
+
class VoidType(Type):
|
|
35
|
+
def __init__(self, id: str) -> None: ...
|
|
36
|
+
|
|
37
|
+
class AnyType(Type):
|
|
38
|
+
def __init__(self, id: str) -> None: ...
|
|
39
|
+
|
|
40
|
+
class BitVectorType(Type):
|
|
41
|
+
def __init__(self, id: str, width: int) -> None: ...
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def width(self) -> int: ...
|
|
45
|
+
|
|
46
|
+
class BitsType(BitVectorType):
|
|
47
|
+
def __init__(self, id: str, width: int) -> None: ...
|
|
48
|
+
|
|
49
|
+
class IntegerType(BitVectorType):
|
|
50
|
+
def __init__(self, id: str, width: int) -> None: ...
|
|
51
|
+
|
|
52
|
+
class SIntType(IntegerType):
|
|
53
|
+
def __init__(self, id: str, width: int) -> None: ...
|
|
54
|
+
|
|
55
|
+
class UIntType(IntegerType):
|
|
56
|
+
def __init__(self, id: str, width: int) -> None: ...
|
|
57
|
+
|
|
58
|
+
class StructType(Type):
|
|
59
|
+
def __init__(self, id: str, fields: Sequence[tuple[str, Type]], reverse: bool = True) -> None: ...
|
|
60
|
+
|
|
61
|
+
@property
|
|
62
|
+
def fields(self) -> list[tuple[str, Type]]: ...
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def reverse(self) -> bool: ...
|
|
66
|
+
|
|
67
|
+
class ArrayType(Type):
|
|
68
|
+
def __init__(self, id: str, element_type: Type, size: int) -> None: ...
|
|
69
|
+
|
|
70
|
+
@property
|
|
71
|
+
def element(self) -> Type: ...
|
|
72
|
+
|
|
73
|
+
@property
|
|
74
|
+
def size(self) -> int: ...
|
|
75
|
+
|
|
76
|
+
class Constant:
|
|
77
|
+
@property
|
|
78
|
+
def value(self) -> object: ...
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def type(self) -> object: ...
|
|
82
|
+
|
|
83
|
+
class AppID:
|
|
84
|
+
def __init__(self, name: str, idx: int | None = None) -> None: ...
|
|
85
|
+
|
|
86
|
+
@property
|
|
87
|
+
def name(self) -> str: ...
|
|
88
|
+
|
|
89
|
+
@property
|
|
90
|
+
def idx(self) -> object: ...
|
|
91
|
+
|
|
92
|
+
def __repr__(self) -> str: ...
|
|
93
|
+
|
|
94
|
+
def __eq__(self, arg: AppID, /) -> bool: ...
|
|
95
|
+
|
|
96
|
+
def __hash__(self) -> int: ...
|
|
97
|
+
|
|
98
|
+
class AppIDPath:
|
|
99
|
+
def __repr__(self) -> str: ...
|
|
100
|
+
|
|
101
|
+
class ModuleInfo:
|
|
102
|
+
@property
|
|
103
|
+
def name(self) -> str | None: ...
|
|
104
|
+
|
|
105
|
+
@property
|
|
106
|
+
def summary(self) -> str | None: ...
|
|
107
|
+
|
|
108
|
+
@property
|
|
109
|
+
def version(self) -> str | None: ...
|
|
110
|
+
|
|
111
|
+
@property
|
|
112
|
+
def repo(self) -> str | None: ...
|
|
113
|
+
|
|
114
|
+
@property
|
|
115
|
+
def commit_hash(self) -> str | None: ...
|
|
116
|
+
|
|
117
|
+
@property
|
|
118
|
+
def constants(self) -> dict[str, Constant]: ...
|
|
119
|
+
|
|
120
|
+
def __repr__(self) -> str: ...
|
|
121
|
+
|
|
122
|
+
class LogLevel(enum.Enum):
|
|
123
|
+
Debug = 1
|
|
124
|
+
|
|
125
|
+
Info = 2
|
|
126
|
+
|
|
127
|
+
Warning = 3
|
|
128
|
+
|
|
129
|
+
Error = 4
|
|
130
|
+
|
|
131
|
+
Debug: LogLevel = LogLevel.Debug
|
|
132
|
+
|
|
133
|
+
Info: LogLevel = LogLevel.Info
|
|
134
|
+
|
|
135
|
+
Warning: LogLevel = LogLevel.Warning
|
|
136
|
+
|
|
137
|
+
Error: LogLevel = LogLevel.Error
|
|
138
|
+
|
|
139
|
+
class Logger:
|
|
140
|
+
pass
|
|
141
|
+
|
|
142
|
+
class Service:
|
|
143
|
+
def get_service_symbol(self) -> str: ...
|
|
144
|
+
|
|
145
|
+
class SysInfo(Service):
|
|
146
|
+
def esi_version(self) -> int: ...
|
|
147
|
+
|
|
148
|
+
def json_manifest(self) -> str: ...
|
|
149
|
+
|
|
150
|
+
def cycle_count(self) -> int | None:
|
|
151
|
+
"""Get the current cycle count of the accelerator system"""
|
|
152
|
+
|
|
153
|
+
def core_clock_frequency(self) -> int | None:
|
|
154
|
+
"""Get the core clock frequency of the accelerator system in Hz"""
|
|
155
|
+
|
|
156
|
+
class MMIORegionDescriptor:
|
|
157
|
+
@property
|
|
158
|
+
def base(self) -> int: ...
|
|
159
|
+
|
|
160
|
+
@property
|
|
161
|
+
def size(self) -> int: ...
|
|
162
|
+
|
|
163
|
+
class MMIO(Service):
|
|
164
|
+
def read(self, arg: int, /) -> int: ...
|
|
165
|
+
|
|
166
|
+
def write(self, arg0: int, arg1: int, /) -> None: ...
|
|
167
|
+
|
|
168
|
+
@property
|
|
169
|
+
def regions(self) -> dict[AppIDPath, MMIORegionDescriptor]: ...
|
|
170
|
+
|
|
171
|
+
class HostMemRegion:
|
|
172
|
+
@property
|
|
173
|
+
def ptr(self) -> int: ...
|
|
174
|
+
|
|
175
|
+
@property
|
|
176
|
+
def size(self) -> int: ...
|
|
177
|
+
|
|
178
|
+
class HostMemOptions:
|
|
179
|
+
def __init__(self) -> None: ...
|
|
180
|
+
|
|
181
|
+
@property
|
|
182
|
+
def writeable(self) -> bool: ...
|
|
183
|
+
|
|
184
|
+
@writeable.setter
|
|
185
|
+
def writeable(self, arg: bool, /) -> None: ...
|
|
186
|
+
|
|
187
|
+
@property
|
|
188
|
+
def use_large_pages(self) -> bool: ...
|
|
189
|
+
|
|
190
|
+
@use_large_pages.setter
|
|
191
|
+
def use_large_pages(self, arg: bool, /) -> None: ...
|
|
192
|
+
|
|
193
|
+
def __repr__(self) -> str: ...
|
|
194
|
+
|
|
195
|
+
class HostMem(Service):
|
|
196
|
+
def allocate(self, size: int, options: HostMemOptions = ...) -> HostMemRegion: ...
|
|
197
|
+
|
|
198
|
+
def map_memory(self, ptr: int, size: int, options: HostMemOptions = ...) -> bool: ...
|
|
199
|
+
|
|
200
|
+
def unmap_memory(self, ptr: int) -> None: ...
|
|
201
|
+
|
|
202
|
+
class TelemetryService(Service):
|
|
203
|
+
pass
|
|
204
|
+
|
|
205
|
+
class MessageDataFuture:
|
|
206
|
+
def valid(self) -> bool: ...
|
|
207
|
+
|
|
208
|
+
def wait(self) -> None: ...
|
|
209
|
+
|
|
210
|
+
def get(self) -> bytearray: ...
|
|
211
|
+
|
|
212
|
+
class ConnectOptions:
|
|
213
|
+
def __init__(self) -> None: ...
|
|
214
|
+
|
|
215
|
+
@property
|
|
216
|
+
def buffer_size(self) -> int | None: ...
|
|
217
|
+
|
|
218
|
+
@buffer_size.setter
|
|
219
|
+
def buffer_size(self, buffer_size: int | None) -> None: ...
|
|
220
|
+
|
|
221
|
+
@property
|
|
222
|
+
def translate_message(self) -> bool: ...
|
|
223
|
+
|
|
224
|
+
@translate_message.setter
|
|
225
|
+
def translate_message(self, arg: bool, /) -> None: ...
|
|
226
|
+
|
|
227
|
+
class ChannelPort:
|
|
228
|
+
def connect(self, options: ConnectOptions) -> None:
|
|
229
|
+
"""Connect with specified options"""
|
|
230
|
+
|
|
231
|
+
def disconnect(self) -> None: ...
|
|
232
|
+
|
|
233
|
+
@property
|
|
234
|
+
def type(self) -> Type: ...
|
|
235
|
+
|
|
236
|
+
class WriteChannelPort(ChannelPort):
|
|
237
|
+
def write(self, arg: bytearray, /) -> None: ...
|
|
238
|
+
|
|
239
|
+
def tryWrite(self, arg: bytearray, /) -> bool: ...
|
|
240
|
+
|
|
241
|
+
class ReadChannelPort(ChannelPort):
|
|
242
|
+
def read(self) -> bytearray:
|
|
243
|
+
"""Read data from the channel. Blocking."""
|
|
244
|
+
|
|
245
|
+
def read_async(self) -> MessageDataFuture: ...
|
|
246
|
+
|
|
247
|
+
class BundlePort:
|
|
248
|
+
@property
|
|
249
|
+
def id(self) -> AppID: ...
|
|
250
|
+
|
|
251
|
+
@property
|
|
252
|
+
def channels(self) -> dict[str, ChannelPort]: ...
|
|
253
|
+
|
|
254
|
+
def getWrite(self, arg: str, /) -> WriteChannelPort: ...
|
|
255
|
+
|
|
256
|
+
def getRead(self, arg: str, /) -> ReadChannelPort: ...
|
|
257
|
+
|
|
258
|
+
class ServicePort(BundlePort):
|
|
259
|
+
pass
|
|
260
|
+
|
|
261
|
+
class MMIORegion(ServicePort):
|
|
262
|
+
@property
|
|
263
|
+
def descriptor(self) -> MMIORegionDescriptor: ...
|
|
264
|
+
|
|
265
|
+
def read(self, arg: int, /) -> int: ...
|
|
266
|
+
|
|
267
|
+
def write(self, arg0: int, arg1: int, /) -> None: ...
|
|
268
|
+
|
|
269
|
+
class Function(ServicePort):
|
|
270
|
+
def call(self, arg: bytearray, /) -> MessageDataFuture: ...
|
|
271
|
+
|
|
272
|
+
def connect(self) -> None: ...
|
|
273
|
+
|
|
274
|
+
class Callback(ServicePort):
|
|
275
|
+
def connect(self, arg: Callable[[object], object], /) -> None: ...
|
|
276
|
+
|
|
277
|
+
class Metric(ServicePort):
|
|
278
|
+
def connect(self) -> None: ...
|
|
279
|
+
|
|
280
|
+
def read(self) -> MessageDataFuture: ...
|
|
281
|
+
|
|
282
|
+
def readInt(self) -> int: ...
|
|
283
|
+
|
|
284
|
+
class HWModule:
|
|
285
|
+
@property
|
|
286
|
+
def info(self) -> ModuleInfo | None: ...
|
|
287
|
+
|
|
288
|
+
@property
|
|
289
|
+
def ports(self) -> dict[AppID, BundlePort]: ...
|
|
290
|
+
|
|
291
|
+
@property
|
|
292
|
+
def services(self) -> list[Service]: ...
|
|
293
|
+
|
|
294
|
+
@property
|
|
295
|
+
def children(self) -> dict[AppID, Instance]: ...
|
|
296
|
+
|
|
297
|
+
class Instance(HWModule):
|
|
298
|
+
@property
|
|
299
|
+
def id(self) -> AppID: ...
|
|
300
|
+
|
|
301
|
+
class Accelerator(HWModule):
|
|
302
|
+
pass
|
|
303
|
+
|
|
304
|
+
class AcceleratorConnection:
|
|
305
|
+
def sysinfo(self) -> SysInfo: ...
|
|
306
|
+
|
|
307
|
+
def get_service_mmio(self) -> MMIO: ...
|
|
308
|
+
|
|
309
|
+
def get_service_hostmem(self) -> HostMem: ...
|
|
310
|
+
|
|
311
|
+
def get_accelerator(self) -> Accelerator: ...
|
|
312
|
+
|
|
313
|
+
class Context:
|
|
314
|
+
"""
|
|
315
|
+
An ESI context owns everything -- types, accelerator connections, and the accelerator facade (aka Accelerator) itself. It MUST NOT be garbage collected while the accelerator is still in use. When it is destroyed, all accelerator connections are disconnected.
|
|
316
|
+
"""
|
|
317
|
+
|
|
318
|
+
def __init__(self) -> None:
|
|
319
|
+
"""Create a context with a default logger."""
|
|
320
|
+
|
|
321
|
+
def connect(self, arg0: str, arg1: str, /) -> AcceleratorConnection: ...
|
|
322
|
+
|
|
323
|
+
def set_stdio_logger(self, arg: LogLevel, /) -> None: ...
|
|
324
|
+
|
|
325
|
+
class Manifest:
|
|
326
|
+
def __init__(self, arg0: Context, arg1: str, /) -> None: ...
|
|
327
|
+
|
|
328
|
+
@property
|
|
329
|
+
def api_version(self) -> int: ...
|
|
330
|
+
|
|
331
|
+
def build_accelerator(self, arg: AcceleratorConnection, /) -> Accelerator: ...
|
|
332
|
+
|
|
333
|
+
@property
|
|
334
|
+
def type_table(self) -> list[object]: ...
|
|
335
|
+
|
|
336
|
+
@property
|
|
337
|
+
def module_infos(self) -> list[ModuleInfo]: ...
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
//===- Accelerator.h - Base ESI runtime API ---------------------*- 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
|
+
// Basic ESI APIs. The 'Accelerator' class is the superclass for all accelerator
|
|
10
|
+
// backends. It should (usually) provide enough functionality such that users do
|
|
11
|
+
// not have to interact with the platform-specific backend implementation with
|
|
12
|
+
// the exception of connecting to the accelerator.
|
|
13
|
+
//
|
|
14
|
+
// DO NOT EDIT!
|
|
15
|
+
// This file is distributed as part of an ESI package. The source for this file
|
|
16
|
+
// should always be modified within CIRCT.
|
|
17
|
+
//
|
|
18
|
+
//===----------------------------------------------------------------------===//
|
|
19
|
+
|
|
20
|
+
// NOLINTNEXTLINE(llvm-header-guard)
|
|
21
|
+
#ifndef ESI_ACCELERATOR_H
|
|
22
|
+
#define ESI_ACCELERATOR_H
|
|
23
|
+
|
|
24
|
+
#include "esi/Context.h"
|
|
25
|
+
#include "esi/Design.h"
|
|
26
|
+
#include "esi/Engines.h"
|
|
27
|
+
#include "esi/Manifest.h"
|
|
28
|
+
#include "esi/Ports.h"
|
|
29
|
+
#include "esi/Services.h"
|
|
30
|
+
|
|
31
|
+
#include <functional>
|
|
32
|
+
#include <map>
|
|
33
|
+
#include <memory>
|
|
34
|
+
#include <string>
|
|
35
|
+
#include <typeinfo>
|
|
36
|
+
|
|
37
|
+
namespace esi {
|
|
38
|
+
// Forward declarations.
|
|
39
|
+
class AcceleratorServiceThread;
|
|
40
|
+
|
|
41
|
+
//===----------------------------------------------------------------------===//
|
|
42
|
+
// Metadata constants which may or may not be used by various backends. Provided
|
|
43
|
+
// here since they are intended to be somewhat standard.
|
|
44
|
+
//===----------------------------------------------------------------------===//
|
|
45
|
+
|
|
46
|
+
constexpr uint32_t MetadataOffset = 8;
|
|
47
|
+
|
|
48
|
+
constexpr uint64_t MagicNumberLo = 0xE5100E51;
|
|
49
|
+
constexpr uint64_t MagicNumberHi = 0x207D98E5;
|
|
50
|
+
constexpr uint64_t MagicNumber = MagicNumberLo | (MagicNumberHi << 32);
|
|
51
|
+
constexpr uint64_t MagicNumberOffset = 0;
|
|
52
|
+
|
|
53
|
+
constexpr uint32_t ExpectedVersionNumber = 0;
|
|
54
|
+
constexpr uint64_t VersionNumberOffset = 8;
|
|
55
|
+
|
|
56
|
+
constexpr uint32_t ManifestPtrOffset = 0x10;
|
|
57
|
+
|
|
58
|
+
constexpr uint32_t CycleCountOffset = 0x20;
|
|
59
|
+
constexpr uint32_t CoreFreqOffset = 0x28;
|
|
60
|
+
|
|
61
|
+
//===----------------------------------------------------------------------===//
|
|
62
|
+
// Accelerator design hierarchy root.
|
|
63
|
+
//===----------------------------------------------------------------------===//
|
|
64
|
+
|
|
65
|
+
/// Top level accelerator class. Maintains a shared pointer to the manifest,
|
|
66
|
+
/// which owns objects used in the design hierarchy owned by this class. Since
|
|
67
|
+
/// this class owns the entire design hierarchy, when it gets destroyed the
|
|
68
|
+
/// entire design hierarchy gets destroyed so all of the instances, ports, etc.
|
|
69
|
+
/// are no longer valid pointers.
|
|
70
|
+
class Accelerator : public HWModule {
|
|
71
|
+
public:
|
|
72
|
+
Accelerator() = delete;
|
|
73
|
+
Accelerator(const Accelerator &) = delete;
|
|
74
|
+
~Accelerator() = default;
|
|
75
|
+
Accelerator(std::optional<ModuleInfo> info,
|
|
76
|
+
std::vector<std::unique_ptr<Instance>> children,
|
|
77
|
+
std::vector<services::Service *> services,
|
|
78
|
+
std::vector<std::unique_ptr<BundlePort>> &&ports)
|
|
79
|
+
: HWModule(info, std::move(children), services, std::move(ports)) {}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
//===----------------------------------------------------------------------===//
|
|
83
|
+
// Connection to the accelerator and its services.
|
|
84
|
+
//===----------------------------------------------------------------------===//
|
|
85
|
+
|
|
86
|
+
/// Abstract class representing a connection to an accelerator. Actual
|
|
87
|
+
/// connections (e.g. to a co-simulation or actual device) are implemented by
|
|
88
|
+
/// subclasses. No methods in here are thread safe.
|
|
89
|
+
class AcceleratorConnection {
|
|
90
|
+
public:
|
|
91
|
+
AcceleratorConnection(Context &ctxt);
|
|
92
|
+
virtual ~AcceleratorConnection();
|
|
93
|
+
Context &getCtxt() const { return ctxt; }
|
|
94
|
+
Logger &getLogger() const { return ctxt.getLogger(); }
|
|
95
|
+
|
|
96
|
+
/// Disconnect from the accelerator cleanly.
|
|
97
|
+
virtual void disconnect();
|
|
98
|
+
|
|
99
|
+
/// Return a pointer to the accelerator 'service' thread (or threads). If the
|
|
100
|
+
/// thread(s) are not running, they will be started when this method is
|
|
101
|
+
/// called. `std::thread` is used. If users don't want the runtime to spin up
|
|
102
|
+
/// threads, don't call this method. `AcceleratorServiceThread` is owned by
|
|
103
|
+
/// AcceleratorConnection and governed by the lifetime of the this object.
|
|
104
|
+
AcceleratorServiceThread *getServiceThread();
|
|
105
|
+
|
|
106
|
+
using Service = services::Service;
|
|
107
|
+
/// Get a typed reference to a particular service type. Caller does *not* take
|
|
108
|
+
/// ownership of the returned pointer -- the Accelerator object owns it.
|
|
109
|
+
/// Pointer lifetime ends with the Accelerator lifetime.
|
|
110
|
+
template <typename ServiceClass>
|
|
111
|
+
ServiceClass *getService(AppIDPath id = {}, std::string implName = {},
|
|
112
|
+
ServiceImplDetails details = {},
|
|
113
|
+
HWClientDetails clients = {}) {
|
|
114
|
+
return dynamic_cast<ServiceClass *>(
|
|
115
|
+
getService(typeid(ServiceClass), id, implName, details, clients));
|
|
116
|
+
}
|
|
117
|
+
/// Calls `createService` and caches the result. Subclasses can override if
|
|
118
|
+
/// they want to use their own caching mechanism.
|
|
119
|
+
virtual Service *getService(Service::Type service, AppIDPath id = {},
|
|
120
|
+
std::string implName = {},
|
|
121
|
+
ServiceImplDetails details = {},
|
|
122
|
+
HWClientDetails clients = {});
|
|
123
|
+
|
|
124
|
+
/// Assume ownership of an accelerator object. Ties the lifetime of the
|
|
125
|
+
/// accelerator to this connection. Returns a raw pointer to the object.
|
|
126
|
+
Accelerator *takeOwnership(std::unique_ptr<Accelerator> accel);
|
|
127
|
+
|
|
128
|
+
/// Create a new engine for channel communication with the accelerator. The
|
|
129
|
+
/// default is to call the global `createEngine` to get an engine which has
|
|
130
|
+
/// registered itself. Individual accelerator connection backends can override
|
|
131
|
+
/// this to customize behavior.
|
|
132
|
+
virtual void createEngine(const std::string &engineTypeName, AppIDPath idPath,
|
|
133
|
+
const ServiceImplDetails &details,
|
|
134
|
+
const HWClientDetails &clients);
|
|
135
|
+
virtual const BundleEngineMap &getEngineMapFor(AppIDPath id) {
|
|
136
|
+
return clientEngines[id];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
Accelerator &getAccelerator() {
|
|
140
|
+
if (!ownedAccelerator)
|
|
141
|
+
throw std::runtime_error(
|
|
142
|
+
"AcceleratorConnection does not own an accelerator");
|
|
143
|
+
return *ownedAccelerator;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
protected:
|
|
147
|
+
/// If `createEngine` is overridden, this method should be called to register
|
|
148
|
+
/// the engine and all of the channels it services.
|
|
149
|
+
void registerEngine(AppIDPath idPath, std::unique_ptr<Engine> engine,
|
|
150
|
+
const HWClientDetails &clients);
|
|
151
|
+
|
|
152
|
+
/// Called by `getServiceImpl` exclusively. It wraps the pointer returned by
|
|
153
|
+
/// this in a unique_ptr and caches it. Separate this from the
|
|
154
|
+
/// wrapping/caching since wrapping/caching is an implementation detail.
|
|
155
|
+
virtual Service *createService(Service::Type service, AppIDPath idPath,
|
|
156
|
+
std::string implName,
|
|
157
|
+
const ServiceImplDetails &details,
|
|
158
|
+
const HWClientDetails &clients) = 0;
|
|
159
|
+
|
|
160
|
+
/// Collection of owned engines.
|
|
161
|
+
std::map<AppIDPath, std::unique_ptr<Engine>> ownedEngines;
|
|
162
|
+
/// Mapping of clients to their servicing engines.
|
|
163
|
+
std::map<AppIDPath, BundleEngineMap> clientEngines;
|
|
164
|
+
|
|
165
|
+
private:
|
|
166
|
+
/// ESI accelerator context.
|
|
167
|
+
Context &ctxt;
|
|
168
|
+
|
|
169
|
+
/// Cache services via a unique_ptr so they get free'd automatically when
|
|
170
|
+
/// Accelerator objects get deconstructed.
|
|
171
|
+
using ServiceCacheKey = std::tuple<std::string, AppIDPath>;
|
|
172
|
+
std::map<ServiceCacheKey, std::unique_ptr<Service>> serviceCache;
|
|
173
|
+
|
|
174
|
+
std::unique_ptr<AcceleratorServiceThread> serviceThread;
|
|
175
|
+
|
|
176
|
+
/// Accelerator object owned by this connection.
|
|
177
|
+
std::unique_ptr<Accelerator> ownedAccelerator;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
namespace registry {
|
|
181
|
+
|
|
182
|
+
namespace internal {
|
|
183
|
+
|
|
184
|
+
/// Backends can register themselves to be connected via a connection string.
|
|
185
|
+
using BackendCreate = std::function<std::unique_ptr<AcceleratorConnection>(
|
|
186
|
+
Context &, std::string)>;
|
|
187
|
+
void registerBackend(const std::string &name, BackendCreate create);
|
|
188
|
+
|
|
189
|
+
// Helper struct to
|
|
190
|
+
template <typename TAccelerator>
|
|
191
|
+
struct RegisterAccelerator {
|
|
192
|
+
RegisterAccelerator(const char *name) {
|
|
193
|
+
registerBackend(name, &TAccelerator::connect);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
#define REGISTER_ACCELERATOR(Name, TAccelerator) \
|
|
198
|
+
static ::esi::registry::internal::RegisterAccelerator<TAccelerator> \
|
|
199
|
+
__register_accel____LINE__(Name)
|
|
200
|
+
|
|
201
|
+
} // namespace internal
|
|
202
|
+
} // namespace registry
|
|
203
|
+
|
|
204
|
+
/// Background thread which services various requests. Currently, it listens on
|
|
205
|
+
/// ports and calls callbacks for incoming messages on said ports.
|
|
206
|
+
class AcceleratorServiceThread {
|
|
207
|
+
public:
|
|
208
|
+
AcceleratorServiceThread();
|
|
209
|
+
~AcceleratorServiceThread();
|
|
210
|
+
|
|
211
|
+
/// When there's data on any of the listenPorts, call the callback. Callable
|
|
212
|
+
/// from any thread.
|
|
213
|
+
void
|
|
214
|
+
addListener(std::initializer_list<ReadChannelPort *> listenPorts,
|
|
215
|
+
std::function<void(ReadChannelPort *, MessageData)> callback);
|
|
216
|
+
|
|
217
|
+
/// Poll this module.
|
|
218
|
+
void addPoll(HWModule &module);
|
|
219
|
+
|
|
220
|
+
/// Instruct the service thread to stop running.
|
|
221
|
+
void stop();
|
|
222
|
+
|
|
223
|
+
private:
|
|
224
|
+
struct Impl;
|
|
225
|
+
std::unique_ptr<Impl> impl;
|
|
226
|
+
};
|
|
227
|
+
} // namespace esi
|
|
228
|
+
|
|
229
|
+
#endif // ESI_ACCELERATOR_H
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
//===- CLI.h - ESI runtime tool CLI parser common ---------------*- 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
|
+
// This file contains the common CLI parser code for ESI runtime tools. Exposed
|
|
10
|
+
// publicly so that out-of-tree tools can use it. This is a header-only library
|
|
11
|
+
// to make compilation easier for out-of-tree tools.
|
|
12
|
+
//
|
|
13
|
+
// DO NOT EDIT!
|
|
14
|
+
// This file is distributed as part of an ESI package. The source for this file
|
|
15
|
+
// should always be modified within CIRCT (lib/dialect/ESI/runtime/cpp).
|
|
16
|
+
//
|
|
17
|
+
//===----------------------------------------------------------------------===//
|
|
18
|
+
|
|
19
|
+
// NOLINTNEXTLINE(llvm-header-guard)
|
|
20
|
+
#ifndef ESI_CLI_H
|
|
21
|
+
#define ESI_CLI_H
|
|
22
|
+
|
|
23
|
+
#include "CLI/CLI.hpp"
|
|
24
|
+
#include "esi/Context.h"
|
|
25
|
+
|
|
26
|
+
namespace esi {
|
|
27
|
+
|
|
28
|
+
/// Common options and code for ESI runtime tools.
|
|
29
|
+
class CliParser : public CLI::App {
|
|
30
|
+
public:
|
|
31
|
+
CliParser(const std::string &toolName)
|
|
32
|
+
: CLI::App(toolName), debug(false), verbose(false) {
|
|
33
|
+
add_option("backend", backend, "Backend to use for connection")->required();
|
|
34
|
+
add_option("connection", connStr,
|
|
35
|
+
"Connection string to use for accelerator communication")
|
|
36
|
+
->required();
|
|
37
|
+
add_flag("--debug", debug, "Enable debug logging");
|
|
38
|
+
#ifdef ESI_RUNTIME_TRACE
|
|
39
|
+
add_flag("--trace", trace, "Enable trace logging");
|
|
40
|
+
#endif
|
|
41
|
+
add_flag("-v,--verbose", verbose, "Enable verbose (info) logging");
|
|
42
|
+
require_subcommand(0, 1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/// Run the parser.
|
|
46
|
+
int esiParse(int argc, const char **argv) {
|
|
47
|
+
CLI11_PARSE(*this, argc, argv);
|
|
48
|
+
if (trace)
|
|
49
|
+
ctxt = Context::withLogger<ConsoleLogger>(Logger::Level::Trace);
|
|
50
|
+
else if (debug)
|
|
51
|
+
ctxt = Context::withLogger<ConsoleLogger>(Logger::Level::Debug);
|
|
52
|
+
else if (verbose)
|
|
53
|
+
ctxt = Context::withLogger<ConsoleLogger>(Logger::Level::Info);
|
|
54
|
+
else
|
|
55
|
+
ctxt = Context::withLogger<ConsoleLogger>(Logger::Level::Warning);
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/// Connect to the accelerator using the specified backend and connection.
|
|
60
|
+
AcceleratorConnection *connect() { return ctxt->connect(backend, connStr); }
|
|
61
|
+
|
|
62
|
+
/// Get the context.
|
|
63
|
+
Context &getContext() { return *ctxt; }
|
|
64
|
+
|
|
65
|
+
protected:
|
|
66
|
+
std::unique_ptr<Context> ctxt;
|
|
67
|
+
|
|
68
|
+
std::string backend;
|
|
69
|
+
std::string connStr;
|
|
70
|
+
bool trace = false;
|
|
71
|
+
bool debug = false;
|
|
72
|
+
bool verbose = false;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
} // namespace esi
|
|
76
|
+
|
|
77
|
+
#endif // ESI_CLI_H
|