コード例 #1
0
    def test_densityOverflowRandom(self):
        dtype = np.float32
        xx = np.array([1.0, 4.6]).astype(dtype)
        yy = np.array([0.5, 4.1]).astype(dtype)
        node_size_x = np.array([0.5, 1.0]).astype(dtype)
        node_size_y = np.array([1.0, 1.0]).astype(dtype)
        #xx = np.array([2.0]).astype(dtype)
        #yy = np.array([1.5]).astype(dtype)
        #node_size_x = np.array([1.0]).astype(dtype)
        #node_size_y = np.array([1.0]).astype(dtype)
        num_nodes = len(xx)
        scale_factor = 1.0

        xl = 1.0
        yl = 1.0
        xh = 5.0
        yh = 5.0
        num_movable_nodes = len(xx)
        num_terminals = 0
        num_filler_nodes = 0

        # test cpu
        custom = move_boundary.MoveBoundary(
            torch.from_numpy(node_size_x),
            torch.from_numpy(node_size_y),
            xl=xl,
            yl=yl,
            xh=xh,
            yh=yh,
            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)

        #result.retain_grad()
        #result.sum().backward()
        #print("custom_result.grad = ", result.grad)

        # test cuda
        if torch.cuda.device_count():
            custom_cuda = move_boundary.MoveBoundary(
                torch.from_numpy(node_size_x).cuda(),
                torch.from_numpy(node_size_y).cuda(),
                xl=xl,
                yl=yl,
                xh=xh,
                yh=yh,
                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())

            np.testing.assert_allclose(result, result_cuda.data.cpu())
コード例 #2
0
 def build_move_boundary(self, params, placedb, data_collections, device):
     """
     @brief bound nodes into layout region 
     @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 move_boundary.MoveBoundary(
             data_collections.node_size_x, data_collections.node_size_y, 
             xl=placedb.xl, yl=placedb.yl, xh=placedb.xh, yh=placedb.yh, 
             num_movable_nodes=placedb.num_movable_nodes, 
             num_filler_nodes=placedb.num_filler_nodes
             )