Beispiel #1
0
def test_generator_interface_basic():
    TYPES = (int, str, float,)
    N = 100
    gold = {}
    interface = GeneratorInterface()
    for _ in range(N):
        name = None
        while name is None or name in gold:
            name = generate_random_string(10)
        type_ = random.choice(TYPES)
        default = generate_random(type_)
        assert isinstance(default, type_)
        gold[name] = (type_, default,)
        interface.register(name, type_, default)

    assert interface.params == gold
Beispiel #2
0
def test_generator_interface_overwrite():
    interface = GeneratorInterface()
    interface.register("foo", int, 10)
    interface.register("bar", str, "hello")
    assert interface.params == {
        "foo": (int, 10,),
        "bar": (str, "hello",)
    }
    try:
        interface.register("foo", str, "foo!")
    except ValueError as e:
        assert e.__str__() == "param foo already registered"
Beispiel #3
0
from common.genesis_wrapper import GenesisWrapper, default_type_map
from common.generator_interface import GeneratorInterface


"""
Defines the memory_core using genesis2.

`data_width`: width of an entry in the memory
`data_depth`: number of entries in the memory

Example usage:
    >>> memory_core = memory_core_wrapper.generator()(
            data_width=16, data_depth=1024)
"""
interface = GeneratorInterface()\
    .register("data_width", int, 16)\
    .register("data_depth", int, 1024)

memory_core_wrapper = GenesisWrapper(
    interface, "memory_core", ["memory_core/genesis/input_sr.vp",
                               "memory_core/genesis/output_sr.vp",
                               "memory_core/genesis/linebuffer_control.vp",
                               "memory_core/genesis/fifo_control.vp",
                               "memory_core/genesis/mem.vp",
                               "memory_core/genesis/memory_core.vp"],
    type_map={"clk_in": m.In(m.Clock),
              "reset": m.In(m.AsyncReset),
              "config_en": m.In(m.Enable)})

param_mapping = {"data_width": "dwidth", "data_depth": "ddepth"}
Beispiel #4
0
from common.genesis_wrapper import GenesisWrapper, default_type_map
from common.generator_interface import GeneratorInterface


interface = GeneratorInterface()\
    .register("width", int, 16)\
    .register("num_tracks", int, 10)

simple_cb_wrapper = GenesisWrapper(
    interface,
    "simple_cb",
    ["simple_cb/genesis/simple_cb.vp"],
    type_map=default_type_map)

if __name__ == "__main__":
    # These functions are unit tested directly, so no need to cover them
    simple_cb_wrapper.main()  # pragma: no cover
