def build_greedy_legalization(self, params, placedb, data_collections, device): """ @brief greedy 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 """ return greedy_legalize.GreedyLegalize( node_size_x=data_collections.node_size_x, node_size_y=data_collections.node_size_y, 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_filler_nodes=placedb.num_filler_nodes )
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 xx = np.array([1.0, 0.5, 3.0]).astype(dtype) yy = np.array([0.5, 0.8, 1.5]).astype(dtype) node_size_x = np.array([0.5, 1.5, 1.0]).astype(dtype) node_size_y = np.array([2.0, 2.0, 4.0]).astype(dtype) num_nodes = len(xx) xl = 1.0 yl = 1.0 xh = 5.0 yh = 5.0 num_terminals = 0 num_filler_nodes = 0 num_movable_nodes = len(xx)-num_terminals-num_filler_nodes site_width = 1 row_height = 2 num_bins_x = 2 num_bins_y = 2 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_filler_nodes, num_movable_nodes, num_movable_nodes+num_terminals, num_filler_nodes) # test cpu custom = greedy_legalize.GreedyLegalize( 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_filler_nodes=num_filler_nodes) pos = Variable(torch.from_numpy(np.concatenate([xx, yy]))) result = custom.forward(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_filler_nodes, num_movable_nodes, num_movable_nodes+num_terminals, num_filler_nodes) # test cuda custom_cuda = greedy_legalize.GreedyLegalize( 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_filler_nodes=num_filler_nodes) pos = Variable(torch.from_numpy(np.concatenate([xx, yy]))).cuda() result_cuda = custom_cuda.forward(pos) print("custom_result = ", result_cuda.data.cpu())