def build_legalization(self, params, placedb, data_collections, device): """ @brief legalization @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 """ # for movable macro legalization # the number of bins control the search granularity ml = macro_legalize.MacroLegalize( node_size_x=data_collections.node_size_x, node_size_y=data_collections.node_size_y, node_weights=data_collections.num_pins_in_nodes, 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, 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) # for standard cell legalization gl = greedy_legalize.GreedyLegalize( node_size_x=data_collections.node_size_x, node_size_y=data_collections.node_size_y, node_weights=data_collections.num_pins_in_nodes, 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, 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=1, num_bins_y=64, #num_bins_x=64, num_bins_y=64, num_movable_nodes=placedb.num_movable_nodes, num_terminal_NIs=placedb.num_terminal_NIs, num_filler_nodes=placedb.num_filler_nodes) # for standard cell legalization al = abacus_legalize.AbacusLegalize( node_size_x=data_collections.node_size_x, node_size_y=data_collections.node_size_y, node_weights=data_collections.num_pins_in_nodes, 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, 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=1, num_bins_y=64, #num_bins_x=64, num_bins_y=64, num_movable_nodes=placedb.num_movable_nodes, num_terminal_NIs=placedb.num_terminal_NIs, num_filler_nodes=placedb.num_filler_nodes) def build_legalization_op(pos): logging.info("Start legalization") pos1 = ml(pos, pos) pos2 = gl(pos1, pos1) legal = self.op_collections.legality_check_op(pos2) if not legal: logging.error("legality check failed in greedy legalization") return pos2 return al(pos1, pos2) return build_legalization_op
def test_greedyLegalizeRandom(self): dtype = np.float64 xl = 1.0 yl = 1.0 xh = 51.0 yh = 51.0 xx = np.random.uniform(xl, xh, size=6).astype(dtype) yy = np.random.uniform(yl, yh, size=6).astype(dtype) node_size_x = np.array([10, 15, 5, 4, 2, 4]).astype(dtype) node_size_y = np.array([10, 20, 30, 2, 4, 6]).astype(dtype) num_nodes = len(xx) num_terminals = 0 num_terminal_NIs = 0 num_filler_nodes = 0 num_movable_nodes = len( xx) - num_terminals - num_terminal_NIs - num_filler_nodes site_width = 1 row_height = 2 num_bins_x = 2 num_bins_y = 2 print("xx = %s" % (xx)) print("yy = %s" % (yy)) plot( "initial.png", xx, yy, node_size_x, node_size_y, xl, yl, xh, yh, num_bins_x, num_bins_y, num_movable_nodes + num_terminals + num_terminal_NIs + num_filler_nodes, num_movable_nodes, num_movable_nodes + num_terminals + num_terminal_NIs, num_filler_nodes) # test cpu custom = macro_legalize.MacroLegalize( torch.from_numpy(node_size_x), torch.from_numpy(node_size_y), xl=xl, yl=yl, xh=xh, yh=yh, site_width=site_width, row_height=row_height, num_bins_x=num_bins_x, num_bins_y=num_bins_y, num_movable_nodes=num_movable_nodes, num_terminal_NIs=num_terminal_NIs, num_filler_nodes=num_filler_nodes) pos = Variable(torch.from_numpy(np.concatenate([xx, yy]))) result = custom(pos, pos) print("custom_result = ", result) print("average displacement = %g" % (np.sum(np.absolute(result.numpy() - np.concatenate([xx, yy]))) / num_movable_nodes)) plot( "final.png", result.numpy()[0:len(xx)], result.numpy()[len(xx):], node_size_x, node_size_y, xl, yl, xh, yh, num_bins_x, num_bins_y, num_movable_nodes + num_terminals + num_terminal_NIs + num_filler_nodes, num_movable_nodes, num_movable_nodes + num_terminals + num_terminal_NIs, num_filler_nodes) # test cuda if torch.cuda.device_count(): custom_cuda = macro_legalize.MacroLegalize( torch.from_numpy(node_size_x).cuda(), torch.from_numpy(node_size_y).cuda(), xl=xl, yl=yl, xh=xh, yh=yh, site_width=site_width, row_height=row_height, num_bins_x=num_bins_x, num_bins_y=num_bins_y, num_movable_nodes=num_movable_nodes, num_terminal_NIs=num_terminal_NIs, num_filler_nodes=num_filler_nodes) pos = Variable(torch.from_numpy(np.concatenate([xx, yy]))).cuda() result_cuda = custom_cuda(pos, pos) print("custom_result = ", result_cuda.data.cpu())