Beispiel #5
0
Default parameters taken from
https://github.com/StanfordAHA/CGRAGenerator/blob/master/hardware/generator_z/top/top.vp#L113-L136
"""
interface = GeneratorInterface()\
    .register("reg_inputs", int, 1)\
    .register("reg_out", int, 0)\
    .register("use_add", int, 1)\
    .register("use_cntr", int, 0)\
    .register("use_bool", int, 1)\
    .register("use_shift", int, 1)\
    .register("mult_mode", int, 1)\
    .register("use_div", int, 0)\
    .register("is_msb", int, 0)\
    .register("en_double", int, 0)\
    .register("en_opt", int, 1)\
    .register("en_trick", int, 0)\
    .register("use_abs", int, 1)\
    .register("use_max_min", int, 1)\
    .register("use_relu", int, 0)\
    .register("get_carry", int, 1)\
    .register("debug", int, 0)\
    .register("use_flip", int, 0)\
    .register("use_acc", int, 1)\
    .register("en_ovfl", int, 1)\
    .register("en_debug", int, 1)\
    .register("lut_inps", int, 3)\
    .register("reg_cnt", int, 1)

type_map = {
    "clk": magma.In(magma.Clock),
    "rst_n": magma.In(magma.AsyncReset),
Beispiel #6
0
import pytest
import inspect
import random
import magma as m
from common.genesis_wrapper import GenesisWrapper
from common.generator_interface import GeneratorInterface

TOP = "test_run_genesis"
INFILES = ["test_common/test_run_genesis.vp"]
PARAMS = {
    "width": 16,
}
INTERFACE = GeneratorInterface()\
    .register("width", int, 32)
WRAPPER = GenesisWrapper(INTERFACE, TOP, INFILES)


@pytest.mark.parametrize("mode", ["declare", "define"])
def test_generator(mode):
    def _foo(*args, **kwargs):
        pass

    generator = WRAPPER.generator(mode=mode)
    assert inspect.isfunction(generator)
    assert inspect.signature(generator) == inspect.signature(_foo)
    # Check that passing non-kwargs fails.
    try:
        generator(0)
        assert False
    except NotImplementedError as e:
        pass
Beispiel #7
0
from common.genesis_wrapper import GenesisWrapper, default_type_map
from common.generator_interface import GeneratorInterface
import magma as m


interface = GeneratorInterface()\
    .register("width", int, 16)\
    .register("num_tracks", int, 10)\
    .register("feedthrough_outputs", str, "1" * 10)\
    .register("has_constant", int, 0)\
    .register("default_value", int, 0)

cb_wrapper = GenesisWrapper(interface, "cb", ["cb/genesis/cb.vp"],
                            type_map=default_type_map)

"""
This program generates the verilog for the connect box and parses it into a
Magma circuit. The circuit declaration is printed at the end of the program.
"""
if __name__ == "__main__":
    # These functions are unit tested directly, so no need to cover them
    cb_wrapper.main()  # pragma: no cover
Beispiel #8
0
import magma
from common.genesis_wrapper import GenesisWrapper
from common.generator_interface import GeneratorInterface


interface = GeneratorInterface()\
    .register("cfg_bus_width", int, 32)\
    .register("cfg_addr_width", int, 32)\
    .register("cfg_op_width", int, 5)

type_map = {
    "clk_in": magma.In(magma.Clock),
    "clk_out": magma.Out(magma.Clock),
    "tck": magma.In(magma.Clock),
    "reset_in": magma.In(magma.AsyncReset),
    "reset_out": magma.Out(magma.AsyncReset),
    "trst_n": magma.In(magma.AsyncReset),
}
gc_wrapper = GenesisWrapper(
    interface,
    "global_controller", [
        "global_controller/genesis/global_controller.vp",
        "global_controller/genesis/jtag.vp",
        "global_controller/genesis/tap.vp",
        "global_controller/genesis/flop.vp",
        "global_controller/genesis/cfg_and_dbg.vp"
    ],
    type_map=type_map)

if __name__ == "__main__":
    """
Beispiel #9
0
`config_addr_width`: Number of bits in config address
`num_ios_per_group`: Number of io1bit tiles in each io_group
`num_groups_per_side`: Number of groups on each of the 4 sides
`tile_id_offset`: ID we begin counting from to assign
                  ids to each io1bit tile. Will probably get
                  rid of this once we develop configuration manager

Example usage:
    >>> pad_frame = pad_frame_wrapper.generator()(
            config_data_width=32, config_addr_width=32,
            num_ios_per_group=16, num_groups_per_side=1,
            tile_id_offset=400)
"""
interface = GeneratorInterface()\
    .register("num_ios_per_group", int, 16)\
    .register("num_groups_per_side", int, 1)\
    .register("config_addr_width", int, 32)\
    .register("config_data_width", int, 32)\
    .register("tile_id_offset", int, 400)

pad_frame_wrapper = GenesisWrapper(interface, "pad_frame", [
    "pad_frame/genesis/pad_frame.vp", "pad_frame/genesis/io_group.vp",
    "pad_frame/genesis/io1bit.vp", "pad_frame/genesis/fixed_io.vp"
])

if __name__ == "__main__":
    """
    This program generates the verilog for the pad frame and parses it into a
    Magma circuit. The circuit declaration is printed at the end of the
    program.
    """
    # These functions are unit tested directly, so no need to cover them