Debian Codegraph @

legacy/generic/simple.py

raw symbols SCIP
1 import sys
2 import os
3 from itertools import chain
4 import re
5 import code
6 import pickle
7 import importlib.resources
8 sys.path.append(os.path.join(sys.path[0], '..'))
9 from apycula import chipdb
10 from apycula.wirenames import wirenames
11
12 device = os.getenv("DEVICE")
13 if not device:
14 raise Exception("DEVICE not set")
15
16 with importlib.resources.open_binary("apycula", f"{device}.pickle") as f:
17 db = pickle.load(f)
18
19 timing_class = "C6/I5" # TODO parameterize
20 timing = db.timing[timing_class]
21
22 def addWire(row, col, wire):
23 gname = chipdb.wire2global(row, col, db, wire)
24 #print("wire", gname)
25 try:
26 ctx.addWire(name=gname, type=wire, y=row, x=col)
27 except AssertionError:
28 pass
29 #print("duplicate wire")
30
31 belre = re.compile(r"(IOB|LUT|DFF|BANK|CFG)(\w*)")
32 for row, rowdata in enumerate(db.grid, 1):
33 for col, tile in enumerate(rowdata, 1):
34 # add wires
35 wires = set(chain(
36 tile.pips.keys(),
37 tile.clock_pips.keys(),
38 *tile.pips.values(),
39 *tile.clock_pips.values(),
40 ))
41 for wire in wires:
42 addWire(row, col, wire)
43 # add aliasses
44 # creat bels
45 #print(row, col, ttyp)
46 for name, bel in tile.bels.items():
47 typ, idx = belre.match(name).groups()
48 if typ == "DFF":
49 z = int(idx)
50 belname = f"R{row}C{col}_SLICE{z}"
51 clkname = f"R{row}C{col}_CLK{z//2}"
52 fname = f"R{row}C{col}_F{z}"
53 qname = f"R{row}C{col}_Q{z}"
54 #print("IOB", row, col, clkname, fname, qname)
55 ctx.addBel(name=belname, type="GENERIC_SLICE", loc=Loc(col, row, z), gb=False)
56 ctx.addBelInput(bel=belname, name="CLK", wire=clkname)
57 for k, n in [('A', 'I[0]'), ('B', 'I[1]'),
58 ('C', 'I[2]'), ('D', 'I[3]')]:
59 inpname = f"R{row}C{col}_{k}{z}"
60 ctx.addBelInput(bel=belname, name=n, wire=inpname)
61 ctx.addBelOutput(bel=belname, name="Q", wire=qname)
62 ctx.addBelOutput(bel=belname, name="F", wire=fname)
63
64 elif typ == "IOB":
65 z = ord(idx)-ord('A')
66 belname = f"R{row}C{col}_IOB{idx}"
67 inp = bel.portmap['I']
68 outp = bel.portmap['O']
69 oe = bel.portmap['OE']
70 iname = f"R{row}C{col}_{inp}"
71 oname = f"R{row}C{col}_{outp}"
72 oename = f"R{row}C{col}_{oe}"
73 #print("IOB", row, col, iname, oname, oename)
74 ctx.addBel(name=belname, type="GENERIC_IOB", loc=Loc(col, row, z), gb=False)
75 ctx.addBelInput(bel=belname, name="I", wire=iname)
76 ctx.addBelInput(bel=belname, name="EN", wire=oename)
77 ctx.addBelOutput(bel=belname, name="O", wire=oname)
78
79
80 wlens = {0: 'X0', 1: 'FX1', 2: 'X2', 8: 'X8'}
81 def wiredelay(wire):
82 m = re.match(r"[NESWX]+([0128])", wire)
83 if m:
84 wlen = int(m.groups()[0])
85 name = wlens.get(wlen)
86 return ctx.getDelayFromNS(max(timing['wire'][name]))
87 elif wire.startswith("UNK"):
88 return ctx.getDelayFromNS(max(timing['glbsrc']['PIO_CENT_PCLK']))
89 elif wire.startswith("SPINE"):
90 return ctx.getDelayFromNS(max(timing['glbsrc']['CENT_SPINE_PCLK']))
91 elif wire.startswith("GT"):
92 return ctx.getDelayFromNS(max(timing['glbsrc']['SPINE_TAP_PCLK']))
93 elif wire.startswith("GBO"):
94 return ctx.getDelayFromNS(max(timing['glbsrc']['TAP_BRANCH_PCLK']))
95 elif wire.startswith("GB"):
96 return ctx.getDelayFromNS(max(timing['glbsrc']['BRANCH_PCLK']))
97 else: # no known delay
98 return ctx.getDelayFromNS(0)
99
100
101
102 def addPip(row, col, srcname, destname):
103 gsrcname = chipdb.wire2global(row, col, db, srcname)
104 gdestname = chipdb.wire2global(row, col, db, destname)
105
106 pipname = f"R{row}C{col}_{srcname}_{destname}"
107 #print("pip", pipname, srcname, gsrcname, destname, gdestname)
108 try:
109 # delay is crude fudge from vendor critical path
110 ctx.addPip(
111 name=pipname, type=destname, srcWire=gsrcname, dstWire=gdestname,
112 delay=wiredelay(destname), loc=Loc(col, row, 0))
113 except IndexError:
114 pass
115 #print("Wire not found", gsrcname, gdestname)
116 except AssertionError:
117 pass
118 #print("Wire already exists", gsrcname, gdestname)
119
120 def addAlias(row, col, srcname, destname):
121 gsrcname = chipdb.wire2global(row, col, db, srcname)
122 gdestname = chipdb.wire2global(row, col, db, destname)
123
124 pipname = f"R{row}C{col}_{srcname}_{destname}"
125 #print("alias", pipname)
126 ctx.addPip(
127 name=pipname+"_ALIAS", type=destname, srcWire=gsrcname, dstWire=gdestname,
128 delay=ctx.getDelayFromNS(0), loc=Loc(col, row, 0))
129
130
131 for row, rowdata in enumerate(db.grid, 1):
132 for col, tile in enumerate(rowdata, 1):
133 for dest, srcs in tile.pips.items():
134 for src in srcs.keys():
135 addPip(row, col, src, dest)
136 for dest, srcs in tile.clock_pips.items():
137 for src in srcs.keys():
138 addPip(row, col, src, dest)
139 for dest, src in tile.aliases.items():
140 addAlias(row, col, src, dest)
141
142 for (row, col, pip), (srow, scol, spip) in db.aliases.items():
143 dest = f"R{row+1}C{col+1}_{pip}"
144 src = f"R{srow+1}C{scol+1}_{spip}"
145 name = f"{src}_{dest}_ALIAS"
146 ctx.addPip(
147 name=name, type=dest, srcWire=src, dstWire=dest,
148 delay=ctx.getDelayFromNS(0), loc=Loc(row+1, col+1, 0))
149
150 # too low numbers will result in slow routing iterations
151 # too high numbers will result in more iterations
152 ctx.setDelayScaling(0.1, 0.7)
153
154 #code.interact(local=locals())