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()
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()
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)
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)
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()
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)
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
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()
def _select(self, defn: m.DefineCircuitKind): return only(find_instances_name_equals(defn, self.inst))
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