CIRCT 21.0.0git
Loading...
Searching...
No Matches
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);
29
30int main(int argc, const char *argv[]) {
31 CliParser cli("esiquery");
32 cli.description("Query an ESI system for information from the manifest.");
33
34 CLI::App *versionSub =
35 cli.add_subcommand("version", "Print ESI system version");
36 CLI::App *infoSub =
37 cli.add_subcommand("info", "Print ESI system information");
38 CLI::App *hierSub = cli.add_subcommand("hier", "Print ESI system hierarchy");
39
40 if (int rc = cli.esiParse(argc, argv))
41 return rc;
42 if (!cli.get_help_ptr()->empty())
43 return 0;
44
45 Context &ctxt = cli.getContext();
46 try {
47 std::unique_ptr<AcceleratorConnection> acc = cli.connect();
48 const auto &info = *acc->getService<services::SysInfo>();
49
50 if (*versionSub)
51 std::cout << info.getEsiVersion() << std::endl;
52 else if (*infoSub)
53 printInfo(std::cout, *acc);
54 else if (*hierSub)
55 printHier(std::cout, *acc);
56 return 0;
57 } catch (std::exception &e) {
58 ctxt.getLogger().error("esiquery", e.what());
59 return -1;
60 }
61}
62
63void printInfo(std::ostream &os, AcceleratorConnection &acc) {
64 std::string jsonManifest =
65 acc.getService<services::SysInfo>()->getJsonManifest();
66 Manifest m(acc.getCtxt(), jsonManifest);
67 os << "API version: " << m.getApiVersion() << std::endl << std::endl;
68 os << "********************************" << std::endl;
69 os << "* Module information" << std::endl;
70 os << "********************************" << std::endl;
71 os << std::endl;
72 for (ModuleInfo mod : m.getModuleInfos())
73 os << "- " << mod;
74
75 os << std::endl;
76 os << "********************************" << std::endl;
77 os << "* Type table" << std::endl;
78 os << "********************************" << std::endl;
79 os << std::endl;
80 size_t i = 0;
81 for (const Type *t : m.getTypeTable())
82 os << " " << i++ << ": " << t->getID() << std::endl;
83}
84
85void printPort(std::ostream &os, const BundlePort &port,
86 std::string indent = "") {
87 os << indent << " " << port.getID() << ":";
88 if (auto svcPort = dynamic_cast<const services::ServicePort *>(&port))
89 if (auto svcPortStr = svcPort->toString()) {
90 os << " " << *svcPortStr << std::endl;
91 return;
92 }
93 os << std::endl;
94 for (const auto &[name, chan] : port.getChannels())
95 os << indent << " " << name << ": " << chan.getType()->getID()
96 << std::endl;
97}
98
99void printInstance(std::ostream &os, const HWModule *d,
100 std::string indent = "") {
101 os << indent << "* Instance:";
102 if (auto inst = dynamic_cast<const Instance *>(d))
103 os << inst->getID() << std::endl;
104 else
105 os << "top" << std::endl;
106 os << indent << "* Ports:" << std::endl;
107 for (const BundlePort &port : d->getPortsOrdered())
108 printPort(os, port, indent + " ");
109 std::vector<const Instance *> children = d->getChildrenOrdered();
110 if (!children.empty()) {
111 os << indent << "* Children:" << std::endl;
112 for (const Instance *child : d->getChildrenOrdered())
113 printInstance(os, child, indent + " ");
114 }
115 os << std::endl;
116}
117
118void printHier(std::ostream &os, AcceleratorConnection &acc) {
119 Manifest manifest(acc.getCtxt(),
121 Accelerator *design = manifest.buildAccelerator(acc);
122 os << "********************************" << std::endl;
123 os << "* Design hierarchy" << std::endl;
124 os << "********************************" << std::endl;
125 os << std::endl;
126 printInstance(os, design);
127}
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
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:58
std::unique_ptr< AcceleratorConnection > connect()
Connect to the accelerator using the specified backend and connection.
Definition CLI.h:53
int esiParse(int argc, const char **argv)
Run the parser.
Definition CLI.h:43
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
void printHier(std::ostream &os, AcceleratorConnection &acc)
Definition esiquery.cpp:118
void printInfo(std::ostream &os, AcceleratorConnection &acc)
Definition esiquery.cpp:63
void printInstance(std::ostream &os, const HWModule *d, std::string indent="")
Definition esiquery.cpp:99
int main(int argc, const char *argv[])
Definition esiquery.cpp:30
void printPort(std::ostream &os, const BundlePort &port, std::string indent="")
Definition esiquery.cpp:85
Definition esi.py:1