Skip to content

Commit

Permalink
Initial subgraph approach debugged.
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Rothman <[email protected]>
  • Loading branch information
litghost committed Nov 4, 2020
1 parent 5aee4d0 commit f369ce6
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 13 deletions.
6 changes: 5 additions & 1 deletion minitests/graph_folding/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ ${WIRE_PATTERNS}: test_reduction.py ${DATABASE}
--database ${DATABASE} \
--wire_patterns ${WIRE_PATTERNS}

.PHONY: clean
.PHONY: clean database wire_patterns

database: ${DATABASE}

wire_patterns: ${WIRE_PATTERNS}

clean:
rm -rf build_${PART}
1 change: 1 addition & 0 deletions minitests/graph_folding/build_node_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def main():
lookup.build_database(db, progressbar.progressbar)
except Exception:
os.unlink(args.database)
raise


if __name__ == "__main__":
Expand Down
6 changes: 5 additions & 1 deletion minitests/graph_folding/estimate_sizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def main():
sizeof_delta = struct.calcsize('i')
sizeof_wire_in_tile_idx = struct.calcsize('i')
cost_per_wire = 2 * sizeof_delta + sizeof_wire_in_tile_idx
max_wires_per_tile = 0
_ = cost_per_wire

all_wires = 0
Expand All @@ -48,6 +49,7 @@ def main():
tile_type_info = db.get_tile_type(tile_type)
tile_type_to_wires[tile_type] = len(tile_type_info.get_wires())
all_wires += len(tile_type_info.get_wires())
max_wires_per_tile = max(max_wires_per_tile, len(tile_type_info.get_wires()))

for tile_type in sorted(
tile_type_to_count, key=
Expand All @@ -56,7 +58,9 @@ def main():
print(
tile_type, tile_type_to_count[tile_type],
tile_type_to_wires[tile_type])
print(all_wires)

print('Total number of wires:', all_wires)
print('Max wires per tile:', max_wires_per_tile)


if __name__ == "__main__":
Expand Down
30 changes: 27 additions & 3 deletions minitests/graph_folding/node_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,21 @@ def create_tables(conn):
pkey INTEGER PRIMARY KEY,
tile_type_pkey INTEGER,
name TEXT,
has_pip_from BOOLEAN,
FOREIGN KEY(tile_type_pkey) REFERENCES tile_type(pkey)
);
CREATE TABLE pip_in_tile(
pkey INTEGER PRIMARY KEY,
tile_type_pkey INTEGER,
wire0_in_tile_pkey INTEGER,
wire1_in_tile_pkey INTEGER,
is_directional BOOLEAN,
FOREIGN KEY(tile_type_pkey) REFERENCES tile_type(pkey),
FOREIGN KEY(wire0_in_tile_pkey) REFERENCES wire_in_tile(pkey),
FOREIGN KEY(wire1_in_tile_pkey) REFERENCES wire_in_tile(pkey)
);
CREATE TABLE tile(
pkey INTEGER PRIMARY KEY,
tile_type_pkey INTEGER,
Expand Down Expand Up @@ -78,13 +90,25 @@ def build_database(self, db, progressbar=lambda x: x):
tile_type_pkey = c.lastrowid
tile_type_pkeys[tile_type_name] = tile_type_pkey
tile_type = db.get_tile_type(tile_type_name)
tile_type

wires_with_pips = set()
for pip in tile_type.get_pips():
wires_with_pips.add(pip.net_from)

if not pip.is_directional:
wires_with_pips.add(pip.net_to)

for wire in tile_type.get_wires():
c.execute(
"INSERT INTO wire_in_tile(name, tile_type_pkey) VALUES (?, ?);",
(wire, tile_type_pkey))
"INSERT INTO wire_in_tile(name, tile_type_pkey, has_pip_from) VALUES (?, ?, ?);",
(wire, tile_type_pkey, wire in wires_with_pips))
wire_in_tile_pkeys[tile_type_name, wire] = c.lastrowid

for pip in tile_type.get_pips():
c.execute(
"INSERT INTO pip_in_tile(tile_type_pkey, wire0_in_tile_pkey, wire1_in_tile_pkey, is_directional) VALUES (?, ?, ?, ?);",
(tile_type_pkey, wire_in_tile_pkeys[tile_type_name, pip.net_from], wire_in_tile_pkeys[tile_type_name, pip.net_to], pip.is_directional))

