esiaccel 0.1.0__cp313-cp313-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.

Files changed (41) hide show
  1. esiaccel/__init__.py +13 -0
  2. esiaccel/accelerator.py +95 -0
  3. esiaccel/bin/esi-cosim.py +405 -0
  4. esiaccel/bin/esiquery +0 -0
  5. esiaccel/cmake/esiaccelConfig.cmake +15 -0
  6. esiaccel/codegen.py +197 -0
  7. esiaccel/cosim/Cosim_DpiPkg.sv +85 -0
  8. esiaccel/cosim/Cosim_Endpoint.sv +189 -0
  9. esiaccel/cosim/Cosim_Manifest.sv +32 -0
  10. esiaccel/cosim/driver.cpp +131 -0
  11. esiaccel/cosim/driver.sv +60 -0
  12. esiaccel/esiCppAccel.cpython-313-x86_64-linux-gnu.so +0 -0
  13. esiaccel/include/esi/Accelerator.h +232 -0
  14. esiaccel/include/esi/CLI.h +77 -0
  15. esiaccel/include/esi/Common.h +154 -0
  16. esiaccel/include/esi/Context.h +74 -0
  17. esiaccel/include/esi/Design.h +127 -0
  18. esiaccel/include/esi/Engines.h +124 -0
  19. esiaccel/include/esi/Logging.h +231 -0
  20. esiaccel/include/esi/Manifest.h +72 -0
  21. esiaccel/include/esi/Ports.h +275 -0
  22. esiaccel/include/esi/Services.h +404 -0
  23. esiaccel/include/esi/Types.h +182 -0
  24. esiaccel/include/esi/Utils.h +102 -0
  25. esiaccel/include/esi/backends/Cosim.h +85 -0
  26. esiaccel/include/esi/backends/RpcServer.h +55 -0
  27. esiaccel/include/esi/backends/Trace.h +87 -0
  28. esiaccel/lib/libCosimBackend.so +0 -0
  29. esiaccel/lib/libESICppRuntime.so +0 -0
  30. esiaccel/lib/libEsiCosimDpiServer.so +0 -0
  31. esiaccel/lib/libMtiPli.so +0 -0
  32. esiaccel/lib/libz.so.1 +0 -0
  33. esiaccel/lib/libz.so.1.2.13 +0 -0
  34. esiaccel/types.py +512 -0
  35. esiaccel/utils.py +36 -0
  36. esiaccel-0.1.0.dist-info/METADATA +254 -0
  37. esiaccel-0.1.0.dist-info/RECORD +41 -0
  38. esiaccel-0.1.0.dist-info/WHEEL +6 -0
  39. esiaccel-0.1.0.dist-info/entry_points.txt +4 -0
  40. esiaccel-0.1.0.dist-info/licenses/LICENSE +234 -0
  41. esiaccel-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,232 @@
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
+ // Constants used by low-level APIs.
43
+ //===----------------------------------------------------------------------===//
44
+
45
+ constexpr uint32_t MetadataOffset = 8;
46
+ constexpr uint64_t MagicNumberLo = 0xE5100E51;
47
+ constexpr uint64_t MagicNumberHi = 0x207D98E5;
48
+ constexpr uint64_t MagicNumber = MagicNumberLo | (MagicNumberHi << 32);
49
+ constexpr uint32_t ExpectedVersionNumber = 0;
50
+
51
+ //===----------------------------------------------------------------------===//
52
+ // Accelerator design hierarchy root.
53
+ //===----------------------------------------------------------------------===//
54
+
55
+ /// Top level accelerator class. Maintains a shared pointer to the manifest,
56
+ /// which owns objects used in the design hierarchy owned by this class. Since
57
+ /// this class owns the entire design hierarchy, when it gets destroyed the
58
+ /// entire design hierarchy gets destroyed so all of the instances, ports, etc.
59
+ /// are no longer valid pointers.
60
+ class Accelerator : public HWModule {
61
+ public:
62
+ Accelerator() = delete;
63
+ Accelerator(const Accelerator &) = delete;
64
+ ~Accelerator() = default;
65
+ Accelerator(std::optional<ModuleInfo> info,
66
+ std::vector<std::unique_ptr<Instance>> children,
67
+ std::vector<services::Service *> services,
68
+ std::vector<std::unique_ptr<BundlePort>> &ports)
69
+ : HWModule(info, std::move(children), services, ports) {}
70
+ };
71
+
72
+ //===----------------------------------------------------------------------===//
73
+ // Connection to the accelerator and its services.
74
+ //===----------------------------------------------------------------------===//
75
+
76
+ /// Abstract class representing a connection to an accelerator. Actual
77
+ /// connections (e.g. to a co-simulation or actual device) are implemented by
78
+ /// subclasses. No methods in here are thread safe.
79
+ class AcceleratorConnection {
80
+ public:
81
+ AcceleratorConnection(Context &ctxt);
82
+ virtual ~AcceleratorConnection();
83
+ Context &getCtxt() const { return ctxt; }
84
+ Logger &getLogger() const { return ctxt.getLogger(); }
85
+
86
+ /// Disconnect from the accelerator cleanly.
87
+ virtual void disconnect();
88
+
89
+ // While building the design, keep around a std::map of active services
90
+ // indexed by the service name. When a new service is encountered during
91
+ // descent, add it to the table (perhaps overwriting one). Modifications to
92
+ // the table only apply to the current branch, so copy this and update it at
93
+ // each level of the tree.
94
+ using ServiceTable = std::map<std::string, services::Service *>;
95
+
96
+ /// Return a pointer to the accelerator 'service' thread (or threads). If the
97
+ /// thread(s) are not running, they will be started when this method is
98
+ /// called. `std::thread` is used. If users don't want the runtime to spin up
99
+ /// threads, don't call this method. `AcceleratorServiceThread` is owned by
100
+ /// AcceleratorConnection and governed by the lifetime of the this object.
101
+ AcceleratorServiceThread *getServiceThread();
102
+
103
+ using Service = services::Service;
104
+ /// Get a typed reference to a particular service type. Caller does *not* take
105
+ /// ownership of the returned pointer -- the Accelerator object owns it.
106
+ /// Pointer lifetime ends with the Accelerator lifetime.
107
+ template <typename ServiceClass>
108
+ ServiceClass *getService(AppIDPath id = {}, std::string implName = {},
109
+ ServiceImplDetails details = {},
110
+ HWClientDetails clients = {}) {
111
+ return dynamic_cast<ServiceClass *>(
112
+ getService(typeid(ServiceClass), id, implName, details, clients));
113
+ }
114
+ /// Calls `createService` and caches the result. Subclasses can override if
115
+ /// they want to use their own caching mechanism.
116
+ virtual Service *getService(Service::Type service, AppIDPath id = {},
117
+ std::string implName = {},
118
+ ServiceImplDetails details = {},
119
+ HWClientDetails clients = {});
120
+
121
+ /// Assume ownership of an accelerator object. Ties the lifetime of the
122
+ /// accelerator to this connection. Returns a raw pointer to the object.
123
+ Accelerator *takeOwnership(std::unique_ptr<Accelerator> accel);
124
+
125
+ /// Create a new engine for channel communication with the accelerator. The
126
+ /// default is to call the global `createEngine` to get an engine which has
127
+ /// registered itself. Individual accelerator connection backends can override
128
+ /// this to customize behavior.
129
+ virtual void createEngine(const std::string &engineTypeName, AppIDPath idPath,
130
+ const ServiceImplDetails &details,
131
+ const HWClientDetails &clients);
132
+ virtual const BundleEngineMap &getEngineMapFor(AppIDPath id) {
133
+ return clientEngines[id];
134
+ }
135
+
136
+ Accelerator &getAccelerator() {
137
+ if (!ownedAccelerator)
138
+ throw std::runtime_error(
139
+ "AcceleratorConnection does not own an accelerator");
140
+ return *ownedAccelerator;
141
+ }
142
+
143
+ protected:
144
+ /// If `createEngine` is overridden, this method should be called to register
145
+ /// the engine and all of the channels it services.
146
+ void registerEngine(AppIDPath idPath, std::unique_ptr<Engine> engine,
147
+ const HWClientDetails &clients);
148
+
149
+ /// Called by `getServiceImpl` exclusively. It wraps the pointer returned by
150
+ /// this in a unique_ptr and caches it. Separate this from the
151
+ /// wrapping/caching since wrapping/caching is an implementation detail.
152
+ virtual Service *createService(Service::Type service, AppIDPath idPath,
153
+ std::string implName,
154
+ const ServiceImplDetails &details,
155
+ const HWClientDetails &clients) = 0;
156
+
157
+ /// Collection of owned engines.
158
+ std::map<AppIDPath, std::unique_ptr<Engine>> ownedEngines;
159
+ /// Mapping of clients to their servicing engines.
160
+ std::map<AppIDPath, BundleEngineMap> clientEngines;
161
+
162
+ private:
163
+ /// ESI accelerator context.
164
+ Context &ctxt;
165
+
166
+ /// Cache services via a unique_ptr so they get free'd automatically when
167
+ /// Accelerator objects get deconstructed.
168
+ using ServiceCacheKey = std::tuple<const std::type_info *, AppIDPath>;
169
+ std::map<ServiceCacheKey, std::unique_ptr<Service>> serviceCache;
170
+
171
+ std::unique_ptr<AcceleratorServiceThread> serviceThread;
172
+
173
+ /// Accelerator object owned by this connection.
174
+ std::unique_ptr<Accelerator> ownedAccelerator;
175
+ };
176
+
177
+ namespace registry {
178
+
179
+ // Connect to an ESI accelerator given a backend name and connection specifier.
180
+ // Alternatively, instantiate the backend directly (if you're using C++).
181
+ std::unique_ptr<AcceleratorConnection> connect(Context &ctxt,
182
+ const std::string &backend,
183
+ const std::string &connection);
184
+
185
+ namespace internal {
186
+
187
+ /// Backends can register themselves to be connected via a connection string.
188
+ using BackendCreate = std::function<std::unique_ptr<AcceleratorConnection>(
189
+ Context &, std::string)>;
190
+ void registerBackend(const std::string &name, BackendCreate create);
191
+
192
+ // Helper struct to
193
+ template <typename TAccelerator>
194
+ struct RegisterAccelerator {
195
+ RegisterAccelerator(const char *name) {
196
+ registerBackend(name, &TAccelerator::connect);
197
+ }
198
+ };
199
+
200
+ #define REGISTER_ACCELERATOR(Name, TAccelerator) \
201
+ static ::esi::registry::internal::RegisterAccelerator<TAccelerator> \
202
+ __register_accel____LINE__(Name)
203
+
204
+ } // namespace internal
205
+ } // namespace registry
206
+
207
+ /// Background thread which services various requests. Currently, it listens on
208
+ /// ports and calls callbacks for incoming messages on said ports.
209
+ class AcceleratorServiceThread {
210
+ public:
211
+ AcceleratorServiceThread();
212
+ ~AcceleratorServiceThread();
213
+
214
+ /// When there's data on any of the listenPorts, call the callback. Callable
215
+ /// from any thread.
216
+ void
217
+ addListener(std::initializer_list<ReadChannelPort *> listenPorts,
218
+ std::function<void(ReadChannelPort *, MessageData)> callback);
219
+
220
+ /// Poll this module.
221
+ void addPoll(HWModule &module);
222
+
223
+ /// Instruct the service thread to stop running.
224
+ void stop();
225
+
226
+ private:
227
+ struct Impl;
228
+ std::unique_ptr<Impl> impl;
229
+ };
230
+ } // namespace esi
231
+
232
+ #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
+ return 0;
55
+ }
56
+
57
+ /// Connect to the accelerator using the specified backend and connection.
58
+ std::unique_ptr<AcceleratorConnection> connect() {
59
+ return ctxt.connect(backend, connStr);
60
+ }
61
+
62
+ /// Get the context.
63
+ Context &getContext() { return ctxt; }
64
+
65
+ protected:
66
+ 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
@@ -0,0 +1,154 @@
1
+ //===- Common.h - Commonly used classes w/o dependencies --------*- 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
+ // 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
+ //
13
+ //===----------------------------------------------------------------------===//
14
+
15
+ // NOLINTNEXTLINE(llvm-header-guard)
16
+ #ifndef ESI_COMMON_H
17
+ #define ESI_COMMON_H
18
+
19
+ #include <any>
20
+ #include <cstdint>
21
+ #include <map>
22
+ #include <optional>
23
+ #include <stdexcept>
24
+ #include <string>
25
+ #include <vector>
26
+
27
+ namespace esi {
28
+ class Type;
29
+
30
+ //===----------------------------------------------------------------------===//
31
+ // Common accelerator description types.
32
+ //===----------------------------------------------------------------------===//
33
+
34
+ struct AppID {
35
+ std::string name;
36
+ std::optional<uint32_t> idx;
37
+
38
+ AppID(const std::string &name, std::optional<uint32_t> idx = std::nullopt)
39
+ : name(name), idx(idx) {}
40
+
41
+ bool operator==(const AppID &other) const {
42
+ return name == other.name && idx == other.idx;
43
+ }
44
+ bool operator!=(const AppID &other) const { return !(*this == other); }
45
+ };
46
+ bool operator<(const AppID &a, const AppID &b);
47
+
48
+ class AppIDPath : public std::vector<AppID> {
49
+ public:
50
+ using std::vector<AppID>::vector;
51
+
52
+ AppIDPath operator+(const AppIDPath &b);
53
+ std::string toStr() const;
54
+ };
55
+ bool operator<(const AppIDPath &a, const AppIDPath &b);
56
+
57
+ struct Constant {
58
+ std::any value;
59
+ std::optional<const Type *> type;
60
+ };
61
+
62
+ struct ModuleInfo {
63
+ std::optional<std::string> name;
64
+ std::optional<std::string> summary;
65
+ std::optional<std::string> version;
66
+ std::optional<std::string> repo;
67
+ std::optional<std::string> commitHash;
68
+ std::map<std::string, Constant> constants;
69
+ std::map<std::string, std::any> extra;
70
+ };
71
+
72
+ /// A description of a service port. Used pretty exclusively in setting up the
73
+ /// design.
74
+ struct ServicePortDesc {
75
+ std::string name;
76
+ std::string portName;
77
+ };
78
+
79
+ /// Details about how to connect to a particular channel.
80
+ struct ChannelAssignment {
81
+ /// The name of the type of connection. Typically, the name of the DMA engine
82
+ /// or "cosim" if a cosimulation channel is being used.
83
+ std::string type;
84
+ /// Implementation-specific options.
85
+ std::map<std::string, std::any> implOptions;
86
+ };
87
+ using ChannelAssignments = std::map<std::string, ChannelAssignment>;
88
+
89
+ /// A description of a hardware client. Used pretty exclusively in setting up
90
+ /// the design.
91
+ struct HWClientDetail {
92
+ AppIDPath relPath;
93
+ ServicePortDesc port;
94
+ ChannelAssignments channelAssignments;
95
+ std::map<std::string, std::any> implOptions;
96
+ };
97
+ using HWClientDetails = std::vector<HWClientDetail>;
98
+ using ServiceImplDetails = std::map<std::string, std::any>;
99
+
100
+ /// A logical chunk of data representing serialized data. Currently, just a
101
+ /// wrapper for a vector of bytes, which is not efficient in terms of memory
102
+ /// copying. This will change in the future as will the API.
103
+ class MessageData {
104
+ public:
105
+ /// Adopts the data vector buffer.
106
+ MessageData() = default;
107
+ MessageData(std::vector<uint8_t> &data) : data(std::move(data)) {}
108
+ MessageData(const uint8_t *data, size_t size) : data(data, data + size) {}
109
+ ~MessageData() = default;
110
+
111
+ const uint8_t *getBytes() const { return data.data(); }
112
+ /// Get the size of the data in bytes.
113
+ size_t getSize() const { return data.size(); }
114
+
115
+ /// Cast to a type. Throws if the size of the data does not match the size of
116
+ /// the message. The lifetime of the resulting pointer is tied to the lifetime
117
+ /// of this object.
118
+ template <typename T>
119
+ const T *as() const {
120
+ if (data.size() != sizeof(T))
121
+ throw std::runtime_error("Data size does not match type size. Size is " +
122
+ std::to_string(data.size()) + ", expected " +
123
+ std::to_string(sizeof(T)) + ".");
124
+ return reinterpret_cast<const T *>(data.data());
125
+ }
126
+
127
+ /// Cast from a type to its raw bytes.
128
+ template <typename T>
129
+ static MessageData from(T &t) {
130
+ return MessageData(reinterpret_cast<const uint8_t *>(&t), sizeof(T));
131
+ }
132
+
133
+ /// Convert the data to a hex string.
134
+ std::string toHex() const;
135
+
136
+ private:
137
+ std::vector<uint8_t> data;
138
+ };
139
+
140
+ } // namespace esi
141
+
142
+ std::ostream &operator<<(std::ostream &, const esi::ModuleInfo &);
143
+ std::ostream &operator<<(std::ostream &, const esi::AppID &);
144
+
145
+ //===----------------------------------------------------------------------===//
146
+ // Functions which should be in the standard library.
147
+ //===----------------------------------------------------------------------===//
148
+
149
+ namespace esi {
150
+ std::string toHex(void *val);
151
+ std::string toHex(uint64_t val);
152
+ } // namespace esi
153
+
154
+ #endif // ESI_COMMON_H
@@ -0,0 +1,74 @@
1
+ //===- Context.h - Accelerator context --------------------------*- 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
+ // 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
+ //
13
+ //===----------------------------------------------------------------------===//
14
+
15
+ // NOLINTNEXTLINE(llvm-header-guard)
16
+ #ifndef ESI_CONTEXT_H
17
+ #define ESI_CONTEXT_H
18
+
19
+ #include "esi/Logging.h"
20
+ #include "esi/Types.h"
21
+
22
+ #include <exception>
23
+ #include <memory>
24
+ #include <optional>
25
+
26
+ namespace esi {
27
+ class AcceleratorConnection;
28
+
29
+ /// AcceleratorConnections, Accelerators, and Manifests must all share a
30
+ /// context. It owns all the types, uniquifying them.
31
+ class Context {
32
+ public:
33
+ Context() : logger(std::make_unique<ConsoleLogger>(Logger::Level::Warning)) {}
34
+ Context(std::unique_ptr<Logger> logger) : logger(std::move(logger)) {}
35
+
36
+ /// Create a context with a specific logger type.
37
+ template <typename T, typename... Args>
38
+ static Context withLogger(Args &&...args) {
39
+ return Context(std::make_unique<T>(args...));
40
+ }
41
+
42
+ /// Resolve a type id to the type.
43
+ std::optional<const Type *> getType(Type::ID id) const {
44
+ if (auto f = types.find(id); f != types.end())
45
+ return f->second.get();
46
+ return std::nullopt;
47
+ }
48
+
49
+ /// Register a type with the context. Takes ownership of the pointer type.
50
+ void registerType(Type *type);
51
+
52
+ /// Connect to an accelerator backend.
53
+ std::unique_ptr<AcceleratorConnection> connect(std::string backend,
54
+ std::string connection);
55
+
56
+ /// Register a logger with the accelerator. Assumes ownership of the logger.
57
+ void setLogger(std::unique_ptr<Logger> logger) {
58
+ if (!logger)
59
+ throw std::invalid_argument("logger must not be null");
60
+ this->logger = std::move(logger);
61
+ }
62
+ inline Logger &getLogger() { return *logger; }
63
+
64
+ private:
65
+ std::unique_ptr<Logger> logger;
66
+
67
+ private:
68
+ using TypeCache = std::map<Type::ID, std::unique_ptr<Type>>;
69
+ TypeCache types;
70
+ };
71
+
72
+ } // namespace esi
73
+
74
+ #endif // ESI_CONTEXT_H
@@ -0,0 +1,127 @@
1
+ //===- Design.h - Dynamic accelerator 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
+ // The dynamic API into an accelerator allows access to the accelerator's design
10
+ // and communication channels through various stl containers (e.g. std::vector,
11
+ // std::map, etc.). This allows runtime reflection against the accelerator and
12
+ // can be pybind'd to create a Python API.
13
+ //
14
+ // The static API, in contrast, is a compile-time API that allows access to the
15
+ // design and communication channels symbolically. It will be generated once
16
+ // (not here) then compiled into the host software.
17
+ //
18
+ // Note for hardware designers: the "design hierarchy" from the host API
19
+ // perspective is not the same as the hardware module instance hierarchy.
20
+ // Rather, it is only the relevant parts as defined by the AppID hierarchy --
21
+ // levels in the hardware module instance hierarchy get skipped.
22
+ //
23
+ // DO NOT EDIT!
24
+ // This file is distributed as part of an ESI package. The source for this file
25
+ // should always be modified within CIRCT.
26
+ //
27
+ //===----------------------------------------------------------------------===//
28
+
29
+ // NOLINTNEXTLINE(llvm-header-guard)
30
+ #ifndef ESI_DESIGN_H
31
+ #define ESI_DESIGN_H
32
+
33
+ #include "esi/Manifest.h"
34
+ #include "esi/Ports.h"
35
+ #include "esi/Services.h"
36
+
37
+ #include <string>
38
+
39
+ namespace esi {
40
+ // Forward declarations.
41
+ class Instance;
42
+ namespace services {
43
+ class Service;
44
+ } // namespace services
45
+
46
+ /// Represents either the top level or an instance of a hardware module.
47
+ class HWModule {
48
+ protected:
49
+ HWModule(std::optional<ModuleInfo> info,
50
+ std::vector<std::unique_ptr<Instance>> children,
51
+ std::vector<services::Service *> services,
52
+ std::vector<std::unique_ptr<BundlePort>> &ports);
53
+
54
+ public:
55
+ virtual ~HWModule() = default;
56
+
57
+ /// Access the module's metadata, if any.
58
+ std::optional<ModuleInfo> getInfo() const { return info; }
59
+ /// Get a vector of the module's children in a deterministic order.
60
+ std::vector<const Instance *> getChildrenOrdered() const {
61
+ std::vector<const Instance *> ret;
62
+ for (const auto &c : children)
63
+ ret.push_back(c.get());
64
+ return ret;
65
+ }
66
+ /// Access the module's children by ID.
67
+ const std::map<AppID, Instance *> &getChildren() const { return childIndex; }
68
+ /// Get the module's ports in a deterministic order.
69
+ std::vector<std::reference_wrapper<BundlePort>> getPortsOrdered() const {
70
+ std::vector<std::reference_wrapper<BundlePort>> ret;
71
+ for (const auto &p : ports)
72
+ ret.push_back(*p);
73
+ return ret;
74
+ }
75
+ /// Access the module's ports by ID.
76
+ const std::map<AppID, BundlePort &> &getPorts() const { return portIndex; }
77
+ /// Access the services provided by this module.
78
+ const std::vector<services::Service *> &getServices() const {
79
+ return services;
80
+ }
81
+
82
+ /// Master poll method. Calls the `poll` method on all locally owned ports and
83
+ /// the master `poll` method on all of the children. Returns true if any of
84
+ /// the `poll` calls returns true.
85
+ bool poll();
86
+
87
+ /// Attempt to resolve a path to a module instance. If a child is not found,
88
+ /// return null and set lastLookup to the path which wasn't found.
89
+ const HWModule *resolveInst(const AppIDPath &path,
90
+ AppIDPath &lastLookup) const;
91
+
92
+ /// Attempt to resolve a path to a port. If a child or port is not found,
93
+ /// return null and set lastLookup to the path which wasn't found.
94
+ BundlePort *resolvePort(const AppIDPath &path, AppIDPath &lastLookup) const;
95
+
96
+ protected:
97
+ const std::optional<ModuleInfo> info;
98
+ const std::vector<std::unique_ptr<Instance>> children;
99
+ const std::map<AppID, Instance *> childIndex;
100
+ const std::vector<services::Service *> services;
101
+ const std::vector<std::unique_ptr<BundlePort>> ports;
102
+ const std::map<AppID, BundlePort &> portIndex;
103
+ };
104
+
105
+ /// Subclass of `HWModule` which represents a submodule instance. Adds an AppID,
106
+ /// which the top level doesn't have or need.
107
+ class Instance : public HWModule {
108
+ public:
109
+ Instance() = delete;
110
+ Instance(const Instance &) = delete;
111
+ ~Instance() = default;
112
+ Instance(AppID id, std::optional<ModuleInfo> info,
113
+ std::vector<std::unique_ptr<Instance>> children,
114
+ std::vector<services::Service *> services,
115
+ std::vector<std::unique_ptr<BundlePort>> &ports)
116
+ : HWModule(info, std::move(children), services, ports), id(id) {}
117
+
118
+ /// Get the instance's ID, which it will always have.
119
+ const AppID getID() const { return id; }
120
+
121
+ protected:
122
+ const AppID id;
123
+ };
124
+
125
+ } // namespace esi
126
+
127
+ #endif // ESI_DESIGN_H