def import_graph_nodes(conn, graph, node_mapping): cur = conn.cursor() tile_loc_to_pkey = {} for node in graph.nodes: if node.type not in (graph2.NodeType.IPIN, graph2.NodeType.OPIN): continue gridloc = graph.loc_map[(node.loc.x_low, node.loc.y_low)] pin_name = graph.pin_ptc_to_name_map[(gridloc.block_type_id, node.loc.ptc)] # Synthetic blocks are handled below. if pin_name.startswith('SYN-'): continue m = PIN_NAME_TO_PARTS.match(pin_name) assert m is not None, pin_name tile_type = m.group(1) tile_type = remove_vpr_tile_prefix(tile_type) pin = m.group(2) (wire_in_tile_pkeys, _) = get_wire_in_tile_from_pin_name(conn=conn, tile_type_str=tile_type, wire_str=pin) cur.execute( """ SELECT site_as_tile_pkey FROM tile WHERE grid_x = ? AND grid_y = ?; """, (node.loc.x_low, node.loc.y_low)) site_as_tile_pkey = cur.fetchone()[0] if site_as_tile_pkey is not None: cur.execute( """ SELECT site_pkey FROM site_as_tile WHERE pkey = ?; """, (site_as_tile_pkey, )) site_pkey = cur.fetchone()[0] wire_in_tile_pkey = wire_in_tile_pkeys[site_pkey] else: assert len(wire_in_tile_pkeys) == 1 _, wire_in_tile_pkey = wire_in_tile_pkeys.popitem() if gridloc not in tile_loc_to_pkey: cur.execute( """ SELECT pkey FROM tile WHERE grid_x = ? AND grid_y = ?;""", (gridloc[0], gridloc[1])) result = cur.fetchone() assert result is not None, (tile_type, gridloc) (tile_pkey, ) = result tile_loc_to_pkey[gridloc] = tile_pkey else: tile_pkey = tile_loc_to_pkey[gridloc] cur.execute( """ SELECT top_graph_node_pkey, bottom_graph_node_pkey, left_graph_node_pkey, right_graph_node_pkey FROM wire WHERE wire_in_tile_pkey = ? AND tile_pkey = ?;""", (wire_in_tile_pkey, tile_pkey)) result = cur.fetchone() assert result is not None, (wire_in_tile_pkey, tile_pkey) (top_graph_node_pkey, bottom_graph_node_pkey, left_graph_node_pkey, right_graph_node_pkey) = result side = node.loc.side if side == tracks.Direction.LEFT: assert left_graph_node_pkey is not None, (tile_type, pin_name) node_mapping[left_graph_node_pkey] = node.id elif side == tracks.Direction.RIGHT: assert right_graph_node_pkey is not None, (tile_type, pin_name) node_mapping[right_graph_node_pkey] = node.id elif side == tracks.Direction.TOP: assert top_graph_node_pkey is not None, (tile_type, pin_name) node_mapping[top_graph_node_pkey] = node.id elif side == tracks.Direction.BOTTOM: assert bottom_graph_node_pkey is not None, (tile_type, pin_name) node_mapping[bottom_graph_node_pkey] = node.id else: assert False, side
def import_graph_nodes(conn, graph, node_mapping, connection_box_map): cur = conn.cursor() tile_loc_to_pkey = {} for node_idx, node in enumerate(graph.nodes): if node.type not in (graph2.NodeType.IPIN, graph2.NodeType.OPIN): continue gridloc = graph.loc_map[(node.loc.x_low, node.loc.y_low)] pin_name = graph.pin_ptc_to_name_map[(gridloc.block_type_id, node.loc.ptc)] # Synthetic blocks are handled below. if pin_name.startswith('SYN-'): set_connection_box(graph, node_idx, node.loc.x_low, node.loc.y_low, box_id=graph.maybe_add_connection_box('IMUX')) continue m = PIN_NAME_TO_PARTS.match(pin_name) assert m is not None, pin_name tile_type = m.group(1) tile_type = remove_vpr_tile_prefix(tile_type) pin = m.group(2) cur.execute( """ SELECT pkey, site_as_tile_pkey FROM tile WHERE grid_x = ? AND grid_y = ?; """, (node.loc.x_low, node.loc.y_low)) result = cur.fetchone() assert result is not None, (tile_type, pin, node.loc) tile_pkey, site_as_tile_pkey = result if site_as_tile_pkey is not None: cur.execute( """ WITH site_for_tile(site_pkey) AS ( SELECT site_pkey FROM site_as_tile WHERE pkey = ? ) SELECT pkey FROM wire_in_tile WHERE site_pin_pkey = ( SELECT pkey FROM site_pin WHERE site_type_pkey = ( SELECT site_type_pkey FROM site WHERE pkey = (SELECT site_pkey FROM site_for_tile) ) AND name = ? ) AND site_pkey = (SELECT site_pkey FROM site_for_tile) ;""", (site_as_tile_pkey, pin)) results = cur.fetchall() assert len(results) == 1 wire_in_tile_pkey = results[0][0] else: cur.execute( """ SELECT pkey FROM wire_in_tile WHERE name = ? AND phy_tile_type_pkey IN ( SELECT tile_type_pkey FROM phy_tile WHERE pkey IN ( SELECT phy_tile_pkey FROM tile_map WHERE tile_pkey = ? ) );""", (pin, tile_pkey)) results = cur.fetchall() assert len(results) == 1 wire_in_tile_pkey = results[0][0] if gridloc not in tile_loc_to_pkey: cur.execute( """ SELECT pkey FROM tile WHERE grid_x = ? AND grid_y = ?;""", (gridloc[0], gridloc[1])) result = cur.fetchone() assert result is not None, (tile_type, gridloc) (tile_pkey, ) = result tile_loc_to_pkey[gridloc] = tile_pkey else: tile_pkey = tile_loc_to_pkey[gridloc] cur.execute( """ SELECT top_graph_node_pkey, bottom_graph_node_pkey, left_graph_node_pkey, right_graph_node_pkey FROM wire WHERE wire_in_tile_pkey = ? AND tile_pkey = ?;""", (wire_in_tile_pkey, tile_pkey)) result = cur.fetchone() assert result is not None, (wire_in_tile_pkey, tile_pkey) (top_graph_node_pkey, bottom_graph_node_pkey, left_graph_node_pkey, right_graph_node_pkey) = result side = node.loc.side if side == tracks.Direction.LEFT: assert left_graph_node_pkey is not None, (tile_type, pin_name) node_mapping[left_graph_node_pkey] = node.id update_connection_box(conn, graph, left_graph_node_pkey, node_idx, connection_box_map) elif side == tracks.Direction.RIGHT: assert right_graph_node_pkey is not None, (tile_type, pin_name) node_mapping[right_graph_node_pkey] = node.id update_connection_box(conn, graph, right_graph_node_pkey, node_idx, connection_box_map) elif side == tracks.Direction.TOP: assert top_graph_node_pkey is not None, (tile_type, pin_name) node_mapping[top_graph_node_pkey] = node.id update_connection_box(conn, graph, top_graph_node_pkey, node_idx, connection_box_map) elif side == tracks.Direction.BOTTOM: assert bottom_graph_node_pkey is not None, (tile_type, pin_name) node_mapping[bottom_graph_node_pkey] = node.id update_connection_box(conn, graph, bottom_graph_node_pkey, node_idx, connection_box_map) else: assert False, side
def import_graph_nodes(conn, graph, node_mapping): cur = conn.cursor() get_tile_and_site_as_tile_pkey = create_get_tile_and_site_as_tile_pkey(cur) get_site_as_tile_wire = create_get_site_as_tile_wire(cur) for node_idx, node in enumerate(graph.nodes): if node.type not in (graph2.NodeType.IPIN, graph2.NodeType.OPIN): continue gridloc = graph.loc_map[(node.loc.x_low, node.loc.y_low)] pin_name = graph.pin_ptc_to_name_map[(gridloc.block_type_id, node.loc.ptc)] # Synthetic blocks are handled below. if pin_name.startswith('SYN-'): continue m = PIN_NAME_TO_PARTS.match(pin_name) assert m is not None, pin_name tile_type = m.group(1) tile_type = remove_vpr_tile_prefix(tile_type) pin = m.group(2) tile_pkey, site_as_tile_pkey = get_tile_and_site_as_tile_pkey( node.loc.x_low, node.loc.y_low) if site_as_tile_pkey is not None: wire_in_tile_pkey = get_site_as_tile_wire(site_as_tile_pkey, pin) else: cur.execute( """ SELECT pkey FROM wire_in_tile WHERE name = ? AND phy_tile_type_pkey IN ( SELECT tile_type_pkey FROM phy_tile WHERE pkey IN ( SELECT phy_tile_pkey FROM tile_map WHERE tile_pkey = ? ) );""", (pin, tile_pkey)) results = cur.fetchall() assert len(results) == 1 wire_in_tile_pkey = results[0][0] tile_pkey, _ = get_tile_and_site_as_tile_pkey(gridloc[0], gridloc[1]) cur.execute( """ SELECT top_graph_node_pkey, bottom_graph_node_pkey, left_graph_node_pkey, right_graph_node_pkey FROM wire WHERE wire_in_tile_pkey = ? AND tile_pkey = ?;""", (wire_in_tile_pkey, tile_pkey)) result = cur.fetchone() assert result is not None, (wire_in_tile_pkey, tile_pkey) (top_graph_node_pkey, bottom_graph_node_pkey, left_graph_node_pkey, right_graph_node_pkey) = result # VPR emits only one node for each site pin, instead of one node for each # side location of a pin. # # If the directional graph nodes are present for a specific tile wire, # the same node ID is assigned to the directional graph node to prevent # VPR failing to find a route. if left_graph_node_pkey is not None: node_mapping[left_graph_node_pkey] = (node.id, node.type) if right_graph_node_pkey is not None: node_mapping[right_graph_node_pkey] = (node.id, node.type) if top_graph_node_pkey is not None: node_mapping[top_graph_node_pkey] = (node.id, node.type) if bottom_graph_node_pkey is not None: node_mapping[bottom_graph_node_pkey] = (node.id, node.type)