Ejemplo n.º 1
0
def main():
    d = Domain(10)

    print(d, d.bounds)

    t = 0
    for x in d:
        print(x)
        t += int(x)
    assert t == 45

    d2 = Domain([3, 3], [1, 1])

    print(d2, d2.bounds)

    t2 = 0
    for x in d2:
        print(x)
        t2 += x[0] * x[1]
    assert t2 == 36


    d3 = Domain([4, 5, 6], [-1, 0, 1])

    print(d3, d3.bounds)

    t3 = 0
    for x in d3:
        t3 += x[0] * x[1] * x[2]
    assert t3 == 420
Ejemplo n.º 2
0
def main():
    futures = []
    for i in IndexLaunch(10):
        futures.append(hi(i))
    for i, future in enumerate(futures):
        print("got %s" % future.get())
        assert int(future.get()) == i

    # Same in 2 dimensions.
    futures = []
    for point in IndexLaunch([3, 3]):
        futures.append(hi(point))
    for i, point in enumerate(Domain([3, 3])):
        assert futures[i].get() == point

    R = Region([4, 4], {'x': legion.float64})
    P = Partition.equal(R, [2, 2])
    legion.fill(R, 'x', 0)

    for i in IndexLaunch([2, 2]):
        hello(R, i)

    for i in IndexLaunch([2, 2]):
        hello(P[i], i)

    # Again, with a more explicit syntax.
    # ID is the name of the (implicit) loop variable.
    futures = index_launch([3, 3], hi, ID)
    for point in Domain([3, 3]):
        assert futures[point].get() == point

    index_launch([2, 2], hello, R, ID)
    index_launch([2, 2], hello, P[ID], ID)
Ejemplo n.º 3
0
def execute_timestep(graph, num_fields, timestep, result, primary, secondary,
                     scratch, p_scratch, dset_max_args):
    fin = timestep % num_fields

    offset = c.task_graph_offset_at_timestep(graph, timestep)
    width = c.task_graph_width_at_timestep(graph, timestep)
    dset = c.task_graph_dependence_set_at_timestep(graph, timestep)

    colors = Domain([width], [offset])

    num_args = dset_max_args[dset]

    if scratch is None:
        point_task = execute_point_tasks[fin][num_args]
    else:
        point_task = execute_point_tasks_scratch[fin][num_args]

    point_task_args = [
        graph if use_native else encode_task_graph(graph),
        num_fields,
        timestep,
        0 if use_native else ID,
        primary[ID],
    ]
    if scratch is not None:
        point_task_args.append(p_scratch[ID])
    elif not use_native:
        point_task_args.append(None)
    point_task_args.extend(secondary[dset][arg][ID] for arg in range(num_args))
    index_launch(colors, point_task, *point_task_args)
Ejemplo n.º 4
0
def main():
    R = Region([4, 4], {'x': legion.float64})

    legion.fill(R, 'x', 0)

    # Create a partition of R.
    colors = [2, 2]
    transform = [[2, 0], [0, 2]]
    extent = [2, 2]
    P = Partition.restrict(R, colors, transform, extent)

    # Again, with different parameters.
    colors2 = [3]
    transform2 = [[1], [2]]
    extent2 = Domain([2, 2], [-1, -1])
    P2 = Partition.restrict(R, colors2, transform2, extent2)

    assert P.color_space.volume == 4
    assert P2.color_space.volume == 3

    # Grab a subregion of P.
    R00 = P[0, 0]

    print('Parent region has volume %s' % R.ispace.volume)
    assert R.ispace.volume == 16
    assert check_subregion(R00).get() == 4
    for Rij in P:
        assert check_subregion(Rij).get() == 4
    assert check_subregion(P2[0]).get() == 1
    assert check_subregion(P2[1]).get() == 4
    assert check_subregion(P2[2]).get() == 2
Ejemplo n.º 5
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.º 6
0
def main():
    print_once('Running circuit_sparse.py')

    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_once(
        "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(
        OrderedDict([
            ('node_cap', legion.float32),
            ('leakage', legion.float32),
            ('charge', legion.float32),
            ('node_voltage', legion.float32),
        ]))
    wire = Fspace(
        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(WIRE_SEGMENTS)] +
                    [('voltage_%d' % i, legion.float32)
                     for i in range(WIRE_SEGMENTS - 1)]))

    all_nodes = Region([num_circuit_nodes], node)
    all_wires = Region([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_once("Circuit memory usage:")
    print_once("  Nodes : %10d * %4d bytes = %12d bytes" %
               (num_circuit_nodes, node_size, num_circuit_nodes * node_size))
    print_once("  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_once("  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([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.restrict(privacy_coloring, [2], np.eye(1), [1],
                                      disjoint_complete)
    all_nodes_part = Partition.image(all_nodes, privacy_part, 'rect', [2],
                                     disjoint_complete)

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

    launch_domain = Ispace([num_superpieces])

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

    wires_part = Partition.equal(all_wires, launch_domain)

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

    if _constant_time_launches:
        c = Future(conf[0], value_type=Config)
        index_launch(launch_domain, init_piece, ID, c, ghost_ranges_part[ID],
                     private_part[ID], shared_part[ID], all_shared,
                     wires_part[ID])
    else:
        for i in IndexLaunch(launch_domain):
            init_piece(i, conf[0], ghost_ranges_part[i], private_part[i],
                       shared_part[i], all_shared, wires_part[i])

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

    if _constant_time_launches:
        index_launch(launch_domain, init_pointers, private_part[ID],
                     shared_part[ID], ghost_part[ID], wires_part[ID])
    else:
        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

    trace = Trace()
    for j in range(num_loops):
        if j == prune:
            legion.execution_fence(block=True)
            start_time = legion.c.legion_get_current_time_in_nanos()
        with trace:
            if _constant_time_launches:
                index_launch(launch_domain, calculate_new_currents, False,
                             steps, private_part[ID], shared_part[ID],
                             ghost_part[ID], wires_part[ID])
                index_launch(launch_domain, distribute_charge,
                             private_part[ID], shared_part[ID], ghost_part[ID],
                             wires_part[ID])
                index_launch(launch_domain, update_voltages, False,
                             private_part[ID], shared_part[ID])
            else:
                for i in IndexLaunch(launch_domain):
                    calculate_new_currents(False, 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(False, private_part[i], shared_part[i])
        if j == num_loops - prune - 1:
            legion.execution_fence(block=True)
            stop_time = legion.c.legion_get_current_time_in_nanos()

    sim_time = (stop_time - start_time) / 1e9
    print_once('ELAPSED TIME = %7.3f s' % sim_time)

    # Compute the floating point operations per second
    num_circuit_nodes = conf.num_pieces * conf.nodes_per_piece
    num_circuit_wires = conf.num_pieces * conf.wires_per_piece
    # calculate currents
    operations = num_circuit_wires * (WIRE_SEGMENTS * 6 +
                                      (WIRE_SEGMENTS - 1) * 4) * conf.steps
    # distribute charge
    operations += (num_circuit_wires * 4)
    # update voltages
    operations += (num_circuit_nodes * 4)
    # multiply by the number of loops
    operations *= conf.num_loops

    # Compute the number of gflops
    gflops = (1e-9 * operations) / sim_time
    print_once("GFLOPS = %7.3f GFLOPS" % gflops)