CIRCT 22.0.0git
Loading...
Searching...
No Matches
Design.h
Go to the documentation of this file.
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
39namespace esi {
40// Forward declarations.
41class Instance;
42namespace services {
43class Service;
44} // namespace services
45
46/// Represents either the top level or an instance of a hardware module.
47class HWModule {
48public:
49 HWModule(const HWModule &) = delete;
50 HWModule &operator=(const HWModule &) = delete;
51
52protected:
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
58public:
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
100protected:
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.
111class Instance : public HWModule {
112public:
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
126protected:
127 const AppID id;
128};
129
130} // namespace esi
131
132#endif // ESI_DESIGN_H
Services provide connections to 'bundles' – collections of named, unidirectional communication channe...
Definition Ports.h:433
Represents either the top level or an instance of a hardware module.
Definition Design.h:47
virtual ~HWModule()=default
HWModule & operator=(const HWModule &)=delete
const std::optional< ModuleInfo > info
Definition Design.h:101
std::vector< std::reference_wrapper< BundlePort > > getPortsOrdered() const
Get the module's ports in a deterministic order.
Definition Design.h:73
BundlePort * resolvePort(const AppIDPath &path, AppIDPath &lastLookup) const
Attempt to resolve a path to a port.
Definition Design.cpp:72
std::vector< const Instance * > getChildrenOrdered() const
Get a vector of the module's children in a deterministic order.
Definition Design.h:64
bool poll()
Master poll method.
Definition Design.cpp:50
const std::vector< std::unique_ptr< BundlePort > > ports
Definition Design.h:105
const std::vector< std::unique_ptr< Instance > > children
Definition Design.h:102
HWModule(const HWModule &)=delete
const std::vector< services::Service * > services
Definition Design.h:104
const std::map< AppID, Instance * > childIndex
Definition Design.h:103
const std::map< AppID, BundlePort & > portIndex
Definition Design.h:106
const HWModule * resolveInst(const AppIDPath &path, AppIDPath &lastLookup) const
Attempt to resolve a path to a module instance.
Definition Design.cpp:59
const std::map< AppID, BundlePort & > & getPorts() const
Access the module's ports by ID.
Definition Design.h:80
const std::map< AppID, Instance * > & getChildren() const
Access the module's children by ID.
Definition Design.h:71
const std::vector< services::Service * > & getServices() const
Access the services provided by this module.
Definition Design.h:82
std::optional< ModuleInfo > getInfo() const
Access the module's metadata, if any.
Definition Design.h:62
Subclass of HWModule which represents a submodule instance.
Definition Design.h:111
AppID getID() const
Get the instance's ID, which it will always have.
Definition Design.h:124
Instance(const Instance &)=delete
Instance()=delete
const AppID id
Definition Design.h:127
~Instance()=default
Instance(AppID id, std::optional< ModuleInfo > info, std::vector< std::unique_ptr< Instance > > children, std::vector< services::Service * > services, std::vector< std::unique_ptr< BundlePort > > &&ports)
Definition Design.h:116
Parent class of all APIs modeled as 'services'.
Definition Services.h:59
Definition esi.py:1