tile_pkeys = {}
for tile_name in progressbar(grid.tiles()):
x, y = grid.loc_of_tilename(tile_name)
Expand Down
45 changes: 37 additions & 8 deletions minitests/graph_folding/reduce_graph_for_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,16 @@ def get_wire_to_node_graph(database, tile_type):
""", (node_pkey, ))
node_tile_x, node_tile_y, node_wire_in_tile_pkey = cur3.fetchone()

delta_x = node_tile_x - tile_x
delta_y = node_tile_y - tile_y

if delta_x == 0 and delta_y == 0 and wire_in_tile_pkey == node_wire_in_tile_pkey:
continue

pattern = WireToNode(
wire_in_tile_pkey=wire_in_tile_pkey,
delta_x=node_tile_x - tile_x,
delta_y=node_tile_y - tile_y,
delta_x=delta_x,
delta_y=delta_y,
node_wire_in_tile_pkey=node_wire_in_tile_pkey)

if pattern not in all_wire_to_nodes:
Expand Down Expand Up @@ -117,14 +123,25 @@ def get_node_to_wires_graph(database, tile_type):
SELECT wire.wire_in_tile_pkey, tile.x, tile.y
FROM wire
INNER JOIN tile ON wire.tile_pkey = tile.pkey
WHERE wire.node_pkey = ?;
INNER JOIN wire_in_tile ON wire.wire_in_tile_pkey = wire_in_tile.pkey
WHERE wire.node_pkey = ? and wire_in_tile.has_pip_from;
""", (node_pkey, )):

delta_x = wire_tile_x - tile_x
delta_y = wire_tile_y - tile_y

if delta_x == 0 and delta_y == 0 and wire_in_tile_pkey == node_wire_in_tile_pkey:
continue

node_to_wires.append(
NodeToWire(
delta_x=wire_tile_x - tile_x,
delta_y=wire_tile_y - tile_y,
delta_x=delta_x,
delta_y=delta_y,
wire_in_tile_pkey=wire_in_tile_pkey))

if len(node_to_wires) == 0:
continue

node_to_wires = (node_wire_in_tile_pkey, frozenset(node_to_wires))
if node_to_wires not in all_node_to_wires:
all_node_to_wires.add(node_to_wires)
Expand Down Expand Up @@ -170,20 +187,24 @@ def main():

if args.wire_to_node:
tile_wire_ids = set()
wire_nodes = set()
dxdys = set()
max_dxdy = 0
for pattern in graph.v:
tile_wire_ids.add(pattern.node_wire_in_tile_pkey)
wire_nodes.add(pattern.wire_in_tile_pkey)
dxdys.add((pattern.delta_x, pattern.delta_y))
max_dxdy = max(max_dxdy, abs(pattern.delta_x))
max_dxdy = max(max_dxdy, abs(pattern.delta_y))

print('Wire nodes {}'.format(len(wire_nodes)))
print('Unique node wire in tile pkey {}'.format(len(tile_wire_ids)))
print('Unique pattern {}'.format(len(graph.v)))
print('Unique dx dy {}'.format(len(dxdys)))
print('Unique dx dy dist {}'.format(max_dxdy))
elif args.node_to_wires:
tile_wire_ids = set()
node_wires = set()
patterns = set()
dxdys = set()
max_dxdy = 0
Expand All @@ -192,6 +213,8 @@ def main():
node_to_wires_to_count = {}

for node_wire_in_tile_pkey, node_to_wires in graph.v:
node_wires.add(node_wire_in_tile_pkey)

if node_to_wires not in node_to_wires_to_count:
node_to_wires_to_count[node_to_wires] = len(node_to_wires)

Expand All @@ -204,9 +227,13 @@ def main():
max_dxdy = max(max_dxdy, abs(pattern.delta_y))

pattern_count = 0
max_node_to_wires = 0
for num_patterns in node_to_wires_to_count.values():
pattern_count += num_patterns
max_node_to_wires = max(max_node_to_wires, num_patterns)

print('Node wires: {}'.format(len(node_wires)))
print('Max number of patterns: {}'.format(max_node_to_wires))
print('Minimum number of pattern storage: {}'.format(pattern_count))
print('Unique wire in tile pkey {}'.format(len(tile_wire_ids)))
print('Unique node_to_wires {}'.format(len(graph.v)))
Expand Down Expand Up @@ -264,13 +291,15 @@ def get_tile_edges():
tile_to_tile_patterns[tile] = tile_pattern
tile_patterns.add(tile_pattern)

number_of_tile_pattern_elements = 0
for tile_pattern in tile_patterns:
number_of_tile_pattern_elements += len(tile_pattern)

print('Have {} tile patterns'.format(len(tile_patterns)))
print(
'Max {} patterns'.format(
max(len(patterns) for patterns in tile_to_tile_patterns.values())))

#for tile, pattern in tile_to_tile_patterns.items():
# print(tile, pattern)
print('Number of tile pattern elements: {}'.format(number_of_tile_pattern_elements))


if __name__ == "__main__":
Expand Down

0 comments on commit f369ce6

Please sign in to comment.