CIRCT  19.0.0git
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 
13 from typing import Dict, Optional
14 
15 from .types import BundlePort
16 from . import esiCppAccel as cpp
17 
18 # Global context for the C++ side.
19 ctxt = cpp.Context()
20 
21 
23  """A connection to an ESI accelerator."""
24 
25  def __init__(self, platform: str, connection_str: str):
26  self.cpp_accelcpp_accel = cpp.AcceleratorConnection(ctxt, platform, connection_str)
27 
28  def manifest(self) -> cpp.Manifest:
29  """Get and parse the accelerator manifest."""
30  return cpp.Manifest(ctxt, self.cpp_accelcpp_accel.sysinfo().json_manifest())
31 
32  def sysinfo(self) -> cpp.SysInfo:
33  return self.cpp_accelcpp_accel.sysinfo()
34 
35  def build_accelerator(self) -> "Accelerator":
36  return Accelerator(self.manifestmanifest().build_accelerator(self.cpp_accelcpp_accel))
37 
38  def get_service_mmio(self) -> cpp.MMIO:
39  return self.cpp_accelcpp_accel.get_service_mmio()
40 
41 
42 class HWModule:
43  """Represents either the top level or an instance of a hardware module."""
44 
45  def __init__(self, parent: Optional["HWModule"], cpp_hwmodule: cpp.HWModule):
46  self.parentparent = parent
47  self.cpp_hwmodulecpp_hwmodule = cpp_hwmodule
48 
49  @property
50  def children(self) -> Dict[cpp.AppID, "Instance"]:
51  return {
52  name: Instance(self, inst)
53  for name, inst in self.cpp_hwmodulecpp_hwmodule.children.items()
54  }
55 
56  @property
57  def ports(self) -> Dict[cpp.AppID, BundlePort]:
58  return {
59  name: BundlePort(self, port)
60  for name, port in self.cpp_hwmodulecpp_hwmodule.ports.items()
61  }
62 
63 
65  """Subclass of `HWModule` which represents a submodule instance. Adds an
66  AppID, which the top level doesn't have or need."""
67 
68  def __init__(self, parent: Optional["HWModule"], cpp_instance: cpp.Instance):
69  super().__init__(parent, cpp_instance)
70  self.cpp_hwmodulecpp_hwmodule: cpp.Instance = cpp_instance
71 
72  @property
73  def id(self) -> cpp.AppID:
74  return self.cpp_hwmodulecpp_hwmodule.id
75 
76 
78  """Root of the accelerator design hierarchy."""
79 
80  def __init__(self, cpp_accelerator: cpp.Accelerator):
81  super().__init__(None, cpp_accelerator)
82  self.cpp_hwmodulecpp_hwmodulecpp_hwmodule = cpp_accelerator
def __init__(self, str platform, str connection_str)
Definition: accelerator.py:25
def __init__(self, cpp.Accelerator cpp_accelerator)
Definition: accelerator.py:80
Dict[cpp.AppID, BundlePort] ports(self)
Definition: accelerator.py:57
Dict[cpp.AppID, "Instance"] children(self)
Definition: accelerator.py:50
def __init__(self, Optional["HWModule"] parent, cpp.HWModule cpp_hwmodule)
Definition: accelerator.py:45
def __init__(self, Optional["HWModule"] parent, cpp.Instance cpp_instance)
Definition: accelerator.py:68