예제 #1
0
def test_internal_signal_path_nested():
    # Validate internal path through adder in _Accum.
    accum_inst = only(find_instances_type(_Top, lambda t: t is _Accum))
    add_inst = only(find_instances_name_substring(_Accum, "add"))
    scope = Scope(_Top, [accum_inst])
    assert scope.validate()
    path = BitSignalPath([
        ScopedBit(add_inst.I0[0], scope),
        ScopedBit(add_inst.O[0], scope),
    ])
    assert path.validate()
예제 #2
0
def test_top_signal_path():
    # Validate top-level path:
    #   I0[0] -> and.I0[0] -> and.O[0] -> or.I1[0] -> or.O[0] -> O[0]
    and_inst = only(find_instances_name_substring(_Top, "and"))
    or_inst = only(find_instances_name_substring(_Top, "or"))
    scope = Scope(_Top)
    assert scope.validate()
    path = BitSignalPath([
        ScopedBit(_Top.I0[0], scope),
        ScopedBit(and_inst.I0[0], scope),
        ScopedBit(and_inst.O[0], scope),
        ScopedBit(or_inst.I1[0], scope),
        ScopedBit(or_inst.O[0], scope),
        ScopedBit(_Top.O[0], scope)
    ])
    path.validate().throw()
예제 #3
0
def test_bit_binop():
    class _Foo(m.Circuit):  # needed to instance a circuit
        m.Bit() | m.Bit()

    Or = type(only(_Foo.instances))
    got = get_primitive_drivers(Or.O)
    print(got)
예제 #4
0
def test_register_to_register():
    ckt = _Registered
    reg0 = only(find_instances_name_equals(ckt, "reg0"))
    reg1 = only(find_instances_name_equals(ckt, "reg1"))
    scope = Scope(ckt)
    through_lists = ((ScopedBit(reg0.O, scope),), (ScopedBit(reg1.I, scope),))
    q = PartialExtractQuery(through_lists=through_lists)
    assert not query_is_empty(q)
    ckt_partial = extract_partial(ckt, q, name="register_to_regsiter_partial")

    with tempfile.TemporaryDirectory() as directory:
        basename = f"{directory}/{ckt_partial.name}"
        m.compile(basename, ckt_partial, inline=True)
        gold = "golds/partial_extract_register_to_regsiter.v"
        assert m.testing.utils.check_files_equal(
            __file__, f"{basename}.v", gold)
예제 #5
0
def test_internal_signal_path():
    # Validate internal path through and.
    and_inst = only(find_instances_name_substring(_Top, "and"))
    scope = Scope(_Top)
    assert scope.validate()
    path = BitSignalPath([
        ScopedBit(and_inst.I0[0], scope),
        ScopedBit(and_inst.O[0], scope),
    ])
    assert path.validate()
    # Validate internal path through or.
    or_inst = only(find_instances_name_substring(_Top, "or"))
    path = BitSignalPath([
        ScopedBit(or_inst.I1[0], scope),
        ScopedBit(or_inst.O[0], scope),
    ])
    assert path.validate()
예제 #6
0
def test_mux(T, height):
    Mux = m.Mux(T=T, height=height)
    Mux = type(only(Mux.instances))
    width = T.flat_length()
    assert isinstance(Mux.I.data, m.Array[height, m.Array[width, m.Bit]])
    index = random.randrange(0, width)
    expected = [Mux.I.data[i][index] for i in range(height)]
    expected += list(Mux.I.sel)
    got = get_primitive_drivers(Mux.O[index])
    _check_unordered_set_identical(expected, got)
예제 #7
0
 def find_node(self, bit: m.Bit) -> BitPortNode:
     node_to_bit = {n: b for n, b in self._node_to_bit.items() if b is bit}
     n, b = only(node_to_bit.items())
     assert b is bit
     return n
예제 #8
0
def test_scope():
    accum = only(find_instances_type(_Top, lambda t: t is _Accum))
    add = only(find_instances_name_substring(_Accum, "add"))
    scope = Scope(_Top, [accum, add])
    assert scope.validate()
예제 #9
0
 def _select(self, defn: m.DefineCircuitKind):
     return only(find_instances_name_equals(defn, self.inst))
예제 #10
0
from pdq.common.algorithms import only
from pdq.circuit_tools.circuit_utils import find_instances_name_equals


@contextlib.contextmanager
def _pushd(new_dir):
    prev_dir = os.getcwd()
    prev_path = sys.path.copy()
    os.chdir(new_dir)
    sys.path.append(".")
    try:
        yield
    finally:
        os.chdir(prev_dir)
        sys.path = prev_path


with _pushd("garnet"):
    with open("garnet.py") as _f:
        exec(_f.read())
        _kwargs = dict(add_pd=False, interconnect_only=True, standalone=True)
        _gen = Garnet(1, 1, **_kwargs)
    _Garnet = _gen.circuit()
_Interconnect = type(only(_Garnet.instances))
_Tile_PE = type(only(find_instances_name_equals(_Interconnect,
                                                "Tile_X00_Y00")))

# Make component(s) public.
Tile_PE = _Tile_PE