def build_detailed_placement(self, params, placedb, data_collections, device): """ @brief detailed placement consisting of global swap and independent set matching @param params parameters @param placedb placement database @param data_collections a collection of all data and variables required for constructing the ops @param device cpu or cuda """ gs = global_swap.GlobalSwap( node_size_x=data_collections.node_size_x, node_size_y=data_collections.node_size_y, flat_region_boxes=data_collections.flat_region_boxes, flat_region_boxes_start=data_collections.flat_region_boxes_start, node2fence_region_map=data_collections.node2fence_region_map, flat_net2pin_map=data_collections.flat_net2pin_map, flat_net2pin_start_map=data_collections.flat_net2pin_start_map, pin2net_map=data_collections.pin2net_map, flat_node2pin_map=data_collections.flat_node2pin_map, flat_node2pin_start_map=data_collections.flat_node2pin_start_map, pin2node_map=data_collections.pin2node_map, pin_offset_x=data_collections.pin_offset_x, pin_offset_y=data_collections.pin_offset_y, net_mask=data_collections.net_mask_ignore_large_degrees, xl=placedb.xl, yl=placedb.yl, xh=placedb.xh, yh=placedb.yh, site_width=placedb.site_width, row_height=placedb.row_height, #num_bins_x=placedb.num_bins_x//16, num_bins_y=placedb.num_bins_y//16, num_bins_x=placedb.num_bins_x // 2, num_bins_y=placedb.num_bins_y // 2, num_movable_nodes=placedb.num_movable_nodes, num_terminal_NIs=placedb.num_terminal_NIs, num_filler_nodes=placedb.num_filler_nodes, batch_size=256, max_iters=2, algorithm='concurrent', num_threads=params.num_threads) kr = k_reorder.KReorder( node_size_x=data_collections.node_size_x, node_size_y=data_collections.node_size_y, flat_region_boxes=data_collections.flat_region_boxes, flat_region_boxes_start=data_collections.flat_region_boxes_start, node2fence_region_map=data_collections.node2fence_region_map, flat_net2pin_map=data_collections.flat_net2pin_map, flat_net2pin_start_map=data_collections.flat_net2pin_start_map, pin2net_map=data_collections.pin2net_map, flat_node2pin_map=data_collections.flat_node2pin_map, flat_node2pin_start_map=data_collections.flat_node2pin_start_map, pin2node_map=data_collections.pin2node_map, pin_offset_x=data_collections.pin_offset_x, pin_offset_y=data_collections.pin_offset_y, net_mask=data_collections.net_mask_ignore_large_degrees, xl=placedb.xl, yl=placedb.yl, xh=placedb.xh, yh=placedb.yh, site_width=placedb.site_width, row_height=placedb.row_height, num_bins_x=placedb.num_bins_x, num_bins_y=placedb.num_bins_y, num_movable_nodes=placedb.num_movable_nodes, num_terminal_NIs=placedb.num_terminal_NIs, num_filler_nodes=placedb.num_filler_nodes, K=4, max_iters=2, num_threads=params.num_threads) ism = independent_set_matching.IndependentSetMatching( node_size_x=data_collections.node_size_x, node_size_y=data_collections.node_size_y, flat_region_boxes=data_collections.flat_region_boxes, flat_region_boxes_start=data_collections.flat_region_boxes_start, node2fence_region_map=data_collections.node2fence_region_map, flat_net2pin_map=data_collections.flat_net2pin_map, flat_net2pin_start_map=data_collections.flat_net2pin_start_map, pin2net_map=data_collections.pin2net_map, flat_node2pin_map=data_collections.flat_node2pin_map, flat_node2pin_start_map=data_collections.flat_node2pin_start_map, pin2node_map=data_collections.pin2node_map, pin_offset_x=data_collections.pin_offset_x, pin_offset_y=data_collections.pin_offset_y, net_mask=data_collections.net_mask_ignore_large_degrees, xl=placedb.xl, yl=placedb.yl, xh=placedb.xh, yh=placedb.yh, site_width=placedb.site_width, row_height=placedb.row_height, num_bins_x=placedb.num_bins_x, num_bins_y=placedb.num_bins_y, num_movable_nodes=placedb.num_movable_nodes, num_terminal_NIs=placedb.num_terminal_NIs, num_filler_nodes=placedb.num_filler_nodes, batch_size=2048, set_size=128, max_iters=50, algorithm='concurrent', num_threads=params.num_threads) # wirelength for position def build_detailed_placement_op(pos): logging.info("Start ABCDPlace for refinement") pos1 = pos for i in range(1): pos1 = kr(pos1) legal = self.op_collections.legality_check_op(pos1) logging.info("K-Reorder legal flag = %d" % (legal)) if not legal: return pos1 pos1 = ism(pos1) legal = self.op_collections.legality_check_op(pos1) logging.info("Independent set matching legal flag = %d" % (legal)) if not legal: return pos1 pos1 = gs(pos1) legal = self.op_collections.legality_check_op(pos1) logging.info("Global swap legal flag = %d" % (legal)) if not legal: return pos1 pos1 = kr(pos1) legal = self.op_collections.legality_check_op(pos1) logging.info("K-Reorder legal flag = %d" % (legal)) if not legal: return pos1 return pos1 return build_detailed_placement_op
def build_detailed_placement(self, params, placedb, data_collections, device): """ @brief detailed placement consisting of global swap and independent set matching @param params parameters @param placedb placement database @param data_collections a collection of all data and variables required for constructing the ops @param device cpu or cuda """ gs = global_swap.GlobalSwap( node_size_x=data_collections.node_size_x, node_size_y=data_collections.node_size_y, flat_region_boxes=data_collections.flat_region_boxes, flat_region_boxes_start=data_collections.flat_region_boxes_start, node2fence_region_map=data_collections.node2fence_region_map, flat_net2pin_map=data_collections.flat_net2pin_map, flat_net2pin_start_map=data_collections.flat_net2pin_start_map, pin2net_map=data_collections.pin2net_map, flat_node2pin_map=data_collections.flat_node2pin_map, flat_node2pin_start_map=data_collections.flat_node2pin_start_map, pin2node_map=data_collections.pin2node_map, pin_offset_x=data_collections.pin_offset_x, pin_offset_y=data_collections.pin_offset_y, net_mask=data_collections.net_mask_ignore_large_degrees, xl=placedb.xl, yl=placedb.yl, xh=placedb.xh, yh=placedb.yh, site_width=placedb.site_width, row_height=placedb.row_height, #num_bins_x=placedb.num_bins_x//16, num_bins_y=placedb.num_bins_y//16, num_bins_x=placedb.num_bins_x // 2, num_bins_y=placedb.num_bins_y // 2, num_movable_nodes=placedb.num_movable_nodes, num_terminal_NIs=placedb.num_terminal_NIs, num_filler_nodes=placedb.num_filler_nodes, batch_size=256, max_iters=2, algorithm='concurrent') kr = k_reorder.KReorder( node_size_x=data_collections.node_size_x, node_size_y=data_collections.node_size_y, flat_region_boxes=data_collections.flat_region_boxes, flat_region_boxes_start=data_collections.flat_region_boxes_start, node2fence_region_map=data_collections.node2fence_region_map, flat_net2pin_map=data_collections.flat_net2pin_map, flat_net2pin_start_map=data_collections.flat_net2pin_start_map, pin2net_map=data_collections.pin2net_map, flat_node2pin_map=data_collections.flat_node2pin_map, flat_node2pin_start_map=data_collections.flat_node2pin_start_map, pin2node_map=data_collections.pin2node_map, pin_offset_x=data_collections.pin_offset_x, pin_offset_y=data_collections.pin_offset_y, net_mask=data_collections.net_mask_ignore_large_degrees, xl=placedb.xl, yl=placedb.yl, xh=placedb.xh, yh=placedb.yh, site_width=placedb.site_width, row_height=placedb.row_height, num_bins_x=placedb.num_bins_x, num_bins_y=placedb.num_bins_y, num_movable_nodes=placedb.num_movable_nodes, num_terminal_NIs=placedb.num_terminal_NIs, num_filler_nodes=placedb.num_filler_nodes, K=4, max_iters=2) ism = independent_set_matching.IndependentSetMatching( node_size_x=data_collections.node_size_x, node_size_y=data_collections.node_size_y, flat_region_boxes=data_collections.flat_region_boxes, flat_region_boxes_start=data_collections.flat_region_boxes_start, node2fence_region_map=data_collections.node2fence_region_map, flat_net2pin_map=data_collections.flat_net2pin_map, flat_net2pin_start_map=data_collections.flat_net2pin_start_map, pin2net_map=data_collections.pin2net_map, flat_node2pin_map=data_collections.flat_node2pin_map, flat_node2pin_start_map=data_collections.flat_node2pin_start_map, pin2node_map=data_collections.pin2node_map, pin_offset_x=data_collections.pin_offset_x, pin_offset_y=data_collections.pin_offset_y, net_mask=data_collections.net_mask_ignore_large_degrees, xl=placedb.xl, yl=placedb.yl, xh=placedb.xh, yh=placedb.yh, site_width=placedb.site_width, row_height=placedb.row_height, num_bins_x=placedb.num_bins_x, num_bins_y=placedb.num_bins_y, num_movable_nodes=placedb.num_movable_nodes, num_terminal_NIs=placedb.num_terminal_NIs, num_filler_nodes=placedb.num_filler_nodes, batch_size=2048, set_size=128, max_iters=50, algorithm='concurrent') # wirelength for position def build_detailed_placement_op(pos): logging.info("Start ABCDPlace for refinement") pos1 = pos legal = self.op_collections.legality_check_op(pos1) logging.info("ABCDPlace input legal flag = %d" % (legal)) if not legal: return pos1 # integer factorization to prime numbers def prime_factorization(num): lt = [] while num != 1: for i in range(2, int(num + 1)): if num % i == 0: # i is a prime factor lt.append(i) num = num / i # get the quotient for further factorization break return lt # compute the scale factor for detailed placement # as the algorithms prefer integer coordinate systems scale_factor = params.scale_factor if params.scale_factor != 1.0: inv_scale_factor = int(round(1.0 / params.scale_factor)) prime_factors = prime_factorization(inv_scale_factor) target_inv_scale_factor = 1 for factor in prime_factors: if factor != 2 and factor != 5: target_inv_scale_factor = inv_scale_factor break scale_factor = 1.0 / target_inv_scale_factor logging.info("Deriving from system scale factor %g (1/%d)" % (params.scale_factor, inv_scale_factor)) logging.info( "Use scale factor %g (1/%d) for detailed placement" % (scale_factor, target_inv_scale_factor)) for i in range(1): pos1 = kr(pos1, scale_factor) legal = self.op_collections.legality_check_op(pos1) logging.info("K-Reorder legal flag = %d" % (legal)) if not legal: return pos1 pos1 = ism(pos1, scale_factor) legal = self.op_collections.legality_check_op(pos1) logging.info("Independent set matching legal flag = %d" % (legal)) if not legal: return pos1 pos1 = gs(pos1, scale_factor) legal = self.op_collections.legality_check_op(pos1) logging.info("Global swap legal flag = %d" % (legal)) if not legal: return pos1 pos1 = kr(pos1, scale_factor) legal = self.op_collections.legality_check_op(pos1) logging.info("K-Reorder legal flag = %d" % (legal)) if not legal: return pos1 return pos1 return build_detailed_placement_op
def test_ispd2005(design, algorithm, device_str): with gzip.open(design, "rb") as f: if sys.version_info[0] < 3: data_collections = pickle.load(f) else: data_collections = pickle.load(f, encoding='bytes') node_size_x = data_collections[0] node_size_y = data_collections[1] flat_net2pin_map = data_collections[2] flat_net2pin_start_map = data_collections[3] pin2net_map = data_collections[4] flat_node2pin_map = data_collections[5] flat_node2pin_start_map = data_collections[6] pin2node_map = data_collections[7] pin_offset_x = data_collections[8] pin_offset_y = data_collections[9] net_mask_ignore_large_degrees = data_collections[10] xl = data_collections[11] yl = data_collections[12] xh = data_collections[13] yh = data_collections[14] site_width = data_collections[15] row_height = data_collections[16] num_bins_x = data_collections[17] num_bins_y = data_collections[18] num_movable_nodes = data_collections[19] num_terminal_NIs = data_collections[20] num_filler_nodes = data_collections[21] pos = data_collections[22] #net_mask = net_mask_ignore_large_degrees net_mask = np.ones_like(net_mask_ignore_large_degrees) for i in range(1, len(flat_net2pin_start_map)): degree = flat_net2pin_start_map[i] - flat_net2pin_start_map[i - 1] if degree > 100: net_mask[i - 1] = 0 net_mask = torch.from_numpy(net_mask) #max_node_degree = 0 #for i in range(1, len(flat_node2pin_start_map)): # if i <= num_movable_nodes: # max_node_degree = max(max_node_degree, flat_node2pin_start_map[i]-flat_node2pin_start_map[i-1]) #print("max node degree %d" % (max_node_degree)) device = torch.device(device_str) print("bins %dx%d" % (num_bins_x, num_bins_y)) print("num_movable_nodes %d, num_nodes %d" % (num_movable_nodes, node_size_x.numel() - num_filler_nodes - num_terminal_NIs)) pos = pos.float().to(device) custom = independent_set_matching.IndependentSetMatching( node_size_x=node_size_x.float().to(device), node_size_y=node_size_y.float().to(device), flat_net2pin_map=flat_net2pin_map.to(device), flat_net2pin_start_map=flat_net2pin_start_map.to(device), pin2net_map=pin2net_map.to(device), flat_node2pin_map=flat_node2pin_map.to(device), flat_node2pin_start_map=flat_node2pin_start_map.to(device), pin2node_map=pin2node_map.to(device), pin_offset_x=pin_offset_x.float().to(device), pin_offset_y=pin_offset_y.float().to(device), net_mask=net_mask.to(device), xl=xl, yl=yl, xh=xh, yh=yh, site_width=site_width, row_height=row_height, num_bins_x=num_bins_x // 1, num_bins_y=num_bins_y // 1, num_movable_nodes=num_movable_nodes, num_terminal_NIs=num_terminal_NIs, num_filler_nodes=num_filler_nodes, batch_size=2048, set_size=128, max_iters=50, algorithm=algorithm, num_threads=20) result = custom(pos)