Ejemplo n.º 1
0
def main():
    conf = parse_args(legion.input_args(True))

    assert conf.num_pieces % conf.pieces_per_superpiece == 0, "pieces should be evenly distributed to superpieces"
    conf.shared_nodes_per_piece = int(
        math.ceil(conf.nodes_per_piece * conf.pct_shared_nodes / 100.0))
    print(
        "circuit settings: loops=%d prune=%d pieces=%d (pieces/superpiece=%d) nodes/piece=%d (nodes/piece=%d) wires/piece=%d pct_in_piece=%d seed=%d"
        % (conf.num_loops, conf.prune, conf.num_pieces,
           conf.pieces_per_superpiece, conf.nodes_per_piece,
           conf.shared_nodes_per_piece, conf.wires_per_piece,
           conf.pct_wire_in_piece, conf.random_seed))

    num_pieces = conf.num_pieces
    num_superpieces = conf.num_pieces // conf.pieces_per_superpiece
    num_circuit_nodes = num_pieces * conf.nodes_per_piece
    num_circuit_wires = num_pieces * conf.wires_per_piece

    node = Fspace.create(
        OrderedDict([
            ('node_cap', legion.float32),
            ('leakage', legion.float32),
            ('charge', legion.float32),
            ('node_voltage', legion.float32),
        ]))
    wire = Fspace.create(
        OrderedDict([
            ('in_ptr', legion.int64),
            ('in_ptr_r', legion.uint8),
            ('out_ptr', legion.int64),
            ('out_ptr_r', legion.uint8),
            ('inductance', legion.float32),
            ('resistance', legion.float32),
            ('wire_cap', legion.float32),
        ] + [('current_%d' % i, legion.float32)
             for i in range(10)] + [('voltage_%d' % i, legion.float32)
                                    for i in range(9)]))

    all_nodes = Region.create([num_circuit_nodes], node)
    all_wires = Region.create([num_circuit_wires], wire)

    node_size = np.dtype(list(
        map(lambda x: (x[0], x[1].numpy_type), node.field_types.items())),
                         align=True).itemsize
    wire_size = np.dtype(list(
        map(lambda x: (x[0], x[1].numpy_type), wire.field_types.items())),
                         align=True).itemsize
    print("Circuit memory usage:")
    print("  Nodes : %10d * %4d bytes = %12d bytes" %
          (num_circuit_nodes, node_size, num_circuit_nodes * node_size))
    print("  Wires : %10d * %4d bytes = %12d bytes" %
          (num_circuit_wires, wire_size, num_circuit_wires * wire_size))
    total = ((num_circuit_nodes * node_size) + (num_circuit_wires * wire_size))
    print("  Total                             %12d bytes" % total)

    snpp = conf.shared_nodes_per_piece
    pnpp = conf.nodes_per_piece - conf.shared_nodes_per_piece
    pps = conf.pieces_per_superpiece
    num_shared_nodes = num_pieces * snpp

    privacy_coloring = Region.create([2], {'rect': legion.rect1d})
    np.copyto(privacy_coloring.rect,
              np.array([(num_shared_nodes, num_circuit_nodes - 1),
                        (0, num_shared_nodes - 1)],
                       dtype=privacy_coloring.rect.dtype),
              casting='no')
    privacy_part = Partition.create_by_restriction(privacy_coloring, [2],
                                                   np.eye(1), [1],
                                                   disjoint_complete)
    all_nodes_part = Partition.create_by_image(all_nodes, privacy_part, 'rect',
                                               [2], disjoint_complete)

    all_private = all_nodes_part[0]
    all_shared = all_nodes_part[1]

    launch_domain = Ispace.create([num_superpieces])

    private_part = Partition.create_by_restriction(
        all_private, launch_domain,
        np.eye(1) * pnpp * pps,
        Domain.create([pnpp * pps], [num_shared_nodes]), disjoint_complete)
    shared_part = Partition.create_by_restriction(all_shared, launch_domain,
                                                  np.eye(1) * snpp * pps,
                                                  [snpp * pps],
                                                  disjoint_complete)

    wires_part = Partition.create_equal(all_wires, launch_domain)

    ghost_ranges = Region.create([num_superpieces],
                                 OrderedDict([('rect', legion.rect1d)]))
    ghost_ranges_part = Partition.create_equal(ghost_ranges, launch_domain)

    for i in IndexLaunch(launch_domain):
        init_piece(int(i), conf[0], ghost_ranges_part[i], private_part[i],
                   shared_part[i], all_shared, wires_part[i])

    ghost_part = Partition.create_by_image(all_shared, ghost_ranges_part,
                                           'rect', launch_domain)

    for i in IndexLaunch(launch_domain):
        init_pointers(private_part[i], shared_part[i], ghost_part[i],
                      wires_part[i])

    steps = conf.steps
    prune = conf.prune
    num_loops = conf.num_loops + 2 * prune

    for j in range(num_loops):
        for i in IndexLaunch(launch_domain):
            calculate_new_currents(j == prune, steps, private_part[i],
                                   shared_part[i], ghost_part[i],
                                   wires_part[i])
        for i in IndexLaunch(launch_domain):
            distribute_charge(private_part[i], shared_part[i], ghost_part[i],
                              wires_part[i])
        for i in IndexLaunch(launch_domain):
            update_voltages(j == num_loops - prune - 1, private_part[i],
                            shared_part[i])
Ejemplo n.º 2
0
def make_colors_part(tiles):
    colors = Region.create(tiles, {'rect': legion.rect2d})
    colors_part = Partition.create_by_restriction(colors, tiles, np.eye(2),
                                                  [1, 1], disjoint_complete)
    return colors, colors_part