CIRCT 20.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 {
48protected:
49 HWModule(std::optional<ModuleInfo> info,
50 std::vector<std::unique_ptr<Instance>> children,
51 std::vector<services::Service *> services,
52 std::vector<std::unique_ptr<BundlePort>> &ports);
53
54public:
55 virtual ~HWModule() = default;
56
57 /// Access the module's metadata, if any.
58 std::optional<ModuleInfo> getInfo() const { return info; }
59 /// Get a vector of the module's children in a deterministic order.
60 std::vector<const Instance *> getChildrenOrdered() const {
61 std::vector<const Instance *> ret;
62 for (const auto &c : children)
63 ret.push_back(c.get());
64 return ret;
65 }
66 /// Access the module's children by ID.
67 const std::map<AppID, Instance *> &getChildren() const { return childIndex; }
68 /// Get the module's ports in a deterministic order.
69 std::vector<std::reference_wrapper<BundlePort>> getPortsOrdered() const {
70 std::vector<std::reference_wrapper<BundlePort>> ret;
71 for (const auto &p : ports)
72 ret.push_back(*p);
73 return ret;
74 }
75 /// Access the module's ports by ID.
76 const std::map<AppID, const BundlePort &> &getPorts() const {
77 return portIndex;
78 }
79 /// Access the services provided by this module.
80 const std::vector<services::Service *> &getServices() const {
81 return services;
82 }
83
84 /// Master poll method. Calls the `poll` method on all locally owned ports and
85 /// the master `poll` method on all of the children. Returns true if any of
86 /// the `poll` calls returns true.
87 bool poll();
88
89protected:
90 const std::optional<ModuleInfo> info;
91 const std::vector<std::unique_ptr<Instance>> children;
92 const std::map<AppID, Instance *> childIndex;
93 const std::vector<services::Service *> services;
94 const std::vector<std::unique_ptr<BundlePort>> ports;
95 const std::map<AppID, const BundlePort &> portIndex;
96};
97
98/// Subclass of `HWModule` which represents a submodule instance. Adds an AppID,
99/// which the top level doesn't have or need.
100class Instance : public HWModule {
101public:
102 Instance() = delete;
103 Instance(const Instance &) = delete;
104 ~Instance() = default;
105 Instance(AppID id, std::optional<ModuleInfo> info,
106 std::vector<std::unique_ptr<Instance>> children,
107 std::vector<services::Service *> services,
108 std::vector<std::unique_ptr<BundlePort>> &ports)
109 : HWModule(info, std::move(children), services, ports), id(id) {}
110
111 /// Get the instance's ID, which it will always have.
112 const AppID getID() const { return id; }
113
114protected:
115 const AppID id;
116};
117
118} // namespace esi
119
120#endif // ESI_DESIGN_H
Represents either the top level or an instance of a hardware module.
Definition Design.h:47
virtual ~HWModule()=default
const std::optional< ModuleInfo > info
Definition Design.h:90
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
bool poll()
Master poll method.
Definition Design.cpp:50
const std::map< AppID, const BundlePort & > & getPorts() const
Access the module's ports by ID.
Definition Design.h:76
const std::vector< std::unique_ptr< BundlePort > > ports
Definition Design.h:94
const std::vector< std::unique_ptr< Instance > > children
Definition Design.h:91
const std::vector< services::Service * > services
Definition Design.h:93
const std::map< AppID, const BundlePort & > portIndex
Definition Design.h:95
const std::map< AppID, Instance * > childIndex
Definition Design.h:92
const std::map< AppID, Instance * > & getChildren() const
Access the module's children by ID.
Definition Design.h:67
const std::vector< services::Service * > & getServices() const
Access the services provided by this module.
Definition Design.h:80
std::optional< ModuleInfo > getInfo() const
Access the module's metadata, if any.
Definition Design.h:58
Subclass of HWModule which represents a submodule instance.
Definition Design.h:100
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:105
Instance(const Instance &)=delete
Instance()=delete
const AppID getID() const
Get the instance's ID, which it will always have.
Definition Design.h:112
const AppID id
Definition Design.h:115
~Instance()=default
Parent class of all APIs modeled as 'services'.
Definition Services.h:45
Definition esi.py:1