CIRCT 22.0.0git
Loading...
Searching...
No Matches
accelerator.py
Go to the documentation of this file.
1# ===-----------------------------------------------------------------------===#
2# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3# See https://llvm.org/LICENSE.txt for license information.
4# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5# ===-----------------------------------------------------------------------===#
6#
7# The structure of the Python classes and hierarchy roughly mirrors the C++
8# side, but wraps the C++ objects. The wrapper classes sometimes add convenience
9# functionality and serve to return wrapped versions of the returned objects.
10#
11# ===-----------------------------------------------------------------------===#
12
13from typing import Dict, List, Optional
14
15from .types import BundlePort
16from . import esiCppAccel as cpp
17
18LogLevel = cpp.LogLevel
19
20
21class Context:
22 """A context for ESI accelerator connections. The underlying C++ context owns
23 everything assocated with it including types, accelerator connections, and
24 the accelerator facade/interface (aka Accelerator) itself. It must not be
25 garbage collected while any accelerators or connections that it owns are still
26 in use as they will be disconnected and destroyed when the context is
27 destroyed."""
28
29 _default: Optional["Context"] = None
30
31 def __init__(self, log_level: cpp.LogLevel = cpp.LogLevel.Warning):
32 self.cpp_ctxt = cpp.Context()
33 self.set_stdio_logger(log_level)
34
35 @staticmethod
36 def default() -> "Context":
37 if Context._default is None:
38 Context._default = Context()
39 return Context._default
40
41 def set_stdio_logger(self, level: cpp.LogLevel):
42 self.cpp_ctxt.set_stdio_logger(level)
43
44 def connect(self, platform: str,
45 connection_str: str) -> "AcceleratorConnection":
47 self, self.cpp_ctxt.connect(platform, connection_str))
48
49
51 """A connection to an ESI accelerator."""
52
53 def __init__(self, ctxt: Context, cpp_accel: cpp.AcceleratorConnection):
54 if not isinstance(ctxt, Context):
55 raise TypeError("ctxt must be a Context")
56 self.ctxt = ctxt
57 self.cpp_accel = cpp_accel
58
59 def manifest(self) -> cpp.Manifest:
60 """Get and parse the accelerator manifest."""
61 return cpp.Manifest(self.ctxt.cpp_ctxt,
62 self.cpp_accel.sysinfo().json_manifest())
63
64 def sysinfo(self) -> cpp.SysInfo:
65 return self.cpp_accel.sysinfo()
66
67 def build_accelerator(self) -> "Accelerator":
69
70 def get_service_mmio(self) -> cpp.MMIO:
71 return self.cpp_accel.get_service_mmio()
72
73 def get_service_hostmem(self) -> cpp.HostMem:
74 return self.cpp_accel.get_service_hostmem()
75
76 def get_accelerator(self) -> "Accelerator":
77 """
78 Return an accelerator that may be owned by this accelerator connection.
79 If no accelerator is owned, will throw.
80 """
82
83
84from .esiCppAccel import HostMemOptions
85
86
88 """Represents either the top level or an instance of a hardware module."""
89
90 def __init__(self, parent: Optional["HWModule"], cpp_hwmodule: cpp.HWModule):
91 self.parent = parent
92 self.cpp_hwmodule = cpp_hwmodule
93
94 @property
95 def children(self) -> Dict[cpp.AppID, "Instance"]:
96 return {
97 name: Instance(self, inst)
98 for name, inst in self.cpp_hwmodule.children.items()
99 }
100
101 @property
102 def ports(self) -> Dict[cpp.AppID, BundlePort]:
103 return {
104 name: BundlePort(self, port)
105 for name, port in self.cpp_hwmodule.ports.items()
106 }
107
108 @property
109 def services(self) -> List[cpp.AppID]:
110 return self.cpp_hwmodule.services
111
112
113MMIO = cpp.MMIO
114
115
117 """Subclass of `HWModule` which represents a submodule instance. Adds an
118 AppID, which the top level doesn't have or need."""
119
120 def __init__(self, parent: Optional["HWModule"], cpp_instance: cpp.Instance):
121 super().__init__(parent, cpp_instance)
122 self.cpp_hwmodule: cpp.Instance = cpp_instance
123
124 @property
125 def id(self) -> cpp.AppID:
126 return self.cpp_hwmodule.id
127
128
130 """Root of the accelerator design hierarchy."""
131
132 def __init__(self, cpp_accelerator: cpp.Accelerator):
133 super().__init__(None, cpp_accelerator)
134 self.cpp_hwmodulecpp_hwmodule = cpp_accelerator
__init__(self, Context ctxt, cpp.AcceleratorConnection cpp_accel)
__init__(self, cpp.Accelerator cpp_accelerator)
"AcceleratorConnection" connect(self, str platform, str connection_str)
__init__(self, cpp.LogLevel log_level=cpp.LogLevel.Warning)
set_stdio_logger(self, cpp.LogLevel level)
Dict[cpp.AppID, BundlePort] ports(self)
Dict[cpp.AppID, "Instance"] children(self)
__init__(self, Optional["HWModule"] parent, cpp.HWModule cpp_hwmodule)
List[cpp.AppID] services(self)
__init__(self, Optional["HWModule"] parent, cpp.Instance cpp_instance)