esiaccel 0.2.3.dev80__cp314-cp314-win_amd64.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.
- esiaccel/CosimBackend.dll +0 -0
- esiaccel/CosimBackend.lib +0 -0
- esiaccel/CosimRpc.dll +0 -0
- esiaccel/CosimRpc.lib +0 -0
- esiaccel/ESICppRuntime.dll +0 -0
- esiaccel/ESICppRuntime.lib +0 -0
- esiaccel/EsiCosimDpiServer.dll +0 -0
- esiaccel/EsiCosimDpiServer.lib +0 -0
- esiaccel/MtiPli.dll +0 -0
- esiaccel/MtiPli.lib +0 -0
- esiaccel/__init__.py +31 -0
- esiaccel/abseil_dll.dll +0 -0
- esiaccel/accelerator.py +134 -0
- esiaccel/cares.dll +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/esi-cosim.py +104 -0
- esiaccel/esiCppAccel.cp312-win_amd64.pyd +0 -0
- esiaccel/esiquery.exe +0 -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/libcrypto-3-x64.dll +0 -0
- esiaccel/libprotobuf.dll +0 -0
- esiaccel/libssl-3-x64.dll +0 -0
- esiaccel/re2.dll +0 -0
- esiaccel/types.py +565 -0
- esiaccel/utils.py +54 -0
- esiaccel/zlib1.dll +0 -0
- esiaccel-0.2.3.dev80.dist-info/METADATA +254 -0
- esiaccel-0.2.3.dev80.dist-info/RECORD +58 -0
- esiaccel-0.2.3.dev80.dist-info/WHEEL +5 -0
- esiaccel-0.2.3.dev80.dist-info/entry_points.txt +4 -0
- esiaccel-0.2.3.dev80.dist-info/licenses/LICENSE +234 -0
- esiaccel-0.2.3.dev80.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,132 @@
|
|
|
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
|
+
public:
|
|
49
|
+
HWModule(const HWModule &) = delete;
|
|
50
|
+
HWModule &operator=(const HWModule &) = delete;
|
|
51
|
+
|
|
52
|
+
protected:
|
|
53
|
+
HWModule(std::optional<ModuleInfo> info,
|
|
54
|
+
std::vector<std::unique_ptr<Instance>> children,
|
|
55
|
+
std::vector<services::Service *> services,
|
|
56
|
+
std::vector<std::unique_ptr<BundlePort>> &&ports);
|
|
57
|
+
|
|
58
|
+
public:
|
|
59
|
+
virtual ~HWModule() = default;
|
|
60
|
+
|
|
61
|
+
/// Access the module's metadata, if any.
|
|
62
|
+
std::optional<ModuleInfo> getInfo() const { return info; }
|
|
63
|
+
/// Get a vector of the module's children in a deterministic order.
|
|
64
|
+
std::vector<const Instance *> getChildrenOrdered() const {
|
|
65
|
+
std::vector<const Instance *> ret;
|
|
66
|
+
for (const auto &c : children)
|
|
67
|
+
ret.push_back(c.get());
|
|
68
|
+
return ret;
|
|
69
|
+
}
|
|
70
|
+
/// Access the module's children by ID.
|
|
71
|
+
const std::map<AppID, Instance *> &getChildren() const { return childIndex; }
|
|
72
|
+
/// Get the module's ports in a deterministic order.
|
|
73
|
+
std::vector<std::reference_wrapper<BundlePort>> getPortsOrdered() const {
|
|
74
|
+
std::vector<std::reference_wrapper<BundlePort>> ret;
|
|
75
|
+
for (const auto &p : ports)
|
|
76
|
+
ret.push_back(*p);
|
|
77
|
+
return ret;
|
|
78
|
+
}
|
|
79
|
+
/// Access the module's ports by ID.
|
|
80
|
+
const std::map<AppID, BundlePort &> &getPorts() const { return portIndex; }
|
|
81
|
+
/// Access the services provided by this module.
|
|
82
|
+
const std::vector<services::Service *> &getServices() const {
|
|
83
|
+
return services;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/// Master poll method. Calls the `poll` method on all locally owned ports and
|
|
87
|
+
/// the master `poll` method on all of the children. Returns true if any of
|
|
88
|
+
/// the `poll` calls returns true.
|
|
89
|
+
bool poll();
|
|
90
|
+
|
|
91
|
+
/// Attempt to resolve a path to a module instance. If a child is not found,
|
|
92
|
+
/// return null and set lastLookup to the path which wasn't found.
|
|
93
|
+
const HWModule *resolveInst(const AppIDPath &path,
|
|
94
|
+
AppIDPath &lastLookup) const;
|
|
95
|
+
|
|
96
|
+
/// Attempt to resolve a path to a port. If a child or port is not found,
|
|
97
|
+
/// return null and set lastLookup to the path which wasn't found.
|
|
98
|
+
BundlePort *resolvePort(const AppIDPath &path, AppIDPath &lastLookup) const;
|
|
99
|
+
|
|
100
|
+
protected:
|
|
101
|
+
const std::optional<ModuleInfo> info;
|
|
102
|
+
const std::vector<std::unique_ptr<Instance>> children;
|
|
103
|
+
const std::map<AppID, Instance *> childIndex;
|
|
104
|
+
const std::vector<services::Service *> services;
|
|
105
|
+
const std::vector<std::unique_ptr<BundlePort>> ports;
|
|
106
|
+
const std::map<AppID, BundlePort &> portIndex;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/// Subclass of `HWModule` which represents a submodule instance. Adds an AppID,
|
|
110
|
+
/// which the top level doesn't have or need.
|
|
111
|
+
class Instance : public HWModule {
|
|
112
|
+
public:
|
|
113
|
+
Instance() = delete;
|
|
114
|
+
Instance(const Instance &) = delete;
|
|
115
|
+
~Instance() = default;
|
|
116
|
+
Instance(AppID id, std::optional<ModuleInfo> info,
|
|
117
|
+
std::vector<std::unique_ptr<Instance>> children,
|
|
118
|
+
std::vector<services::Service *> services,
|
|
119
|
+
std::vector<std::unique_ptr<BundlePort>> &&ports)
|
|
120
|
+
: HWModule(info, std::move(children), services, std::move(ports)),
|
|
121
|
+
id(id) {}
|
|
122
|
+
|
|
123
|
+
/// Get the instance's ID, which it will always have.
|
|
124
|
+
AppID getID() const { return id; }
|
|
125
|
+
|
|
126
|
+
protected:
|
|
127
|
+
const AppID id;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
} // namespace esi
|
|
131
|
+
|
|
132
|
+
#endif // ESI_DESIGN_H
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
//===- Engines.h - Implement port communication -----------------*- 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
|
+
// Engines (as in DMA engine) implement the actual communication between the
|
|
16
|
+
// host and the accelerator. They are low level of the ESI runtime API and are
|
|
17
|
+
// not intended to be used directly by users.
|
|
18
|
+
//
|
|
19
|
+
// They are called "engines" rather than "DMA engines" since communication need
|
|
20
|
+
// not be implemented via DMA.
|
|
21
|
+
//
|
|
22
|
+
//===----------------------------------------------------------------------===//
|
|
23
|
+
|
|
24
|
+
// NOLINTNEXTLINE(llvm-header-guard)
|
|
25
|
+
#ifndef ESI_ENGINGES_H
|
|
26
|
+
#define ESI_ENGINGES_H
|
|
27
|
+
|
|
28
|
+
#include "esi/Common.h"
|
|
29
|
+
#include "esi/Ports.h"
|
|
30
|
+
#include "esi/Services.h"
|
|
31
|
+
#include "esi/Utils.h"
|
|
32
|
+
|
|
33
|
+
#include <cassert>
|
|
34
|
+
#include <future>
|
|
35
|
+
|
|
36
|
+
namespace esi {
|
|
37
|
+
class Accelerator;
|
|
38
|
+
|
|
39
|
+
/// Engines implement the actual channel communication between the host and the
|
|
40
|
+
/// accelerator. Engines can support multiple channels. They are low level of
|
|
41
|
+
/// the ESI runtime API and are not intended to be used directly by users.
|
|
42
|
+
class Engine {
|
|
43
|
+
public:
|
|
44
|
+
Engine(AcceleratorConnection &conn) : connected(false), conn(conn) {}
|
|
45
|
+
virtual ~Engine() = default;
|
|
46
|
+
/// Start the engine, if applicable.
|
|
47
|
+
virtual void connect() { connected = true; };
|
|
48
|
+
/// Stop the engine, if applicable.
|
|
49
|
+
virtual void disconnect() { connected = false; };
|
|
50
|
+
/// Get a port for a channel, from the cache if it exists or create it. An
|
|
51
|
+
/// engine may override this method if different behavior is desired.
|
|
52
|
+
virtual ChannelPort &requestPort(AppIDPath idPath,
|
|
53
|
+
const std::string &channelName,
|
|
54
|
+
BundleType::Direction dir, const Type *type);
|
|
55
|
+
|
|
56
|
+
protected:
|
|
57
|
+
/// Each engine needs to know how to create a ports. This method is called if
|
|
58
|
+
/// a port doesn't exist in the engine cache.
|
|
59
|
+
virtual std::unique_ptr<ChannelPort>
|
|
60
|
+
createPort(AppIDPath idPath, const std::string &channelName,
|
|
61
|
+
BundleType::Direction dir, const Type *type) = 0;
|
|
62
|
+
|
|
63
|
+
bool connected;
|
|
64
|
+
AcceleratorConnection &conn;
|
|
65
|
+
|
|
66
|
+
private:
|
|
67
|
+
std::map<std::pair<AppIDPath, std::string>, std::unique_ptr<ChannelPort>>
|
|
68
|
+
ownedPorts;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/// Since engines can support multiple channels BUT not necessarily all of the
|
|
72
|
+
/// channels in a bundle, a mapping from bundle channels to engines is needed.
|
|
73
|
+
class BundleEngineMap {
|
|
74
|
+
friend class AcceleratorConnection;
|
|
75
|
+
|
|
76
|
+
public:
|
|
77
|
+
/// Request ports for all the channels in a bundle. If the engine doesn't
|
|
78
|
+
/// exist for a particular channel, skip said channel.
|
|
79
|
+
PortMap requestPorts(const AppIDPath &idPath,
|
|
80
|
+
const BundleType *bundleType) const;
|
|
81
|
+
|
|
82
|
+
private:
|
|
83
|
+
/// Set a particlar engine for a particular channel. Should only be called by
|
|
84
|
+
/// AcceleratorConnection while registering engines.
|
|
85
|
+
void setEngine(const std::string &channelName, Engine *engine);
|
|
86
|
+
std::map<std::string, Engine *> bundleEngineMap;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
namespace registry {
|
|
90
|
+
|
|
91
|
+
/// Create an engine by name. This is the primary way to create engines for
|
|
92
|
+
/// "normal" backends.
|
|
93
|
+
std::unique_ptr<Engine> createEngine(AcceleratorConnection &conn,
|
|
94
|
+
const std::string &dmaEngineName,
|
|
95
|
+
AppIDPath idPath,
|
|
96
|
+
const ServiceImplDetails &details,
|
|
97
|
+
const HWClientDetails &clients);
|
|
98
|
+
|
|
99
|
+
namespace internal {
|
|
100
|
+
|
|
101
|
+
/// Engines can register themselves for pluggable functionality.
|
|
102
|
+
using EngineCreate = std::function<std::unique_ptr<Engine>(
|
|
103
|
+
AcceleratorConnection &conn, AppIDPath idPath,
|
|
104
|
+
const ServiceImplDetails &details, const HWClientDetails &clients)>;
|
|
105
|
+
void registerEngine(const std::string &name, EngineCreate create);
|
|
106
|
+
|
|
107
|
+
/// Helper struct to register engines.
|
|
108
|
+
template <typename TEngine>
|
|
109
|
+
struct RegisterEngine {
|
|
110
|
+
RegisterEngine(const char *name) { registerEngine(name, &TEngine::create); }
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
#define CONCAT_(prefix, suffix) prefix##suffix
|
|
114
|
+
#define CONCAT(prefix, suffix) CONCAT_(prefix, suffix)
|
|
115
|
+
#define REGISTER_ENGINE(Name, TEngine) \
|
|
116
|
+
static ::esi::registry::internal::RegisterEngine<TEngine> CONCAT( \
|
|
117
|
+
__register_engine__, __LINE__)(Name)
|
|
118
|
+
|
|
119
|
+
} // namespace internal
|
|
120
|
+
} // namespace registry
|
|
121
|
+
|
|
122
|
+
} // namespace esi
|
|
123
|
+
|
|
124
|
+
#endif // ESI_PORTS_H
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
//===- Logging.h - ESI Runtime logging --------------------------*- 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
|
+
// ESI runtime logging is very simple but very flexible. Rather than mandating a
|
|
10
|
+
// particular logging library, it allows users to hook into their existing
|
|
11
|
+
// logging system by implementing a simple interface.
|
|
12
|
+
//
|
|
13
|
+
//===----------------------------------------------------------------------===//
|
|
14
|
+
//
|
|
15
|
+
// DO NOT EDIT!
|
|
16
|
+
// This file is distributed as part of an ESI package. The source for this file
|
|
17
|
+
// should always be modified within CIRCT.
|
|
18
|
+
//
|
|
19
|
+
//===----------------------------------------------------------------------===//
|
|
20
|
+
|
|
21
|
+
// NOLINTNEXTLINE(llvm-header-guard)
|
|
22
|
+
#ifndef ESI_LOGGING_H
|
|
23
|
+
#define ESI_LOGGING_H
|
|
24
|
+
|
|
25
|
+
#include <any>
|
|
26
|
+
#include <functional>
|
|
27
|
+
#include <iosfwd>
|
|
28
|
+
#include <map>
|
|
29
|
+
#include <memory>
|
|
30
|
+
#include <mutex>
|
|
31
|
+
#include <string>
|
|
32
|
+
|
|
33
|
+
namespace esi {
|
|
34
|
+
|
|
35
|
+
class Logger {
|
|
36
|
+
public:
|
|
37
|
+
enum class Level {
|
|
38
|
+
Trace, // Trace is even more detailed than debug and requires a compiler
|
|
39
|
+
// flag to be enabled when the runtime is built. Allows clients to do
|
|
40
|
+
// things like log every single message or interaction.
|
|
41
|
+
Debug, // Information useful when trying to debug an application.
|
|
42
|
+
Info, // General information, like connecting to an accelerator.
|
|
43
|
+
Warning, // May indicate a problem.
|
|
44
|
+
Error, // Many errors will be followed by exceptions which may get caught.
|
|
45
|
+
};
|
|
46
|
+
Logger(bool debugEnabled, bool traceEnabled)
|
|
47
|
+
: debugEnabled(debugEnabled), traceEnabled(traceEnabled) {}
|
|
48
|
+
virtual ~Logger() = default;
|
|
49
|
+
bool getDebugEnabled() { return debugEnabled; }
|
|
50
|
+
bool getTraceEnabled() { return traceEnabled; }
|
|
51
|
+
|
|
52
|
+
/// Report a log message.
|
|
53
|
+
/// Arguments:
|
|
54
|
+
/// level: The log level as defined by the 'Level' enum above.
|
|
55
|
+
/// subsystem: The subsystem that generated the log message.
|
|
56
|
+
/// msg: The log message.
|
|
57
|
+
/// details: Optional additional structured details to include in the log
|
|
58
|
+
/// message. If there are no details, this should be nullptr.
|
|
59
|
+
virtual void
|
|
60
|
+
log(Level level, const std::string &subsystem, const std::string &msg,
|
|
61
|
+
const std::map<std::string, std::any> *details = nullptr) = 0;
|
|
62
|
+
|
|
63
|
+
/// Report an error.
|
|
64
|
+
virtual void error(const std::string &subsystem, const std::string &msg,
|
|
65
|
+
const std::map<std::string, std::any> *details = nullptr) {
|
|
66
|
+
log(Level::Error, subsystem, msg, details);
|
|
67
|
+
}
|
|
68
|
+
/// Report a warning.
|
|
69
|
+
virtual void
|
|
70
|
+
warning(const std::string &subsystem, const std::string &msg,
|
|
71
|
+
const std::map<std::string, std::any> *details = nullptr) {
|
|
72
|
+
log(Level::Warning, subsystem, msg, details);
|
|
73
|
+
}
|
|
74
|
+
/// Report an informational message.
|
|
75
|
+
virtual void info(const std::string &subsystem, const std::string &msg,
|
|
76
|
+
const std::map<std::string, std::any> *details = nullptr) {
|
|
77
|
+
log(Level::Info, subsystem, msg, details);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/// Report a debug message. This is not virtual so that it can be inlined to
|
|
81
|
+
/// minimize performance impact that debug messages have, allowing debug
|
|
82
|
+
/// messages in Release builds.
|
|
83
|
+
inline void debug(const std::string &subsystem, const std::string &msg,
|
|
84
|
+
const std::map<std::string, std::any> *details = nullptr) {
|
|
85
|
+
if (debugEnabled)
|
|
86
|
+
debugImpl(subsystem, msg, details);
|
|
87
|
+
}
|
|
88
|
+
/// Call the debug function callback only if debug is enabled then log a debug
|
|
89
|
+
/// message. Allows users to run heavy weight debug message generation code
|
|
90
|
+
/// only when debug is enabled, which in turns allows users to provide
|
|
91
|
+
/// fully-featured debug messages in Release builds with minimal performance
|
|
92
|
+
/// impact. Not virtual so that it can be inlined.
|
|
93
|
+
inline void
|
|
94
|
+
debug(std::function<
|
|
95
|
+
void(std::string &subsystem, std::string &msg,
|
|
96
|
+
std::unique_ptr<std::map<std::string, std::any>> &details)>
|
|
97
|
+
debugFunc) {
|
|
98
|
+
if (debugEnabled)
|
|
99
|
+
debugImpl(debugFunc);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/// Log a trace message. If tracing is not enabled, this is a no-op. Since it
|
|
103
|
+
/// is inlined, the compiler will hopefully optimize it away creating a
|
|
104
|
+
/// zero-overhead call. This means that clients are free to go crazy with
|
|
105
|
+
/// trace messages.
|
|
106
|
+
inline void trace(const std::string &subsystem, const std::string &msg,
|
|
107
|
+
const std::map<std::string, std::any> *details = nullptr) {
|
|
108
|
+
#ifdef ESI_RUNTIME_TRACE
|
|
109
|
+
if (traceEnabled)
|
|
110
|
+
log(Level::Trace, subsystem, msg, details);
|
|
111
|
+
#endif
|
|
112
|
+
}
|
|
113
|
+
/// Log a trace message using a callback. Same as above, users can go hog-wild
|
|
114
|
+
/// calling this.
|
|
115
|
+
inline void
|
|
116
|
+
trace(std::function<
|
|
117
|
+
void(std::string &subsystem, std::string &msg,
|
|
118
|
+
std::unique_ptr<std::map<std::string, std::any>> &details)>
|
|
119
|
+
traceFunc) {
|
|
120
|
+
#ifdef ESI_RUNTIME_TRACE
|
|
121
|
+
if (!traceEnabled)
|
|
122
|
+
return;
|
|
123
|
+
std::string subsystem;
|
|
124
|
+
std::string msg;
|
|
125
|
+
std::unique_ptr<std::map<std::string, std::any>> details = nullptr;
|
|
126
|
+
traceFunc(subsystem, msg, details);
|
|
127
|
+
log(Level::Trace, subsystem, msg, details.get());
|
|
128
|
+
#endif
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
protected:
|
|
132
|
+
/// Overrideable version of debug. Only gets called if debug is enabled.
|
|
133
|
+
virtual void debugImpl(const std::string &subsystem, const std::string &msg,
|
|
134
|
+
const std::map<std::string, std::any> *details) {
|
|
135
|
+
log(Level::Debug, subsystem, msg, details);
|
|
136
|
+
}
|
|
137
|
+
/// Overrideable version of debug. Only gets called if debug is enabled.
|
|
138
|
+
virtual void
|
|
139
|
+
debugImpl(std::function<
|
|
140
|
+
void(std::string &subsystem, std::string &msg,
|
|
141
|
+
std::unique_ptr<std::map<std::string, std::any>> &details)>
|
|
142
|
+
debugFunc) {
|
|
143
|
+
if (!debugEnabled)
|
|
144
|
+
return;
|
|
145
|
+
std::string subsystem;
|
|
146
|
+
std::string msg;
|
|
147
|
+
std::unique_ptr<std::map<std::string, std::any>> details = nullptr;
|
|
148
|
+
debugFunc(subsystem, msg, details);
|
|
149
|
+
debugImpl(subsystem, msg, details.get());
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/// Enable or disable debug messages.
|
|
153
|
+
bool debugEnabled = false;
|
|
154
|
+
|
|
155
|
+
/// Enable or disable trace messages.
|
|
156
|
+
bool traceEnabled;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/// A thread-safe logger which calls functions implemented by subclasses. Only
|
|
160
|
+
/// protects the `log` method. If subclasses override other methods and need to
|
|
161
|
+
/// protect them, they need to do that themselves.
|
|
162
|
+
class TSLogger : public Logger {
|
|
163
|
+
public:
|
|
164
|
+
using Logger::Logger;
|
|
165
|
+
|
|
166
|
+
/// Grabs the lock and calls logImpl.
|
|
167
|
+
void log(Level level, const std::string &subsystem, const std::string &msg,
|
|
168
|
+
const std::map<std::string, std::any> *details) override final;
|
|
169
|
+
|
|
170
|
+
protected:
|
|
171
|
+
/// Subclasses must implement this method to log messages.
|
|
172
|
+
virtual void logImpl(Level level, const std::string &subsystem,
|
|
173
|
+
const std::string &msg,
|
|
174
|
+
const std::map<std::string, std::any> *details) = 0;
|
|
175
|
+
|
|
176
|
+
/// Mutex to protect the stream from interleaved logging writes.
|
|
177
|
+
std::mutex mutex;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/// A logger that writes to a C++ std::ostream.
|
|
181
|
+
class StreamLogger : public TSLogger {
|
|
182
|
+
public:
|
|
183
|
+
/// Create a stream logger that logs to the given output stream and error
|
|
184
|
+
/// output stream.
|
|
185
|
+
StreamLogger(Level minLevel, std::ostream &out, std::ostream &error)
|
|
186
|
+
: TSLogger(minLevel <= Level::Debug, minLevel <= Level::Trace),
|
|
187
|
+
minLevel(minLevel), outStream(out), errorStream(error) {}
|
|
188
|
+
/// Create a stream logger that logs to stdout, stderr.
|
|
189
|
+
StreamLogger(Level minLevel);
|
|
190
|
+
void logImpl(Level level, const std::string &subsystem,
|
|
191
|
+
const std::string &msg,
|
|
192
|
+
const std::map<std::string, std::any> *details) override;
|
|
193
|
+
|
|
194
|
+
private:
|
|
195
|
+
/// The minimum log level to emit.
|
|
196
|
+
Level minLevel;
|
|
197
|
+
|
|
198
|
+
/// Everything except errors goes here.
|
|
199
|
+
std::ostream &outStream;
|
|
200
|
+
/// Just for errors.
|
|
201
|
+
std::ostream &errorStream;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
/// A logger that writes to the console. Includes color support.
|
|
205
|
+
class ConsoleLogger : public TSLogger {
|
|
206
|
+
public:
|
|
207
|
+
/// Create a stream logger that logs to stdout, stderr.
|
|
208
|
+
ConsoleLogger(Level minLevel);
|
|
209
|
+
void logImpl(Level level, const std::string &subsystem,
|
|
210
|
+
const std::string &msg,
|
|
211
|
+
const std::map<std::string, std::any> *details) override;
|
|
212
|
+
|
|
213
|
+
private:
|
|
214
|
+
/// The minimum log level to emit.
|
|
215
|
+
Level minLevel;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/// A logger that does nothing.
|
|
219
|
+
class NullLogger : public Logger {
|
|
220
|
+
public:
|
|
221
|
+
NullLogger() : Logger(false, false) {}
|
|
222
|
+
void log(Level, const std::string &, const std::string &,
|
|
223
|
+
const std::map<std::string, std::any> *) override {}
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
/// 'Stringify' a std::any. This is used to log std::any values by some loggers.
|
|
227
|
+
std::string toString(const std::any &a);
|
|
228
|
+
|
|
229
|
+
} // namespace esi
|
|
230
|
+
|
|
231
|
+
#endif // ESI_LOGGING_H
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
//===- Manifest.h - Metadata on the accelerator -----------------*- 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
|
+
// Manifest parsing and API creation.
|
|
10
|
+
//
|
|
11
|
+
// DO NOT EDIT!
|
|
12
|
+
// This file is distributed as part of an ESI package. The source for this file
|
|
13
|
+
// should always be modified within CIRCT.
|
|
14
|
+
//
|
|
15
|
+
//===----------------------------------------------------------------------===//
|
|
16
|
+
|
|
17
|
+
// NOLINTNEXTLINE(llvm-header-guard)
|
|
18
|
+
#ifndef ESI_MANIFEST_H
|
|
19
|
+
#define ESI_MANIFEST_H
|
|
20
|
+
|
|
21
|
+
#include "esi/Common.h"
|
|
22
|
+
#include "esi/Context.h"
|
|
23
|
+
#include "esi/Types.h"
|
|
24
|
+
|
|
25
|
+
#include <any>
|
|
26
|
+
#include <memory>
|
|
27
|
+
#include <optional>
|
|
28
|
+
#include <string>
|
|
29
|
+
#include <vector>
|
|
30
|
+
|
|
31
|
+
namespace esi {
|
|
32
|
+
|
|
33
|
+
// Forward declarations.
|
|
34
|
+
class AcceleratorConnection;
|
|
35
|
+
class Accelerator;
|
|
36
|
+
|
|
37
|
+
/// Class to parse a manifest. It also constructs the dynamic API for the
|
|
38
|
+
/// accelerator.
|
|
39
|
+
class Manifest {
|
|
40
|
+
public:
|
|
41
|
+
class Impl;
|
|
42
|
+
|
|
43
|
+
Manifest(const Manifest &) = delete;
|
|
44
|
+
Manifest(Context &ctxt, const std::string &jsonManifest);
|
|
45
|
+
~Manifest();
|
|
46
|
+
|
|
47
|
+
uint32_t getApiVersion() const;
|
|
48
|
+
// Modules which have designer specified metadata.
|
|
49
|
+
std::vector<ModuleInfo> getModuleInfos() const;
|
|
50
|
+
|
|
51
|
+
// Build a dynamic design hierarchy from the manifest. The
|
|
52
|
+
// AcceleratorConnection owns the returned pointer so its lifetime is
|
|
53
|
+
// determined by the connection.
|
|
54
|
+
Accelerator *buildAccelerator(AcceleratorConnection &acc) const;
|
|
55
|
+
|
|
56
|
+
/// The Type Table is an ordered list of types. The offset can be used to
|
|
57
|
+
/// compactly and uniquely within a design. It does not include all of the
|
|
58
|
+
/// types in a design -- just the ones listed in the 'types' section of the
|
|
59
|
+
/// manifest.
|
|
60
|
+
const std::vector<const Type *> &getTypeTable() const;
|
|
61
|
+
|
|
62
|
+
private:
|
|
63
|
+
Impl *impl;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
} // namespace esi
|
|
67
|
+
|
|
68
|
+
std::ostream &operator<<(std::ostream &, const esi::ModuleInfo &);
|
|
69
|
+
|
|
70
|
+
#endif // ESI_MANIFEST_H
|