25#pragma GCC diagnostic push
26#pragma GCC diagnostic ignored "-Wcovered-switch-default"
28#include <nlohmann/json.hpp>
30#pragma GCC diagnostic pop
43int main(
int argc,
const char *argv[]) {
45 cli.description(
"Query an ESI system for information from the manifest.");
47 CLI::App *versionSub =
48 cli.add_subcommand(
"version",
"Print ESI system version");
49 bool infoDetails =
false;
51 cli.add_subcommand(
"info",
"Print ESI system information");
52 infoSub->add_flag(
"--details", infoDetails,
53 "Print detailed information about the system");
54 bool hierDetails =
false;
55 CLI::App *hierSub = cli.add_subcommand(
"hier",
"Print ESI system hierarchy");
56 hierSub->add_flag(
"--details", hierDetails,
57 "Print detailed information about the system");
58 bool telemetryJson =
false;
59 CLI::App *telemetrySub =
60 cli.add_subcommand(
"telemetry",
"Print ESI system telemetry information");
61 telemetrySub->add_flag(
"--json", telemetryJson,
62 "Dump telemetry information as JSON");
64 cli.add_subcommand(
"reset",
"Reset the ESI system design");
66 if (
int rc = cli.
esiParse(argc, argv))
68 if (!cli.get_help_ptr()->empty())
77 std::cout << info.getEsiVersion() << std::endl;
82 else if (*telemetrySub) {
87 }
else if (*resetSub) {
91 }
catch (std::exception &e) {
98 std::string jsonManifest =
100 Manifest m(acc.getCtxt(), jsonManifest);
101 os <<
"API version: " << m.
getApiVersion() << std::endl << std::endl;
102 os <<
"********************************" << std::endl;
103 os <<
"* Module information" << std::endl;
104 os <<
"********************************" << std::endl;
113 os <<
"********************************" << std::endl;
114 os <<
"* Type table" << std::endl;
115 os <<
"********************************" << std::endl;
119 os <<
" " << i++ <<
": " << t->getID() << std::endl;
131 os << indent <<
" " << port.
getID() <<
":";
133 if (
auto svcPortStr = svcPort->toString(
true)) {
134 os <<
" " << *svcPortStr << std::endl;
138 for (
const auto &[name, chan] : port.
getChannels())
139 os << indent <<
" " << name <<
": " << chan.getType()->
toString(
true)
146 std::any_of(d->getPorts().begin(), d->getPorts().end(),
147 [&](
const std::pair<const AppID, BundlePort &> port) {
148 return showPort(port.second, details);
150 if (!details && !hasPorts && d->getChildren().empty())
152 os << indent <<
"* Instance: ";
153 if (
auto inst =
dynamic_cast<const Instance *
>(d)) {
154 os << inst->getID() << std::endl;
155 if (inst->getInfo() && inst->getInfo()->name)
156 os << indent <<
"* Module: " << *inst->getInfo()->name << std::endl;
158 os <<
"top" << std::endl;
161 os << indent <<
"* Ports:" << std::endl;
162 for (
const BundlePort &port : d->getPortsOrdered())
163 printPort(os, port, indent +
" ", details);
164 std::vector<const Instance *> children = d->getChildrenOrdered();
165 if (!children.empty()) {
166 os << indent <<
"* Children:" << std::endl;
167 for (
const Instance *child : d->getChildrenOrdered())
177 os <<
"********************************" << std::endl;
178 os <<
"* Design hierarchy" << std::endl;
179 os <<
"********************************" << std::endl;
186 bool hasData =
false;
188 for (
const auto &portRef :
module.getPortsOrdered()) {
189 BundlePort &port = portRef.get();
193 node[metric->getID().toString()] = metric->readInt();
198 for (
const Instance *child : module.getChildrenOrdered()) {
199 nlohmann::json childNode = nlohmann::json::object();
201 node[child->getID().toString()] = childNode;
213 acc.getServiceThread()->addPoll(*accel);
215 nlohmann::json root = nlohmann::json::object();
217 root = nlohmann::json{{
"error",
"No telemetry metrics found"}};
219 os << root.dump(2) << std::endl;
226 acc.getServiceThread()->addPoll(*accel);
230 os <<
"No telemetry service found" << std::endl;
233 os <<
"********************************" << std::endl;
234 os <<
"* Telemetry" << std::endl;
235 os <<
"********************************" << std::endl;
238 const std::map<AppIDPath, services::TelemetryService::Metric *>
240 for (
const auto &[
id, port] : telemetryPorts) {
244 uint64_t value = port->readInt();
245 os << value << std::endl;
250 os <<
"Resetting design..." << std::endl;
Abstract class representing a connection to an accelerator.
Top level accelerator class.
Services provide connections to 'bundles' – collections of named, unidirectional communication channe...
const PortMap & getChannels() const
AppID getID() const
Get the ID of the port.
Common options and code for ESI runtime tools.
Context & getContext()
Get the context.
AcceleratorConnection * connect()
Connect to the accelerator using the specified backend and connection.
int esiParse(int argc, const char **argv)
Run the parser.
AcceleratorConnections, Accelerators, and Manifests must all share a context.
Represents either the top level or an instance of a hardware module.
Subclass of HWModule which represents a submodule instance.
virtual void error(const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details=nullptr)
Report an error.
Class to parse a manifest.
uint32_t getApiVersion() const
Accelerator * buildAccelerator(AcceleratorConnection &acc) const
const std::vector< const Type * > & getTypeTable() const
The Type Table is an ordered list of types.
std::vector< ModuleInfo > getModuleInfos() const
Root class of the ESI type system.
Add a custom interface to a service client at a particular point in the design hierarchy.
Information about the Accelerator system.
virtual std::string getJsonManifest() const
Return the JSON-formatted system manifest.
A telemetry port which gets attached to a service port.
Service for retrieving telemetry data from the accelerator.
std::map< AppIDPath, Metric * > getTelemetryPorts()
void printHier(std::ostream &os, AcceleratorConnection &acc, bool details)
void printInstance(std::ostream &os, const HWModule *d, std::string indent, bool details)
void printPort(std::ostream &os, const BundlePort &port, std::string indent, bool details)
void printInfo(std::ostream &os, AcceleratorConnection &acc, bool details)
void printTelemetry(std::ostream &os, AcceleratorConnection &acc)
static bool showPort(const BundlePort &port, bool details)
static bool collectTelemetryJson(const HWModule &module, nlohmann::json &node)
void printTelemetryJson(std::ostream &os, AcceleratorConnection &acc)
void resetDesign(std::ostream &os, AcceleratorConnection &acc)
std::string toString() const