CIRCT 22.0.0git
Loading...
Searching...
No Matches
Cosim.cpp
Go to the documentation of this file.
1//===- Cosim.cpp - Connection to ESI simulation via GRPC ------------------===//
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// (lib/dialect/ESI/runtime/cpp/lib/backends/Cosim.cpp).
13//
14//===----------------------------------------------------------------------===//
15
16#include "esi/backends/Cosim.h"
17#include "esi/Engines.h"
18#include "esi/Ports.h"
19#include "esi/Services.h"
20#include "esi/Utils.h"
22
23#include <cstring>
24#include <fstream>
25#include <iostream>
26#include <set>
27
28using namespace esi;
29using namespace esi::services;
30using namespace esi::backends::cosim;
31
32namespace {
33
34//===----------------------------------------------------------------------===//
35// WriteCosimChannelPort
36//===----------------------------------------------------------------------===//
37
38/// Cosim client implementation of a write channel port.
39class WriteCosimChannelPort : public WriteChannelPort {
40public:
41 WriteCosimChannelPort(AcceleratorConnection &conn, RpcClient &client,
42 const RpcClient::ChannelDesc &desc, const Type *type,
43 std::string name)
44 : WriteChannelPort(type), conn(conn), client(client), desc(desc),
45 name(std::move(name)) {}
46 ~WriteCosimChannelPort() = default;
47
48 void connectImpl(const ChannelPort::ConnectOptions &options) override {
49 if (desc.dir != RpcClient::ChannelDirection::ToServer)
50 throw std::runtime_error("Channel '" + name +
51 "' is not a to server channel");
52 }
53
54protected:
55 void writeImpl(const MessageData &data) override {
56 // Add trace logging before sending the message.
57 conn.getLogger().trace(
58 [this,
59 &data](std::string &subsystem, std::string &msg,
60 std::unique_ptr<std::map<std::string, std::any>> &details) {
61 subsystem = "cosim_write";
62 msg = "Writing message to channel '" + name + "'";
63 details = std::make_unique<std::map<std::string, std::any>>();
64 (*details)["channel"] = name;
65 (*details)["data_size"] = data.getSize();
66 (*details)["message_data"] = data.toHex();
67 });
68
69 client.writeToServer(name, data);
70 }
71
72 bool tryWriteImpl(const MessageData &data) override {
73 writeImpl(data);
74 return true;
75 }
76
77private:
79 RpcClient &client;
81 std::string name;
82};
83
84//===----------------------------------------------------------------------===//
85// ReadCosimChannelPort
86//===----------------------------------------------------------------------===//
87
88/// Cosim client implementation of a read channel port. Since gRPC read protocol
89/// streams messages back, this implementation is quite complex.
90class ReadCosimChannelPort : public ReadChannelPort {
91public:
92 ReadCosimChannelPort(AcceleratorConnection &conn, RpcClient &client,
93 const RpcClient::ChannelDesc &desc, const Type *type,
94 std::string name)
95 : ReadChannelPort(type), conn(conn), client(client), desc(desc),
96 name(std::move(name)) {}
97
98 ~ReadCosimChannelPort() = default;
99
100 void connectImpl(const ChannelPort::ConnectOptions &options) override {
101 if (desc.dir != RpcClient::ChannelDirection::ToClient)
102 throw std::runtime_error("Channel '" + name +
103 "' is not a to client channel");
104
105 // Connect to the channel and set up callback.
106 connection =
107 client.connectClientReceiver(name, [this](const MessageData &data) {
108 // Add trace logging for the received message.
109 conn.getLogger().trace(
110 [this, &data](
111 std::string &subsystem, std::string &msg,
112 std::unique_ptr<std::map<std::string, std::any>> &details) {
113 subsystem = "cosim_read";
114 msg = "Received message from channel '" + name + "'";
115 details = std::make_unique<std::map<std::string, std::any>>();
116 (*details)["channel"] = name;
117 (*details)["data_size"] = data.getSize();
118 (*details)["message_data"] = data.toHex();
119 });
120
121 bool consumed = callback(data);
122
123 if (consumed) {
124 // Log the message consumption.
125 conn.getLogger().trace(
126 [this](
127 std::string &subsystem, std::string &msg,
128 std::unique_ptr<std::map<std::string, std::any>> &details) {
129 subsystem = "cosim_read";
130 msg = "Message from channel '" + name + "' consumed";
131 });
132 }
133
134 return consumed;
135 });
136 }
137
138 void disconnect() override {
139 conn.getLogger().debug("cosim_read", "Disconnecting channel " + name);
140 if (connection) {
141 connection->disconnect();
142 connection.reset();
143 }
145 }
146
147private:
149 RpcClient &client;
151 std::string name;
152 std::unique_ptr<RpcClient::ReadChannelConnection> connection;
153};
154
155} // anonymous namespace
156
157//===----------------------------------------------------------------------===//
158// CosimAccelerator
159//===----------------------------------------------------------------------===//
160
161/// Parse the connection std::string and instantiate the accelerator. Support
162/// the traditional 'host:port' syntax and a path to 'cosim.cfg' which is output
163/// by the cosimulation when it starts (which is useful when it chooses its own
164/// port).
165std::unique_ptr<AcceleratorConnection>
166CosimAccelerator::connect(Context &ctxt, std::string connectionString) {
167 std::string portStr;
168 std::string host = "localhost";
169
170 size_t colon;
171 if ((colon = connectionString.find(':')) != std::string::npos) {
172 portStr = connectionString.substr(colon + 1);
173 host = connectionString.substr(0, colon);
174 } else if (connectionString.ends_with("cosim.cfg")) {
175 std::ifstream cfg(connectionString);
176 std::string line, key, value;
177
178 while (getline(cfg, line))
179 if ((colon = line.find(":")) != std::string::npos) {
180 key = line.substr(0, colon);
181 value = line.substr(colon + 1);
182 if (key == "port")
183 portStr = value;
184 else if (key == "host")
185 host = value;
186 }
187
188 if (portStr.size() == 0)
189 throw std::runtime_error("port line not found in file");
190 } else if (connectionString == "env") {
191 char *hostEnv = getenv("ESI_COSIM_HOST");
192 if (hostEnv)
193 host = hostEnv;
194 else
195 host = "localhost";
196 char *portEnv = getenv("ESI_COSIM_PORT");
197 if (portEnv)
198 portStr = portEnv;
199 else
200 throw std::runtime_error("ESI_COSIM_PORT environment variable not set");
201 } else {
202 throw std::runtime_error("Invalid connection std::string '" +
203 connectionString + "'");
204 }
205 uint16_t port = stoul(portStr);
206 auto conn = make_unique<CosimAccelerator>(ctxt, host, port);
207
208 // Using the MMIO manifest method is really only for internal debugging, so it
209 // doesn't need to be part of the connection string.
210 char *manifestMethod = getenv("ESI_COSIM_MANIFEST_MMIO");
211 if (manifestMethod != nullptr)
212 conn->setManifestMethod(ManifestMethod::MMIO);
213
214 return conn;
215}
216
217/// Construct and connect to a cosim server.
218CosimAccelerator::CosimAccelerator(Context &ctxt, std::string hostname,
219 uint16_t port)
220 : AcceleratorConnection(ctxt) {
221 // Connect to the simulation.
222 rpcClient = std::make_unique<RpcClient>(hostname, port);
223}
228
229namespace {
230class CosimSysInfo : public SysInfo {
231public:
232 CosimSysInfo(CosimAccelerator &conn, RpcClient *rpcClient)
233 : SysInfo(conn), rpcClient(rpcClient) {}
234
235 uint32_t getEsiVersion() const override { return rpcClient->getEsiVersion(); }
236
237 std::vector<uint8_t> getCompressedManifest() const override {
238 return rpcClient->getCompressedManifest();
239 }
240
241private:
242 RpcClient *rpcClient;
243};
244} // namespace
245
246namespace {
247class CosimMMIO : public MMIO {
248public:
249 CosimMMIO(CosimAccelerator &conn, Context &ctxt, const AppIDPath &idPath,
250 RpcClient *rpcClient, const HWClientDetails &clients)
251 : MMIO(conn, idPath, clients) {
252 // We have to locate the channels ourselves since this service might be used
253 // to retrieve the manifest.
254 RpcClient::ChannelDesc cmdArg, cmdResp;
255 if (!rpcClient->getChannelDesc("__cosim_mmio_read_write.arg", cmdArg) ||
256 !rpcClient->getChannelDesc("__cosim_mmio_read_write.result", cmdResp))
257 throw std::runtime_error("Could not find MMIO channels");
258
259 const esi::Type *i64Type = getType(ctxt, new UIntType(cmdResp.type, 64));
260 const esi::Type *cmdType = getType(
261 ctxt, new StructType(cmdArg.type, {{"write", new BitsType("i1", 1)},
262 {"offset", new UIntType("ui32", 32)},
263 {"data", new BitsType("i64", 64)}}));
264
265 // Get ports, create the function, then connect to it.
266 cmdArgPort = std::make_unique<WriteCosimChannelPort>(
267 conn, *rpcClient, cmdArg, cmdType, "__cosim_mmio_read_write.arg");
268 cmdRespPort = std::make_unique<ReadCosimChannelPort>(
269 conn, *rpcClient, cmdResp, i64Type, "__cosim_mmio_read_write.result");
270 auto *bundleType = new BundleType(
271 "cosimMMIO", {{"arg", BundleType::Direction::To, cmdType},
272 {"result", BundleType::Direction::From, i64Type}});
273 cmdMMIO.reset(FuncService::Function::get(AppID("__cosim_mmio"), bundleType,
274 *cmdArgPort, *cmdRespPort));
275 cmdMMIO->connect();
276 }
277
278#pragma pack(push, 1)
279 struct MMIOCmd {
280 uint64_t data;
281 uint32_t offset;
282 bool write;
283 };
284#pragma pack(pop)
285
286 // Call the read function and wait for a response.
287 uint64_t read(uint32_t addr) const override {
288 MMIOCmd cmd{.data = 0, .offset = addr, .write = false};
289 auto arg = MessageData::from(cmd);
290 std::future<MessageData> result = cmdMMIO->call(arg);
291 result.wait();
292 uint64_t ret = *result.get().as<uint64_t>();
293 conn.getLogger().trace(
294 [addr, ret](std::string &subsystem, std::string &msg,
295 std::unique_ptr<std::map<std::string, std::any>> &details) {
296 subsystem = "cosim_mmio";
297 msg = "MMIO[0x" + toHex(addr) + "] = 0x" + toHex(ret);
298 });
299 return ret;
300 }
301
302 void write(uint32_t addr, uint64_t data) override {
303 conn.getLogger().trace(
304 [addr,
305 data](std::string &subsystem, std::string &msg,
306 std::unique_ptr<std::map<std::string, std::any>> &details) {
307 subsystem = "cosim_mmio";
308 msg = "MMIO[0x" + toHex(addr) + "] <- 0x" + toHex(data);
309 });
310 MMIOCmd cmd{.data = data, .offset = addr, .write = true};
311 auto arg = MessageData::from(cmd);
312 std::future<MessageData> result = cmdMMIO->call(arg);
313 result.wait();
314 }
315
316private:
317 const esi::Type *getType(Context &ctxt, esi::Type *type) {
318 if (auto t = ctxt.getType(type->getID())) {
319 delete type;
320 return *t;
321 }
322 ctxt.registerType(type);
323 return type;
324 }
325 std::unique_ptr<WriteCosimChannelPort> cmdArgPort;
326 std::unique_ptr<ReadCosimChannelPort> cmdRespPort;
327 std::unique_ptr<FuncService::Function> cmdMMIO;
328};
329
330#pragma pack(push, 1)
331struct HostMemReadReq {
332 uint8_t tag;
333 uint32_t length;
334 uint64_t address;
335};
336
337struct HostMemReadResp {
338 uint64_t data;
339 uint8_t tag;
340};
341
342struct HostMemWriteReq {
343 uint8_t valid_bytes;
344 uint64_t data;
345 uint8_t tag;
346 uint64_t address;
347};
348
349using HostMemWriteResp = uint8_t;
350#pragma pack(pop)
351
352class CosimHostMem : public HostMem {
353public:
354 CosimHostMem(AcceleratorConnection &acc, Context &ctxt, RpcClient *rpcClient)
355 : HostMem(acc), acc(acc), ctxt(ctxt), rpcClient(rpcClient) {}
356
357 void start() override {
358 // We have to locate the channels ourselves since this service might be used
359 // to retrieve the manifest.
360
361 if (writeRespPort)
362 return;
363
364 // TODO: The types here are WRONG. They need to be wrapped in Channels! Fix
365 // this in a subsequent PR.
366
367 // Setup the read side callback.
368 RpcClient::ChannelDesc readArg, readResp;
369 if (!rpcClient->getChannelDesc("__cosim_hostmem_read_req.data", readArg) ||
370 !rpcClient->getChannelDesc("__cosim_hostmem_read_resp.data", readResp))
371 throw std::runtime_error("Could not find HostMem read channels");
372
373 const esi::Type *readRespType =
374 getType(ctxt, new StructType(readResp.type,
375 {{"tag", new UIntType("ui8", 8)},
376 {"data", new BitsType("i64", 64)}}));
377 const esi::Type *readReqType =
378 getType(ctxt, new StructType(readArg.type,
379 {{"address", new UIntType("ui64", 64)},
380 {"length", new UIntType("ui32", 32)},
381 {"tag", new UIntType("ui8", 8)}}));
382
383 // Get ports. Unfortunately, we can't model this as a callback since there
384 // will sometimes be multiple responses per request.
385 readRespPort = std::make_unique<WriteCosimChannelPort>(
386 conn, *rpcClient, readResp, readRespType,
387 "__cosim_hostmem_read_resp.data");
388 readReqPort = std::make_unique<ReadCosimChannelPort>(
389 conn, *rpcClient, readArg, readReqType,
390 "__cosim_hostmem_read_req.data");
391 readReqPort->connect(
392 [this](const MessageData &req) { return serviceRead(req); });
393
394 // Setup the write side callback.
395 RpcClient::ChannelDesc writeArg, writeResp;
396 if (!rpcClient->getChannelDesc("__cosim_hostmem_write.arg", writeArg) ||
397 !rpcClient->getChannelDesc("__cosim_hostmem_write.result", writeResp))
398 throw std::runtime_error("Could not find HostMem write channels");
399
400 const esi::Type *writeRespType =
401 getType(ctxt, new UIntType(writeResp.type, 8));
402 const esi::Type *writeReqType =
403 getType(ctxt, new StructType(writeArg.type,
404 {{"address", new UIntType("ui64", 64)},
405 {"tag", new UIntType("ui8", 8)},
406 {"data", new BitsType("i64", 64)}}));
407
408 // Get ports, create the function, then connect to it.
409 writeRespPort = std::make_unique<WriteCosimChannelPort>(
410 conn, *rpcClient, writeResp, writeRespType,
411 "__cosim_hostmem_write.result");
412 writeReqPort = std::make_unique<ReadCosimChannelPort>(
413 conn, *rpcClient, writeArg, writeReqType, "__cosim_hostmem_write.arg");
414 auto *bundleType = new BundleType(
415 "cosimHostMem",
416 {{"arg", BundleType::Direction::To, writeReqType},
417 {"result", BundleType::Direction::From, writeRespType}});
418 write.reset(CallService::Callback::get(acc, AppID("__cosim_hostmem_write"),
419 bundleType, *writeRespPort,
420 *writeReqPort));
421 write->connect([this](const MessageData &req) { return serviceWrite(req); },
422 true);
423 }
424
425 // Service the read request as a callback. Simply reads the data from the
426 // location specified. TODO: check that the memory has been mapped.
427 bool serviceRead(const MessageData &reqBytes) {
428 const HostMemReadReq *req = reqBytes.as<HostMemReadReq>();
429 acc.getLogger().trace(
430 [&](std::string &subsystem, std::string &msg,
431 std::unique_ptr<std::map<std::string, std::any>> &details) {
432 subsystem = "hostmem";
433 msg = "Read request: addr=0x" + toHex(req->address) +
434 " len=" + std::to_string(req->length) +
435 " tag=" + std::to_string(req->tag);
436 });
437 // Send one response per 8 bytes.
438 uint64_t *dataPtr = reinterpret_cast<uint64_t *>(req->address);
439 for (uint32_t i = 0, e = (req->length + 7) / 8; i < e; ++i) {
440 HostMemReadResp resp{.data = dataPtr[i], .tag = req->tag};
441 acc.getLogger().trace(
442 [&](std::string &subsystem, std::string &msg,
443 std::unique_ptr<std::map<std::string, std::any>> &details) {
444 subsystem = "HostMem";
445 msg = "Read result: data=0x" + toHex(resp.data) +
446 " tag=" + std::to_string(resp.tag);
447 });
448 readRespPort->write(MessageData::from(resp));
449 }
450 return true;
451 }
452
453 // Service a write request as a callback. Simply write the data to the
454 // location specified. TODO: check that the memory has been mapped.
455 MessageData serviceWrite(const MessageData &reqBytes) {
456 const HostMemWriteReq *req = reqBytes.as<HostMemWriteReq>();
457 acc.getLogger().trace(
458 [&](std::string &subsystem, std::string &msg,
459 std::unique_ptr<std::map<std::string, std::any>> &details) {
460 subsystem = "hostmem";
461 msg = "Write request: addr=0x" + toHex(req->address) + " data=0x" +
462 toHex(req->data) +
463 " valid_bytes=" + std::to_string(req->valid_bytes) +
464 " tag=" + std::to_string(req->tag);
465 });
466 uint8_t *dataPtr = reinterpret_cast<uint8_t *>(req->address);
467 for (uint8_t i = 0; i < req->valid_bytes; ++i)
468 dataPtr[i] = (req->data >> (i * 8)) & 0xFF;
469 HostMemWriteResp resp = req->tag;
470 return MessageData::from(resp);
471 }
472
473 struct CosimHostMemRegion : public HostMemRegion {
474 CosimHostMemRegion(std::size_t size) {
475 ptr = malloc(size);
476 memset(ptr, 0xFF, size);
477 this->size = size;
478 }
479 virtual ~CosimHostMemRegion() { free(ptr); }
480 virtual void *getPtr() const override { return ptr; }
481 virtual std::size_t getSize() const override { return size; }
482
483 private:
484 void *ptr;
485 std::size_t size;
486 };
487
488 virtual std::unique_ptr<HostMemRegion>
489 allocate(std::size_t size, HostMem::Options opts) const override {
490 auto ret = std::unique_ptr<HostMemRegion>(new CosimHostMemRegion(size));
491 acc.getLogger().debug(
492 [&](std::string &subsystem, std::string &msg,
493 std::unique_ptr<std::map<std::string, std::any>> &details) {
494 subsystem = "HostMem";
495 msg = "Allocated host memory region at 0x" + toHex(ret->getPtr()) +
496 " of size " + std::to_string(size);
497 });
498 return ret;
499 }
500 virtual bool mapMemory(void *ptr, std::size_t size,
501 HostMem::Options opts) const override {
502 return true;
503 }
504 virtual void unmapMemory(void *ptr) const override {}
505
506private:
507 const esi::Type *getType(Context &ctxt, esi::Type *type) {
508 if (auto t = ctxt.getType(type->getID())) {
509 delete type;
510 return *t;
511 }
512 ctxt.registerType(type);
513 return type;
514 }
516 Context &ctxt;
517 RpcClient *rpcClient;
518 std::unique_ptr<WriteCosimChannelPort> readRespPort;
519 std::unique_ptr<ReadCosimChannelPort> readReqPort;
520 std::unique_ptr<CallService::Callback> read;
521 std::unique_ptr<WriteCosimChannelPort> writeRespPort;
522 std::unique_ptr<ReadCosimChannelPort> writeReqPort;
523 std::unique_ptr<CallService::Callback> write;
524};
525} // namespace
526
527namespace esi::backends::cosim {
528/// Implement the magic cosim channel communication.
529class CosimEngine : public Engine {
530public:
532 const ServiceImplDetails &details, const HWClientDetails &clients)
533 : Engine(conn), conn(conn) {
534 // Compute our parents idPath path.
535 AppIDPath prefix = std::move(idPath);
536 if (prefix.size() > 0)
537 prefix.pop_back();
538
539 for (auto client : clients) {
540 AppIDPath fullClientPath = prefix + client.relPath;
541 std::map<std::string, std::string> channelAssignments;
542 for (auto assignment : client.channelAssignments)
543 if (assignment.second.type == "cosim")
544 channelAssignments[assignment.first] = std::any_cast<std::string>(
545 assignment.second.implOptions.at("name"));
546 clientChannelAssignments[fullClientPath] = std::move(channelAssignments);
547 }
548 }
549
550 std::unique_ptr<ChannelPort> createPort(AppIDPath idPath,
551 const std::string &channelName,
553 const Type *type) override;
554
555private:
557 std::map<AppIDPath, std::map<std::string, std::string>>
559};
560} // namespace esi::backends::cosim
561
562std::unique_ptr<ChannelPort>
563CosimEngine::createPort(AppIDPath idPath, const std::string &channelName,
564 BundleType::Direction dir, const Type *type) {
565
566 // Find the client details for the port at 'fullPath'.
567 auto f = clientChannelAssignments.find(idPath);
568 if (f == clientChannelAssignments.end())
569 throw std::runtime_error("Could not find port for '" + idPath.toStr() +
570 "." + channelName + "'");
571 const std::map<std::string, std::string> &channelAssignments = f->second;
572 auto cosimChannelNameIter = channelAssignments.find(channelName);
573 if (cosimChannelNameIter == channelAssignments.end())
574 throw std::runtime_error("Could not find channel '" + idPath.toStr() + "." +
575 channelName + "' in cosimulation");
576
577 // Get the endpoint, which may or may not exist. Construct the port.
578 // Everything is validated when the client calls 'connect()' on the port.
580 if (!conn.rpcClient->getChannelDesc(cosimChannelNameIter->second, chDesc))
581 throw std::runtime_error("Could not find channel '" + idPath.toStr() + "." +
582 channelName + "' in cosimulation");
583
584 std::unique_ptr<ChannelPort> port;
585 std::string fullChannelName = idPath.toStr() + "." + channelName;
586 if (BundlePort::isWrite(dir))
587 port = std::make_unique<WriteCosimChannelPort>(
588 conn, *conn.rpcClient, chDesc, type, fullChannelName);
589 else
590 port = std::make_unique<ReadCosimChannelPort>(conn, *conn.rpcClient, chDesc,
591 type, fullChannelName);
592 return port;
593}
594
595void CosimAccelerator::createEngine(const std::string &engineTypeName,
596 AppIDPath idPath,
597 const ServiceImplDetails &details,
598 const HWClientDetails &clients) {
599
600 std::unique_ptr<Engine> engine = nullptr;
601 if (engineTypeName == "cosim")
602 engine = std::make_unique<CosimEngine>(*this, idPath, details, clients);
603 else
604 engine = ::esi::registry::createEngine(*this, engineTypeName, idPath,
605 details, clients);
606 registerEngine(idPath, std::move(engine), clients);
607}
609 AppIDPath idPath, std::string implName,
610 const ServiceImplDetails &details,
611 const HWClientDetails &clients) {
612 if (svcType == typeid(services::MMIO)) {
613 return new CosimMMIO(*this, getCtxt(), idPath, rpcClient.get(), clients);
614 } else if (svcType == typeid(services::HostMem)) {
615 return new CosimHostMem(*this, getCtxt(), rpcClient.get());
616 } else if (svcType == typeid(SysInfo)) {
617 switch (manifestMethod) {
619 return new CosimSysInfo(*this, rpcClient.get());
621 return new MMIOSysInfo(getService<services::MMIO>());
622 }
623 }
624 return nullptr;
625}
626
630
#define REGISTER_ACCELERATOR(Name, TAccelerator)
Abstract class representing a connection to an accelerator.
Definition Accelerator.h:79
Context & getCtxt() const
Definition Accelerator.h:83
Context & ctxt
ESI accelerator context.
void registerEngine(AppIDPath idPath, std::unique_ptr< Engine > engine, const HWClientDetails &clients)
If createEngine is overridden, this method should be called to register the engine and all of the cha...
virtual void disconnect()
Disconnect from the accelerator cleanly.
Logger & getLogger() const
Definition Accelerator.h:84
std::string toStr() const
Definition Manifest.cpp:781
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:437
Bundles represent a collection of channels.
Definition Types.h:97
virtual void connectImpl(const ConnectOptions &options)
Called by all connect methods to let backends initiate the underlying connections.
Definition Ports.h:202
AcceleratorConnections, Accelerators, and Manifests must all share a context.
Definition Context.h:34
std::optional< const Type * > getType(Type::ID id) const
Resolve a type id to the type.
Definition Context.h:50
void registerType(Type *type)
Register a type with the context. Takes ownership of the pointer type.
Definition Context.cpp:33
Engines implement the actual channel communication between the host and the accelerator.
Definition Engines.h:42
void trace(const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details=nullptr)
Log a trace message.
Definition Logging.h:106
A logical chunk of data representing serialized data.
Definition Common.h:113
const T * as() const
Cast to a type.
Definition Common.h:148
static MessageData from(T &t)
Cast from a type to its raw bytes.
Definition Common.h:158
A ChannelPort which reads data from the accelerator.
Definition Ports.h:318
std::function< bool(MessageData)> callback
Backends call this callback when new data is available.
Definition Ports.h:378
virtual void disconnect() override
Definition Ports.h:323
Structs are an ordered collection of fields, each with a name and a type.
Definition Types.h:210
Root class of the ESI type system.
Definition Types.h:34
ID getID() const
Definition Types.h:40
Unsigned integer.
Definition Types.h:199
A ChannelPort which sends data to the accelerator.
Definition Ports.h:206
virtual bool tryWriteImpl(const MessageData &data)=0
Implementation for tryWrite(). Subclasses must implement this.
virtual void writeImpl(const MessageData &)=0
Implementation for write(). Subclasses must implement this.
Connect to an ESI simulation.
Definition Cosim.h:36
void createEngine(const std::string &engineTypeName, AppIDPath idPath, const ServiceImplDetails &details, const HWClientDetails &clients) override
Create a new engine for channel communication with the accelerator.
Definition Cosim.cpp:595
std::unique_ptr< RpcClient > rpcClient
Definition Cosim.h:65
void setManifestMethod(ManifestMethod method)
Definition Cosim.cpp:627
static std::unique_ptr< AcceleratorConnection > connect(Context &, std::string connectionString)
Parse the connection std::string and instantiate the accelerator.
Definition Cosim.cpp:166
virtual Service * createService(Service::Type service, AppIDPath path, std::string implName, const ServiceImplDetails &details, const HWClientDetails &clients) override
Called by getServiceImpl exclusively.
Definition Cosim.cpp:608
CosimAccelerator(Context &, std::string hostname, uint16_t port)
Construct and connect to a cosim server.
Definition Cosim.cpp:218
std::set< std::unique_ptr< ChannelPort > > channels
Definition Cosim.h:69
Implement the magic cosim channel communication.
Definition Cosim.cpp:529
CosimEngine(CosimAccelerator &conn, AppIDPath idPath, const ServiceImplDetails &details, const HWClientDetails &clients)
Definition Cosim.cpp:531
std::map< AppIDPath, std::map< std::string, std::string > > clientChannelAssignments
Definition Cosim.cpp:558
std::unique_ptr< ChannelPort > createPort(AppIDPath idPath, const std::string &channelName, BundleType::Direction dir, const Type *type) override
Each engine needs to know how to create a ports.
Definition Cosim.cpp:563
A gRPC client for communicating with the cosimulation server.
Definition RpcClient.h:36
uint32_t getEsiVersion() const
Get the ESI version from the manifest.
bool getChannelDesc(const std::string &channelName, ChannelDesc &desc) const
Get the channel description for a channel name.
static Callback * get(AcceleratorConnection &acc, AppID id, const BundleType *type, WriteChannelPort &result, ReadChannelPort &arg)
Definition Services.cpp:255
static Function * get(AppID id, BundleType *type, WriteChannelPort &arg, ReadChannelPort &result)
Definition Services.cpp:207
Implement the SysInfo API for a standard MMIO protocol.
Definition Services.h:199
Parent class of all APIs modeled as 'services'.
Definition Services.h:59
const std::type_info & Type
Definition Services.h:61
Information about the Accelerator system.
Definition Services.h:113
std::unique_ptr< Engine > createEngine(AcceleratorConnection &conn, const std::string &dmaEngineName, AppIDPath idPath, const ServiceImplDetails &details, const HWClientDetails &clients)
Create an engine by name.
Definition Engines.cpp:509
Definition esi.py:1
std::map< std::string, std::any > ServiceImplDetails
Definition Common.h:108
std::string toHex(void *val)
Definition Common.cpp:37
std::vector< HWClientDetail > HWClientDetails
Definition Common.h:107
Description of a channel from the server.
Definition RpcClient.h:55
Options for allocating host memory.
Definition Services.h:241