elasticai.creator.ir2verilog#

Package Contents#

Classes#

Ir2Verilog

Shape

PluginLoader

PluginLoader for Ir2Verilog passes.

PluginLoader

PluginLoader for Ir2Verilog passes.

Node

Extending ir.core.Node to an hdl specific node.

Edge

TemplateDirector

Director for building verilog templates.

VerilogTemplate

Functions#

Data#

API#

class elasticai.creator.ir2verilog.Ir2Verilog[source]#

Initialization

__call__(root: elasticai.creator.hdl_ir.DataGraph, registry: elasticai.creator.hdl_ir.Registry, default_root_name='root') collections.abc.Iterable[elasticai.creator.ir2verilog.ir2verilog.Code][source]#
register_static(name: str | None, fn: collections.abc.Callable[[], str]) collections.abc.Callable[[], str][source]#
register(name: str | None, fn: elasticai.creator.hdl_ir.TypeHandler) elasticai.creator.hdl_ir.TypeHandler[source]#
override(name: str | None, fn: elasticai.creator.hdl_ir.TypeHandler) elasticai.creator.hdl_ir.TypeHandler[source]#
elasticai.creator.ir2verilog.type_handler(name: str | None, fn: elasticai.creator.hdl_ir.NonIterableTypeHandler) elasticai.creator.hdl_ir.NonIterableTypeHandler[source]#
elasticai.creator.ir2verilog.type_handler_iterable(name: str | None, fn: elasticai.creator.hdl_ir.TypeHandler) elasticai.creator.hdl_ir.TypeHandler[source]#
class elasticai.creator.ir2verilog.Shape(*values: int)[source]#

Initialization

values are interpreted as one of the following:

  • width

  • depth, width

  • depth, width, height

Usually width is kernel_size, depth is channels

classmethod from_tuple(values: elasticai.creator.hdl_ir.ShapeTuple | list[int]) elasticai.creator.hdl_ir.Shape[source]#
to_tuple() elasticai.creator.hdl_ir.ShapeTuple[source]#
to_list() list[int][source]#
__getitem__(item)[source]#
size() int[source]#
ndim() int[source]#
property depth: int#
__eq__(other)[source]#
property width: int#
property height: int#
__repr__() str[source]#
elasticai.creator.ir2verilog.factory#

‘IrFactory(…)’

class elasticai.creator.ir2verilog.PluginLoader(lowering: elasticai.creator.ir2verilog.ir2verilog.Ir2Verilog)[source]#

Bases: elasticai.creator.plugin.PluginLoaderBase

PluginLoader for Ir2Verilog passes.

Initialization

filter_plugin_dicts(plugins: collections.abc.Iterable[dict[str, Any]]) collections.abc.Iterable[dict[str, Any]][source]#
load_symbol(symbol: elasticai.creator.ir2verilog.ir2verilog.PluginSymbol) None[source]#
get_symbols(specs: collections.abc.Iterable[elasticai.creator.ir2verilog.ir2verilog.PluginSpec]) collections.abc.Iterable[elasticai.creator.ir2verilog.ir2verilog.PluginSymbol][source]#
class elasticai.creator.ir2verilog.PluginLoader(lowering: elasticai.creator.ir2verilog.ir2verilog.Ir2Verilog)[source]#

Bases: elasticai.creator.plugin.PluginLoaderBase

PluginLoader for Ir2Verilog passes.

Initialization

filter_plugin_dicts(plugins: collections.abc.Iterable[dict[str, Any]]) collections.abc.Iterable[dict[str, Any]][source]#
load_symbol(symbol: elasticai.creator.ir2verilog.ir2verilog.PluginSymbol) None[source]#
get_symbols(specs: collections.abc.Iterable[elasticai.creator.ir2verilog.ir2verilog.PluginSpec]) collections.abc.Iterable[elasticai.creator.ir2verilog.ir2verilog.PluginSymbol][source]#
elasticai.creator.ir2verilog.factory#

‘IrFactory(…)’

class elasticai.creator.ir2verilog.Node[source]#

Bases: elasticai.creator.ir.ir_v2.Node, typing.Protocol

Extending ir.core.Node to an hdl specific node.

This node contains all knowledge that we need to create and use an instance of an hdl component. However, this becomes a little bit complicated because vhdl differentiates between

Attributes:

implementation:: The name of the implementation, e.g., entity name in vhdl or module name for verilog, will be used to derive the architecture name. E.g., if the implementation is "adder", we will instantiate the entity work.adder(rtl). CAUTION: This behaviour is subject to change. Future versions might require the full entity name

property implementation: str#
property input_shape: elasticai.creator.hdl_ir.Shape#
property output_shape: elasticai.creator.hdl_ir.Shape#
class elasticai.creator.ir2verilog.Edge[source]#

Bases: elasticai.creator.ir.ir_v2.Edge, typing.Protocol

property src_dst_indices: tuple[tuple[int | str, int | str], ...]#
elasticai.creator.ir2verilog.Code: TypeAlias#

None

class elasticai.creator.ir2verilog.TemplateDirector[source]#

Director for building verilog templates.

Most methods correspond to verilog language constructs. Building the final template can be expensive! Typically you only want to do this once. E.g.:

from string import Template
from elasticai.creator.ir2verilog import type_handler, Code, TemplateDirector, Implementation

class _ExplodingTemplate:
    def substitute(self, params):
        raise RuntimeError("Template not initialized!")

_template = None

@type_handler
def fir_filter(impl: Implementation) -> Code:
    global _template
    if _template is None:
        _template = (
            TemplateDirector()
            .define_scoped_switch("USE_EXT_WEIGHTS", False)
            .define_scoped_switch("USE_EXT_MAC", False)
            .parameter("BITWIDTH")
            .parameter("LENGTH")
            .localparam("FILT_COEFFS")
            .localparam("NUM_MULT_UNIT")
            .add_module_name()
            .set_prototype(res.read_text(package_path, "verilog/filter_fir_full.v"))
            .build()
        )
    return _template.substitute(impl.attributes)

Initialization

reset() Self[source]#
set_prototype(prototype: str) Self[source]#
parameter(name: str) Self[source]#
localparam(name: str) Self[source]#
replace_module_of_instance(module_name: str, new_name: str) Self[source]#
replace_instance_name(module_name: str, new_name: str) Self[source]#
define_scoped_switch(name: str, default: bool) Self[source]#

Add a switch for a define that is scoped to the module name.

The switch will be prefixed with the value that users provide as module_name to the render call.

Parameters:
  • name – String with name of the switch/define name

  • default – Setting switch for defining output state (True=set, False=undefine)

add_module_name() Self[source]#
build() elasticai.creator.ir2verilog.templates.VerilogTemplate[source]#
class elasticai.creator.ir2verilog.VerilogTemplate(template: string.Template, defines: dict[str, bool], module_name: dict[str, str])[source]#

Initialization

substitute(params: Mapping[str, str | bool]) str[source]#