Loading [MathJax]/extensions/tex2jax.js
CIRCT 21.0.0git
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
esiquery.cpp
Go to the documentation of this file.
1//===- esiquery.cpp - ESI accelerator system query tool -------------------===//
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/Accelerator.h"
17#include "esi/CLI.h"
18#include "esi/Manifest.h"
19#include "esi/Services.h"
20
21#include <iostream>
22#include <map>
23#include <stdexcept>
24
25using namespace esi;
26
27void printInfo(std::ostream &os, AcceleratorConnection &acc);
28void printHier(std::ostream &os, AcceleratorConnection &acc);
29void printTelemetry(std::ostream &os, AcceleratorConnection &acc);
30
31int main(int argc, const char *argv[]) {
32 CliParser cli("esiquery");
33 cli.description("Query an ESI system for information from the manifest.");
34
35 CLI::App *versionSub =
36 cli.add_subcommand("version", "Print ESI system version");
37 CLI::App *infoSub =
38 cli.add_subcommand("info", "Print ESI system information");
39 CLI::App *hierSub = cli.add_subcommand("hier", "Print ESI system hierarchy");
40 CLI::App *telemetrySub =
41 cli.add_subcommand("telemetry", "Print ESI system telemetry information");
42
43 if (int rc = cli.esiParse(argc, argv))
44 return rc;
45 if (!cli.get_help_ptr()->empty())
46 return 0;
47
48 Context &ctxt = cli.getContext();
49 try {
50 std::unique_ptr<AcceleratorConnection> acc = cli.connect();
51 const auto &info = *acc->getService<services::SysInfo>();
52
53 if (*versionSub)
54 std::cout << info.getEsiVersion() << std::endl;
55 else if (*infoSub)
56 printInfo(std::cout, *acc);
57 else if (*hierSub)
58 printHier(std::cout, *acc);
59 else if (*telemetrySub)
60 printTelemetry(std::cout, *acc);
61 return 0;
62 } catch (std::exception &e) {
63 ctxt.getLogger().error("esiquery", e.what());
64 return -1;
65 }
66}
67
68void printInfo(std::ostream &os, AcceleratorConnection &acc) {
69 std::string jsonManifest =
70 acc.getService<services::SysInfo>()->getJsonManifest();
71 Manifest m(acc.getCtxt(), jsonManifest);
72 os << "API version: " << m.getApiVersion() << std::endl << std::endl;
73 os << "********************************" << std::endl;
74 os << "* Module information" << std::endl;
75 os << "********************************" << std::endl;
76 os << std::endl;
77 for (ModuleInfo mod : m.getModuleInfos())
78 os << "- " << mod;
79
80 os << std::endl;
81 os << "********************************" << std::endl;
82 os << "* Type table" << std::endl;
83 os << "********************************" << std::endl;
84 os << std::endl;
85 size_t i = 0;
86 for (const Type *t : m.getTypeTable())
87 os << " " << i++ << ": " << t->getID() << std::endl;
88}
89
90void printPort(std::ostream &os, const BundlePort &port,
91 std::string indent = "") {
92 os << indent << " " << port.getID() << ":";
93 if (auto svcPort = dynamic_cast<const services::ServicePort *>(&port))
94 if (auto svcPortStr = svcPort->toString()) {
95 os << " " << *svcPortStr << std::endl;
96 return;
97 }
98 os << std::endl;
99 for (const auto &[name, chan] : port.getChannels())
100 os << indent << " " << name << ": " << chan.getType()->getID()
101 << std::endl;
102}
103
104void printInstance(std::ostream &os, const HWModule *d,
105 std::string indent = "") {
106 os << indent << "* Instance:";
107 if (auto inst = dynamic_cast<const Instance *>(d))
108 os << inst->getID() << std::endl;
109 else
110 os << "top" << std::endl;
111 os << indent << "* Ports:" << std::endl;
112 for (const BundlePort &port : d->getPortsOrdered())
113 printPort(os, port, indent + " ");
114 std::vector<const Instance *> children = d->getChildrenOrdered();
115 if (!children.empty()) {
116 os << indent << "* Children:" << std::endl;
117 for (const Instance *child : d->getChildrenOrdered())
118 printInstance(os, child, indent + " ");
119 }
120 os << std::endl;
121}
122
123void printHier(std::ostream &os, AcceleratorConnection &acc) {
124 Manifest manifest(acc.getCtxt(),
126 Accelerator *design = manifest.buildAccelerator(acc);
127 os << "********************************" << std::endl;
128 os << "* Design hierarchy" << std::endl;
129 os << "********************************" << std::endl;
130 os << std::endl;
131 printInstance(os, design, /*indent=*/"");
132}
133
134void printTelemetry(std::ostream &os, AcceleratorConnection &acc) {
135 Manifest manifest(acc.getCtxt(),
137 auto accel = manifest.buildAccelerator(acc);
138 acc.getServiceThread()->addPoll(*accel);
139
140 auto telemetry = acc.getService<services::TelemetryService>();
141 if (!telemetry) {
142 os << "No telemetry service found" << std::endl;
143 return;
144 }
145 os << "********************************" << std::endl;
146 os << "* Telemetry" << std::endl;
147 os << "********************************" << std::endl;
148 os << std::endl;
149
150 const std::map<AppIDPath, services::TelemetryService::Telemetry *>
151 &telemetryPorts = telemetry->getTelemetryPorts();
152 for (const auto &[id, port] : telemetryPorts) {
153 port->connect();
154 os << id << ": ";
155 os.flush();
156 uint64_t value = *port->read().get().as<uint64_t>();
157 os << value << std::endl;
158 }
159}
Abstract class representing a connection to an accelerator.
Definition Accelerator.h:79
ServiceClass * getService(AppIDPath id={}, std::string implName={}, ServiceImplDetails details={}, HWClientDetails clients={})
Get a typed reference to a particular service type.
Context & getCtxt() const
Definition Accelerator.h:83
AcceleratorServiceThread * getServiceThread()
Return a pointer to the accelerator 'service' thread (or threads).
void addPoll(HWModule &module)
Poll this module.
Top level accelerator class.
Definition Accelerator.h:60
Services provide connections to 'bundles' – collections of named, unidirectional communication channe...
Definition Ports.h:226
const PortMap & getChannels() const
Definition Ports.h:247
AppID getID() const
Get the ID of the port.
Definition Ports.h:239
Common options and code for ESI runtime tools.
Definition CLI.h:29
Context & getContext()
Get the context.
Definition CLI.h:63
std::unique_ptr< AcceleratorConnection > connect()
Connect to the accelerator using the specified backend and connection.
Definition CLI.h:58
int esiParse(int argc, const char **argv)
Run the parser.
Definition CLI.h:46
AcceleratorConnections, Accelerators, and Manifests must all share a context.
Definition Context.h:31
Represents either the top level or an instance of a hardware module.
Definition Design.h:47
std::vector< std::reference_wrapper< BundlePort > > getPortsOrdered() const
Get the module's ports in a deterministic order.
Definition Design.h:69
std::vector< const Instance * > getChildrenOrdered() const
Get a vector of the module's children in a deterministic order.
Definition Design.h:60
Subclass of HWModule which represents a submodule instance.
Definition Design.h:107
Class to parse a manifest.
Definition Manifest.h:39
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.
Definition Types.h:27
Add a custom interface to a service client at a particular point in the design hierarchy.
Definition Services.h:36
Information about the Accelerator system.
Definition Services.h:100
virtual std::string getJsonManifest() const
Return the JSON-formatted system manifest.
Definition Services.cpp:40
Service for retrieving telemetry data from the accelerator.
Definition Services.h:341
const std::map< AppIDPath, Telemetry * > & getTelemetryPorts()
Definition Services.h:376
void printHier(std::ostream &os, AcceleratorConnection &acc)
Definition esiquery.cpp:123
void printTelemetry(std::ostream &os, AcceleratorConnection &acc)
Definition esiquery.cpp:134
void printInfo(std::ostream &os, AcceleratorConnection &acc)
Definition esiquery.cpp:68
void printInstance(std::ostream &os, const HWModule *d, std::string indent="")
Definition esiquery.cpp:104
int main(int argc, const char *argv[])
Definition esiquery.cpp:31
void printPort(std::ostream &os, const BundlePort &port, std::string indent="")
Definition esiquery.cpp:90
Definition esi.py:1