CIRCT  19.0.0git
Cosim.h
Go to the documentation of this file.
1 //===- Cosim.h - ESI C++ cosimulation backend -------------------*- 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 is a specialization of the ESI C++ API (backend) for connection into a
10 // simulation of an ESI system. Currently uses Cap'nProto RPC, but that could
11 // change. Requires Cap'nProto C++ library.
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_BACKENDS_COSIM_H
21 #define ESI_BACKENDS_COSIM_H
22 
23 #include "esi/Accelerator.h"
24 
25 #include <memory>
26 #include <set>
27 
28 // Only expose this backend class directly if the cosimulation backend is
29 // enabled.
30 #ifdef ESI_COSIM
31 
32 namespace esi {
33 namespace cosim {
34 class RpcClient;
35 } // namespace cosim
36 
37 namespace backends {
38 namespace cosim {
39 
40 /// Connect to an ESI simulation.
41 class CosimAccelerator : public esi::AcceleratorConnection {
42 public:
43  CosimAccelerator(Context &, std::string hostname, uint16_t port);
44  static std::unique_ptr<AcceleratorConnection>
45  connect(Context &, std::string connectionString);
46 
47  // Different ways to retrieve the manifest in Cosimulation.
48  enum ManifestMethod {
49  Cosim, // Use the backdoor cosim interface. Default.
50  MMIO, // Use MMIO emulation.
51  };
52  // Set the way this connection will retrieve the manifest.
53  void setManifestMethod(ManifestMethod method);
54 
55  /// Request the host side channel ports for a particular instance (identified
56  /// by the AppID path). For convenience, provide the bundle type and direction
57  /// of the bundle port.
58  virtual std::map<std::string, ChannelPort &>
59  requestChannelsFor(AppIDPath, const BundleType *) override;
60 
61 protected:
62  virtual Service *createService(Service::Type service, AppIDPath path,
63  std::string implName,
64  const ServiceImplDetails &details,
65  const HWClientDetails &clients) override;
66 
67 private:
68  std::unique_ptr<esi::cosim::RpcClient> rpcClient;
69 
70  // We own all channels connected to rpcClient since their lifetime is tied to
71  // rpcClient.
72  std::set<std::unique_ptr<ChannelPort>> channels;
73  // Map from client path to channel assignments for that client.
74  std::map<AppIDPath, std::map<std::string, std::string>>
75  clientChannelAssignments;
76 
77  ManifestMethod manifestMethod = Cosim;
78 };
79 
80 } // namespace cosim
81 } // namespace backends
82 } // namespace esi
83 
84 #endif // ESI_COSIM
85 
86 #endif // ESI_BACKENDS_COSIM_H
Abstract class representing a connection to an accelerator.
Definition: Accelerator.h:75
def connect(destination, source)
Definition: support.py:37
Definition: esi.py:1
std::map< std::string, std::any > ServiceImplDetails
Definition: Common.h:80
std::vector< HWClientDetail > HWClientDetails
Definition: Common.h:79