CIRCT 23.0.0git
Loading...
Searching...
No Matches
esiCppAccel.cpp
Go to the documentation of this file.
1//===- esiaccel.cpp - ESI runtime python bindings ---------------*- 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// Simply wrap the C++ API into a Python module called 'esiaccel'.
10//
11//===----------------------------------------------------------------------===//
12
13#include "esi/Accelerator.h"
14#include "esi/Services.h"
15
16#include "esi/backends/Cosim.h"
17
18#include <ranges>
19#include <sstream>
20
21// nanobind includes.
22// Python world does not respect constness. So it doesn't make sense to have
23// const checks. Disable related warnings.
24#if defined(__GNUC__)
25#pragma GCC diagnostic push
26#pragma GCC diagnostic ignored "-Wcast-qual"
27#endif
28#include <nanobind/nanobind.h>
29#include <nanobind/stl/function.h>
30#include <nanobind/stl/map.h>
31#include <nanobind/stl/optional.h>
32#include <nanobind/stl/pair.h>
33#include <nanobind/stl/string.h>
34#include <nanobind/stl/tuple.h>
35#include <nanobind/stl/unique_ptr.h>
36#include <nanobind/stl/vector.h>
37#if defined(__GNUC__)
38#pragma GCC diagnostic pop
39#endif
40
41namespace nb = nanobind;
42
43using namespace esi;
44using namespace esi::services;
45
46namespace nanobind {
47namespace detail {
48
49template <>
50struct type_hook<ChannelPort> {
51 static const std::type_info *get(const ChannelPort *port) {
52 if (dynamic_cast<const WriteChannelPort *>(port))
53 return &typeid(WriteChannelPort);
54 if (dynamic_cast<const ReadChannelPort *>(port))
55 return &typeid(ReadChannelPort);
56 return &typeid(ChannelPort);
57 }
58};
59
60template <>
61struct type_hook<Service> {
62 static const std::type_info *get(const Service *svc) {
63 if (dynamic_cast<const MMIO *>(svc))
64 return &typeid(MMIO);
65 if (dynamic_cast<const SysInfo *>(svc))
66 return &typeid(SysInfo);
67 if (dynamic_cast<const HostMem *>(svc))
68 return &typeid(HostMem);
69 if (dynamic_cast<const TelemetryService *>(svc))
70 return &typeid(TelemetryService);
71 return &typeid(Service);
72 }
73};
74
75/// Nanobind doesn't have a built-in type caster for std::any.
76/// We must provide one which knows about all of the potential types which the
77/// any might be.
78template <>
79struct type_caster<std::any> {
80 NB_TYPE_CASTER(std::any, const_name("object"))
81
82 static handle from_cpp(const std::any &src, rv_policy /* policy */,
83 cleanup_list * /* cleanup */) {
84 const std::type_info &t = src.type();
85 if (t == typeid(std::string))
86 return nb::str(std::any_cast<std::string>(src).c_str()).release();
87 else if (t == typeid(int64_t))
88 return nb::int_(std::any_cast<int64_t>(src)).release();
89 else if (t == typeid(uint64_t))
90 return nb::int_(std::any_cast<uint64_t>(src)).release();
91 else if (t == typeid(double))
92 return nb::float_(std::any_cast<double>(src)).release();
93 else if (t == typeid(bool))
94 return nb::bool_(std::any_cast<bool>(src)).release();
95 else if (t == typeid(std::nullptr_t))
96 return nb::none().release();
97 return nb::none().release();
98 }
99};
100} // namespace detail
101} // namespace nanobind
102
103/// Resolve a Type to the Python wrapper object.
104nb::object getPyType(std::optional<const Type *> t) {
105 nb::object typesModule = nb::module_::import_("esiaccel.types");
106 if (!t)
107 return nb::none();
108 return typesModule.attr("_get_esi_type")(*t);
109}
110
111// NOLINTNEXTLINE(readability-identifier-naming)
112NB_MODULE(esiCppAccel, m) {
113 // TODO: Fix leaks! The one I know of is in the callback code -- if one
114 // registers a python callback it creates a leak.
115 nb::set_leak_warnings(false);
116
117 nb::class_<Type>(m, "Type")
118 .def(nb::init<const Type::ID &>(), nb::arg("id"))
119 .def_prop_ro("id", &Type::getID)
120 .def("__repr__", [](Type &t) { return "<" + t.getID() + ">"; });
121 nb::class_<ChannelType, Type>(m, "ChannelType")
122 .def(nb::init<const Type::ID &, const Type *>(), nb::arg("id"),
123 nb::arg("inner"))
124 .def_prop_ro("inner", &ChannelType::getInner, nb::rv_policy::reference);
125 nb::enum_<BundleType::Direction>(m, "Direction")
126 .value("To", BundleType::Direction::To)
127 .value("From", BundleType::Direction::From)
128 .export_values();
129 nb::class_<BundleType, Type>(m, "BundleType")
130 .def(nb::init<const Type::ID &, const BundleType::ChannelVector &>(),
131 nb::arg("id"), nb::arg("channels"))
132 .def_prop_ro("channels", &BundleType::getChannels,
133 nb::rv_policy::reference);
134 nb::class_<VoidType, Type>(m, "VoidType")
135 .def(nb::init<const Type::ID &>(), nb::arg("id"));
136 nb::class_<AnyType, Type>(m, "AnyType")
137 .def(nb::init<const Type::ID &>(), nb::arg("id"));
138 nb::class_<TypeAliasType, Type>(m, "TypeAliasType")
139 .def(nb::init<const Type::ID &, std::string, const Type *>(),
140 nb::arg("id"), nb::arg("name"), nb::arg("inner_type"))
141 .def_prop_ro("name", &TypeAliasType::getName)
142 .def_prop_ro("inner", &TypeAliasType::getInnerType,
143 nb::rv_policy::reference);
144 nb::class_<BitVectorType, Type>(m, "BitVectorType")
145 .def(nb::init<const Type::ID &, uint64_t>(), nb::arg("id"),
146 nb::arg("width"))
147 .def_prop_ro("width", &BitVectorType::getWidth);
148 nb::class_<BitsType, BitVectorType>(m, "BitsType")
149 .def(nb::init<const Type::ID &, uint64_t>(), nb::arg("id"),
150 nb::arg("width"));
151 nb::class_<IntegerType, BitVectorType>(m, "IntegerType")
152 .def(nb::init<const Type::ID &, uint64_t>(), nb::arg("id"),
153 nb::arg("width"));
154 nb::class_<SIntType, IntegerType>(m, "SIntType")
155 .def(nb::init<const Type::ID &, uint64_t>(), nb::arg("id"),
156 nb::arg("width"));
157 nb::class_<UIntType, IntegerType>(m, "UIntType")
158 .def(nb::init<const Type::ID &, uint64_t>(), nb::arg("id"),
159 nb::arg("width"));
160 nb::class_<StructType, Type>(m, "StructType")
161 .def(nb::init<const Type::ID &, const StructType::FieldVector &, bool>(),
162 nb::arg("id"), nb::arg("fields"), nb::arg("reverse") = true)
163 .def_prop_ro("fields", &StructType::getFields, nb::rv_policy::reference)
164 .def_prop_ro("reverse", &StructType::isReverse);
165 nb::class_<ArrayType, Type>(m, "ArrayType")
166 .def(nb::init<const Type::ID &, const Type *, uint64_t>(), nb::arg("id"),
167 nb::arg("element_type"), nb::arg("size"))
168 .def_prop_ro("element", &ArrayType::getElementType,
169 nb::rv_policy::reference)
170 .def_prop_ro("size", &ArrayType::getSize);
171
172 nb::class_<Constant>(m, "Constant")
173 .def_prop_ro("value", [](Constant &c) { return c.value; })
174 .def_prop_ro("type", [](Constant &c) { return getPyType(*c.type); });
175
176 nb::class_<AppID>(m, "AppID")
177 .def(nb::init<std::string, std::optional<uint32_t>>(), nb::arg("name"),
178 nb::arg("idx") = std::nullopt)
179 .def_prop_ro("name", [](AppID &id) { return id.name; })
180 .def_prop_ro("idx",
181 [](AppID &id) -> nb::object {
182 if (id.idx)
183 return nb::cast(id.idx);
184 return nb::none();
185 })
186 .def("__repr__",
187 [](AppID &id) {
188 std::string ret = "<" + id.name;
189 if (id.idx)
190 ret = ret + "[" + std::to_string(*id.idx) + "]";
191 ret = ret + ">";
192 return ret;
193 })
194 .def("__eq__", [](AppID &a, AppID &b) { return a == b; })
195 .def("__hash__", [](AppID &id) {
196 return utils::hash_combine(std::hash<std::string>{}(id.name),
197 std::hash<uint32_t>{}(id.idx.value_or(-1)));
198 });
199 nb::class_<AppIDPath>(m, "AppIDPath").def("__repr__", &AppIDPath::toStr);
200
201 nb::class_<ModuleInfo>(m, "ModuleInfo")
202 .def_prop_ro("name", [](ModuleInfo &info) { return info.name; })
203 .def_prop_ro("summary", [](ModuleInfo &info) { return info.summary; })
204 .def_prop_ro("version", [](ModuleInfo &info) { return info.version; })
205 .def_prop_ro("repo", [](ModuleInfo &info) { return info.repo; })
206 .def_prop_ro("commit_hash",
207 [](ModuleInfo &info) { return info.commitHash; })
208 .def_prop_ro("constants", [](ModuleInfo &info) { return info.constants; })
209 // TODO: "extra" field.
210 .def("__repr__", [](ModuleInfo &info) {
211 std::string ret;
212 std::stringstream os(ret);
213 os << info;
214 return os.str();
215 });
216
217 nb::enum_<Logger::Level>(m, "LogLevel")
218 .value("Debug", Logger::Level::Debug)
219 .value("Info", Logger::Level::Info)
220 .value("Warning", Logger::Level::Warning)
221 .value("Error", Logger::Level::Error)
222 .export_values();
223 nb::class_<Logger>(m, "Logger");
224
225 nb::class_<services::Service>(m, "Service")
226 .def("get_service_symbol", &services::Service::getServiceSymbol);
227
228 nb::class_<SysInfo, services::Service>(m, "SysInfo")
229 .def("esi_version", &SysInfo::getEsiVersion)
230 .def("json_manifest", &SysInfo::getJsonManifest)
231 .def("cycle_count", &SysInfo::getCycleCount,
232 "Get the current cycle count of the accelerator system")
233 .def("core_clock_frequency", &SysInfo::getCoreClockFrequency,
234 "Get the core clock frequency of the accelerator system in Hz");
235
236 nb::class_<MMIO::RegionDescriptor>(m, "MMIORegionDescriptor")
237 .def_prop_ro("base", [](MMIO::RegionDescriptor &r) { return r.base; })
238 .def_prop_ro("size", [](MMIO::RegionDescriptor &r) { return r.size; });
239 nb::class_<services::MMIO, services::Service>(m, "MMIO")
240 .def("read", &services::MMIO::read)
241 .def("write", &services::MMIO::write)
242 .def_prop_ro("regions", &services::MMIO::getRegions,
243 nb::rv_policy::reference);
244
245 nb::class_<services::HostMem::HostMemRegion>(m, "HostMemRegion")
246 .def_prop_ro("ptr",
248 return reinterpret_cast<uintptr_t>(mem.getPtr());
249 })
250 .def_prop_ro("size", &services::HostMem::HostMemRegion::getSize);
251
252 nb::class_<services::HostMem::Options>(m, "HostMemOptions")
253 .def(nb::init<>())
254 .def_rw("writeable", &services::HostMem::Options::writeable)
255 .def_rw("use_large_pages", &services::HostMem::Options::useLargePages)
256 .def("__repr__", [](services::HostMem::Options &opts) {
257 std::string ret = "HostMemOptions(";
258 if (opts.writeable)
259 ret += "writeable ";
260 if (opts.useLargePages)
261 ret += "use_large_pages";
262 ret += ")";
263 return ret;
264 });
265
266 nb::class_<services::HostMem, services::Service>(m, "HostMem")
267 .def("allocate", &services::HostMem::allocate, nb::arg("size"),
268 nb::arg("options") = services::HostMem::Options(),
269 nb::rv_policy::take_ownership)
270 .def(
271 "map_memory",
272 [](HostMem &self, uintptr_t ptr, size_t size, HostMem::Options opts) {
273 return self.mapMemory(reinterpret_cast<void *>(ptr), size, opts);
274 },
275 nb::arg("ptr"), nb::arg("size"),
276 nb::arg("options") = services::HostMem::Options())
277 .def(
278 "unmap_memory",
279 [](HostMem &self, uintptr_t ptr) {
280 return self.unmapMemory(reinterpret_cast<void *>(ptr));
281 },
282 nb::arg("ptr"));
283 nb::class_<services::TelemetryService, services::Service>(m,
284 "TelemetryService");
285
286 nb::class_<std::future<MessageData>>(m, "MessageDataFuture")
287 .def("valid", [](std::future<MessageData> &f) { return f.valid(); })
288 .def("wait",
289 [](std::future<MessageData> &f) {
290 // Yield the GIL while waiting for the future to complete, in case
291 // of python callbacks occurring from other threads while waiting.
292 nb::gil_scoped_release release{};
293 f.wait();
294 })
295 .def("get", [](std::future<MessageData> &f) {
296 std::optional<MessageData> data;
297 {
298 // Yield the GIL while waiting for the future to complete, in case of
299 // python callbacks occurring from other threads while waiting.
300 nb::gil_scoped_release release{};
301 data.emplace(f.get());
302 }
303 return nb::bytearray((const char *)data->getBytes(), data->getSize());
304 });
305
306 nb::class_<ChannelPort::ConnectOptions>(m, "ConnectOptions")
307 .def(nb::init<>())
308 .def_rw("buffer_size", &ChannelPort::ConnectOptions::bufferSize,
309 nb::arg("buffer_size").none())
310 .def_rw("translate_message",
312
313 nb::class_<ChannelPort>(m, "ChannelPort")
314 .def("connect", &ChannelPort::connect, nb::arg("options"),
315 "Connect with specified options")
316 .def("disconnect", &ChannelPort::disconnect)
317 .def_prop_ro("type", &ChannelPort::getType, nb::rv_policy::reference);
318
319 nb::class_<WriteChannelPort, ChannelPort>(m, "WriteChannelPort")
320 .def("write",
321 [](WriteChannelPort &p, nb::bytearray data) {
322 std::vector<uint8_t> dataVec((const uint8_t *)data.c_str(),
323 (const uint8_t *)data.c_str() +
324 data.size());
325 p.write(dataVec);
326 })
327 .def("tryWrite", [](WriteChannelPort &p, nb::bytearray data) {
328 std::vector<uint8_t> dataVec((const uint8_t *)data.c_str(),
329 (const uint8_t *)data.c_str() +
330 data.size());
331 return p.tryWrite(dataVec);
332 });
333 nb::class_<ReadChannelPort, ChannelPort>(m, "ReadChannelPort")
334 .def(
335 "read",
336 [](ReadChannelPort &p) -> nb::bytearray {
337 MessageData data;
338 p.read(data);
339 return nb::bytearray((const char *)data.getBytes(), data.getSize());
340 },
341 "Read data from the channel. Blocking.")
342 .def("read_async", &ReadChannelPort::readAsync);
343
344 nb::class_<BundlePort>(m, "BundlePort")
345 .def_prop_ro("id", &BundlePort::getID)
346 .def_prop_ro("channels", &BundlePort::getChannels,
347 nb::rv_policy::reference)
348 .def("getWrite", &BundlePort::getRawWrite, nb::rv_policy::reference)
349 .def("getRead", &BundlePort::getRawRead, nb::rv_policy::reference);
350
351 nb::class_<ServicePort, BundlePort>(m, "ServicePort");
352
353 nb::class_<MMIO::MMIORegion, ServicePort>(m, "MMIORegion")
354 .def_prop_ro("descriptor", &MMIO::MMIORegion::getDescriptor)
355 .def("read", &MMIO::MMIORegion::read)
356 .def("write", &MMIO::MMIORegion::write);
357
358 nb::class_<FuncService::Function, ServicePort>(m, "Function")
359 .def("call",
360 [](FuncService::Function &self,
361 nb::bytearray msg) -> std::future<MessageData> {
362 std::vector<uint8_t> dataVec((const uint8_t *)msg.c_str(),
363 (const uint8_t *)msg.c_str() +
364 msg.size());
365 MessageData data(dataVec);
366 return self.call(data);
367 })
368 .def("connect", &FuncService::Function::connect);
369
370 nb::class_<CallService::Callback, ServicePort>(m, "Callback")
371 .def("connect", [](CallService::Callback &self,
372 std::function<nb::object(nb::object)> pyCallback) {
373 // TODO: Under certain conditions this will cause python to crash. I
374 // don't remember how to replicate these crashes, but IIRC they are
375 // deterministic.
376 self.connect([pyCallback](const MessageData &req) -> MessageData {
377 nb::gil_scoped_acquire acquire{};
378 std::vector<uint8_t> arg(req.getBytes(),
379 req.getBytes() + req.getSize());
380 nb::bytes argObj((const char *)arg.data(), arg.size());
381 auto ret = pyCallback(argObj);
382 if (ret.is_none())
383 return MessageData();
384 nb::bytearray retBytes = nb::cast<nb::bytearray>(ret);
385 std::vector<uint8_t> dataVec((const uint8_t *)retBytes.c_str(),
386 (const uint8_t *)retBytes.c_str() +
387 retBytes.size());
388 return MessageData(dataVec);
389 });
390 });
391
392 nb::class_<TelemetryService::Metric, ServicePort>(m, "Metric")
393 .def("connect", &TelemetryService::Metric::connect)
394 .def("read", &TelemetryService::Metric::read)
395 .def("readInt", &TelemetryService::Metric::readInt);
396
397 // Store this variable (not commonly done) as the "children" method needs for
398 // "Instance" to be defined first.
399 auto hwmodule =
400 nb::class_<HWModule>(m, "HWModule")
401 .def_prop_ro("info", &HWModule::getInfo)
402 .def_prop_ro("ports", &HWModule::getPorts, nb::rv_policy::reference)
403 .def_prop_ro("services", &HWModule::getServices,
404 nb::rv_policy::reference);
405
406 // In order to inherit methods from "HWModule", it needs to be defined first.
407 nb::class_<Instance, HWModule>(m, "Instance")
408 .def_prop_ro("id", &Instance::getID);
409
410 nb::class_<Accelerator, HWModule>(m, "Accelerator");
411
412 // Since this returns a vector of Instance*, we need to define Instance first
413 // or else stubgen complains.
414 hwmodule.def_prop_ro("children", &HWModule::getChildren,
415 nb::rv_policy::reference);
416
417 auto accConn = nb::class_<AcceleratorConnection>(m, "AcceleratorConnection");
418
419 nb::class_<Context>(
420 m, "Context",
421 "An ESI context owns everything -- types, accelerator connections, and "
422 "the accelerator facade (aka Accelerator) itself. It MUST NOT be garbage "
423 "collected while the accelerator is still in use. When it is destroyed, "
424 "all accelerator connections are disconnected.")
425 .def(nb::init<>(), "Create a context with a default logger.")
426 .def("connect", &Context::connect, nb::rv_policy::reference)
427 .def("set_stdio_logger", [](Context &ctxt, Logger::Level level) {
428 ctxt.setLogger(std::make_unique<StreamLogger>(level));
429 });
430
431 accConn
432 .def(
433 "sysinfo",
434 [](AcceleratorConnection &acc) {
435 return acc.getService<services::SysInfo>({});
436 },
437 nb::rv_policy::reference)
438 .def(
439 "get_service_mmio",
440 [](AcceleratorConnection &acc) {
441 return acc.getService<services::MMIO>({});
442 },
443 nb::rv_policy::reference)
444 .def(
445 "get_service_hostmem",
446 [](AcceleratorConnection &acc) {
447 return acc.getService<services::HostMem>({});
448 },
449 nb::rv_policy::reference)
450 .def("get_accelerator", &AcceleratorConnection::getAccelerator,
451 nb::rv_policy::reference);
452
453 nb::class_<Manifest>(m, "Manifest")
454 .def(nb::init<Context &, std::string>())
455 .def_prop_ro("api_version", &Manifest::getApiVersion)
456 .def(
457 "build_accelerator",
458 [&](Manifest &m, AcceleratorConnection &conn) -> Accelerator * {
459 auto *acc = m.buildAccelerator(conn);
460 conn.getServiceThread()->addPoll(*acc);
461 return acc;
462 },
463 nb::rv_policy::reference)
464 .def_prop_ro("type_table",
465 [](Manifest &m) {
466 std::vector<nb::object> ret;
467 std::ranges::transform(m.getTypeTable(),
468 std::back_inserter(ret), getPyType);
469 return ret;
470 })
471 .def_prop_ro("module_infos", &Manifest::getModuleInfos);
472}
Abstract class representing a connection to an accelerator.
Definition Accelerator.h:89
ServiceClass * getService(AppIDPath id={}, std::string implName={}, ServiceImplDetails details={}, HWClientDetails clients={})
Get a typed reference to a particular service type.
Accelerator & getAccelerator()
AcceleratorServiceThread * getServiceThread()
Return a pointer to the accelerator 'service' thread (or threads).
Top level accelerator class.
Definition Accelerator.h:70
std::string toStr() const
Definition Manifest.cpp:799
uint64_t getWidth() const
Definition Types.h:190
Unidirectional channels are the basic communication primitive between the host and accelerator.
Definition Ports.h:36
const Type * getType() const
Definition Ports.h:130
virtual void connect(const ConnectOptions &options=ConnectOptions())=0
Set up a connection to the accelerator.
virtual void disconnect()=0
AcceleratorConnections, Accelerators, and Manifests must all share a context.
Definition Context.h:34
void setLogger(std::unique_ptr< Logger > logger)
Register a logger with the accelerator. Assumes ownership of the logger.
Definition Context.h:64
const std::map< AppID, BundlePort & > & getPorts() const
Access the module's ports by ID.
Definition Design.h:80
const std::map< AppID, Instance * > & getChildren() const
Access the module's children by ID.
Definition Design.h:71
const std::vector< services::Service * > & getServices() const
Access the services provided by this module.
Definition Design.h:82
std::optional< ModuleInfo > getInfo() const
Access the module's metadata, if any.
Definition Design.h:62
AppID getID() const
Get the instance's ID, which it will always have.
Definition Design.h:124
Class to parse a manifest.
Definition Manifest.h:39
A logical chunk of data representing serialized data.
Definition Common.h:113
const uint8_t * getBytes() const
Definition Common.h:124
size_t getSize() const
Get the size of the data in bytes.
Definition Common.h:138
A ChannelPort which reads data from the accelerator.
Definition Ports.h:318
virtual std::future< MessageData > readAsync()
Asynchronous read.
Definition Ports.cpp:126
const Type * getInnerType() const
Definition Types.h:170
const std::string & getName() const
Definition Types.h:169
Root class of the ESI type system.
Definition Types.h:36
ID getID() const
Definition Types.h:42
A ChannelPort which sends data to the accelerator.
Definition Ports.h:206
void write(const MessageData &data)
A very basic blocking write API.
Definition Ports.h:222
bool tryWrite(const MessageData &data)
A basic non-blocking write API.
Definition Ports.h:241
A function call which gets attached to a service port.
Definition Services.h:343
A function call which gets attached to a service port.
Definition Services.h:291
virtual std::unique_ptr< HostMemRegion > allocate(std::size_t size, Options opts) const =0
Allocate a region of host memory in accelerator accessible address space.
virtual void unmapMemory(void *ptr) const
Unmap memory which was previously mapped with 'mapMemory'.
Definition Services.h:277
virtual bool mapMemory(void *ptr, std::size_t size, Options opts) const
Try to make a region of host memory accessible to the accelerator.
Definition Services.h:272
virtual uint64_t read(uint32_t addr) const
Read a 64-bit value from this region, not the global address space.
Definition Services.cpp:132
virtual void write(uint32_t addr, uint64_t data)
Write a 64-bit value to this region, not the global address space.
Definition Services.cpp:137
virtual RegionDescriptor getDescriptor() const
Get the offset (and size) of the region in the parent (usually global) MMIO address space.
Definition Services.h:188
virtual uint64_t read(uint32_t addr) const =0
Read a 64-bit value from the global MMIO space.
virtual void write(uint32_t addr, uint64_t data)=0
Write a 64-bit value to the global MMIO space.
const std::map< AppIDPath, RegionDescriptor > & getRegions() const
Get the regions of MMIO space that this service manages.
Definition Services.h:158
Parent class of all APIs modeled as 'services'.
Definition Services.h:59
virtual std::string getServiceSymbol() const =0
Information about the Accelerator system.
Definition Services.h:113
virtual std::optional< uint64_t > getCoreClockFrequency() const
Get the "core" clock frequency of the accelerator system in Hz.
Definition Services.h:127
virtual std::string getJsonManifest() const
Return the JSON-formatted system manifest.
Definition Services.cpp:40
virtual uint32_t getEsiVersion() const =0
Get the ESI version number to check version compatibility.
virtual std::optional< uint64_t > getCycleCount() const
Get the current cycle count of the accelerator system.
Definition Services.h:124
void connect()
Connect to a particular telemetry port. Offset should be non-nullopt.
Definition Services.cpp:389
std::future< MessageData > read()
Definition Services.cpp:396
Service for retrieving telemetry data from the accelerator.
Definition Services.h:390
nb::object getPyType(std::optional< const Type * > t)
Resolve a Type to the Python wrapper object.
NB_MODULE(esiCppAccel, m)
size_t hash_combine(size_t h1, size_t h2)
C++'s stdlib doesn't have a hash_combine function. This is a simple one.
Definition Utils.h:32
Definition esi.py:1
std::optional< unsigned > bufferSize
The buffer size is optional and should be considered merely a hint.
Definition Ports.h:45
bool translateMessage
If the type of this port is a window, translate the incoming/outgoing data into its underlying ('into...
Definition Ports.h:104
std::any value
Definition Common.h:68
std::optional< const Type * > type
Definition Common.h:69
RAII memory region for host memory.
Definition Services.h:237
virtual void * getPtr() const =0
Get a pointer to the host memory.
virtual std::size_t getSize() const =0
Options for allocating host memory.
Definition Services.h:255
Describe a region (slice) of MMIO space.
Definition Services.h:143
static const std::type_info * get(const ChannelPort *port)
static const std::type_info * get(const Service *svc)