예제 #1
0
def main():
    R = Region([4, 4], {'x': pygion.float64})

    pygion.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
예제 #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': pygion.float64})
    P = Partition.equal(R, [2, 2])
    pygion.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)
예제 #3
0
파일: region.py 프로젝트: sanidhya/legion
def main():
    # Create a 2D index space of size 4x4.
    I = Ispace([4, 4])

    # Create a field space with a single field x of type float64.
    F = Fspace({'x': pygion.float64})

    # Create a region from I and F.
    R = Region(I, F)

    # This could have also been done with the following shortand, and
    # Legion will automatically create an index space and field space.
    R2 = Region([4, 4], {'x': pygion.float64})

    # Fill the field x of region R with an initial value.
    pygion.fill(R, 'x', 101)

    # Launch two tasks. The second task will depend on the first,
    # since they both write R.
    init(R)
    child_result = inc(R, 1)

    # Note: when a task runs, it returns a future. To get the value of
    # the future, you have to block. However, in idiomatic Legion code
    # it would be more common to pass the future to another task
    # (without blocking).
    print("child task returned", child_result)
    print("child task future contains", child_result.get())
    print("main_task done")
예제 #4
0
def main():
    R = Region([4, 4], {'x': pygion.float64})
    pygion.fill(R, 'x', 0)

    # Create a partition of R.
    P = Partition.equal(R, [2, 2])

    # Same as above, broken explicitly into two steps.
    IP2 = Ipartition.equal(R.ispace, [2, 2])
    P2 = Partition(R, IP2)

    assert P.color_space.volume == 4

    # 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

    # Partition the subregion again.
    P00 = Partition.equal(R00, [2, 2])
    total_volume = 0
    for x in range(2):
        for y in range(2):
            R00xy = P00[x, y]
            total_volume += check_subregion(R00xy).get()
    assert total_volume == 4

    # An easy way to iterate subregions:
    for Rij in P:
        assert Rij.ispace.volume == 4
예제 #5
0
def main():
    R = pygion.Region(
        [10], {
            'b': pygion.bool_,
            'c64': pygion.complex64,
            'c128': pygion.complex128,
            'f32': pygion.float32,
            'f64': pygion.float64,
            'i8': pygion.int8,
            'i16': pygion.int16,
            'i32': pygion.int32,
            'i64': pygion.int64,
            'u8': pygion.uint8,
            'u16': pygion.uint16,
            'u32': pygion.uint32,
            'u64': pygion.uint64,
        })

    do_local_fills(R)

    pygion.fill(R, 'c64', 5 + 6j)

    print('value of R.c64[0] after remote fill %s' % R.c64[1])

    x = complex_plus_one(3 + 4j)
    print(x.get())
예제 #6
0
def make_region():
    # If you return a region from a task, the privileges to the region
    # will be automatically given to the calling task.
    R = Region([4, 4], {'x': pygion.float64})
    pygion.fill(R, 'x', 0)
    print('returning from make_region with', R)
    return R
예제 #7
0
def main():
    R = Region([4], fspace)
    for field_name in R.keys():
        pygion.fill(R, field_name, 0)
    inc(R, 20)
    check(R, 20)
    mul(R, 3)
    check_except_c128(R, 60)
예제 #8
0
def make_region_dict():
    # It should also work if the region in question is returned as
    # part of a larger data structure.
    R = Region([4, 4], {'x': pygion.float64})
    pygion.fill(R, 'x', 0)
    result = {'asdf': R}
    print('returning from make_region_dict with', result)
    return result
예제 #9
0
def main():
    R = Region([4, 4], {'x': pygion.float64, 'y': pygion.float64})
    pygion.fill(R, 'x', 101)
    pygion.fill(R, 'y', 102)
    init_x(R)
    init_y(R)
    inc(R, 1000)
    saxpy(R, 2)
    check(R)
예제 #10
0
def main():
    R = Region([4, 4], {'x': pygion.float64, 'y': pygion.int32})
    pygion.fill(R, 'x', 1.25)
    pygion.fill(R, 'y', 2)
    inc(R, 20)
    print(R.x)
    print(R.y)
    assert R.x[0, 0] == 21.25
    assert R.y[0, 0] == 22
예제 #11
0
def main():
    R = pygion.Region([4, 4], {'x': pygion.float64})
    pygion.fill(R, 'x', 0)
    P = pygion.Partition.equal(R, [2, 2])
    hello_subregion(P[0, 0])  # this should work
    try:
        hello_subregion(P)  # this should fail
    except TypeError:
        print('Test passed')
    else:
        assert False, 'Test failed'
예제 #12
0
def main():
    R = pygion.Region([4], {'x': pygion.float64})
    P = pygion.Partition.equal(R, [4])
    pygion.fill(R, 'x', 0)

    hello2(P[0], 0)

    for i in pygion.IndexLaunch([4]):
        hello2(P[i], i)

    pygion.index_launch([4], hello2, P[ID], ID)

    # FIXME: This is needed in nopaint to avoid a race with region deletion
    pygion.execution_fence()
예제 #13
0
def main():
    R = Region([4, 4], {'x': pygion.float64})
    P = Partition.equal(R, [2, 2])
    pygion.fill(R, 'x', 0)

    trace1 = Trace()
    for t in range(5):
        with trace1:
            for i in IndexLaunch([2, 2]):
                look(R, i)

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

    trace2 = Trace()
    for t in range(5):
        with trace2:
            index_launch([2, 2], look, R, ID)
            index_launch([2, 2], incr, P[ID], ID)
예제 #14
0
def main():
    print('hello from Python')
    x = hello(1234, 3.14)
    print('Python got result from Regent task: %s' % x.get())

    print('creating a field space with two fields')
    # Note: Need to use OrderedDict so that the field ordering matches Regent.
    fs = Fspace(OrderedDict([('x', pygion.float64), ('y', pygion.float64)]))

    print('creating a region with 12 elements')
    r = Region([12], fs)

    pygion.fill(r, 'x', 1)
    pygion.fill(r, 'y', 2)

    a = 1.5

    print('calling SAXPY task in Regent')
    saxpy(r, a)

    check(r)
예제 #15
0
파일: copy.py 프로젝트: sanidhya/legion
def main():
    R = Region([4, 4], {'x': pygion.int32, 'y': pygion.int32, 'z': pygion.int32, 'w': pygion.int32})
    pygion.fill(R, 'x', 1)
    pygion.fill(R, 'y', 20)
    pygion.fill(R, ['z', 'w'], 100)

    pygion.copy(R, ['x', 'y'], R, ['z', 'w'], redop='+')
    pygion.copy(R, 'x', R, 'y', redop='+')
    pygion.copy(R, 'y', R, 'x')

    assert R.x[0, 0] == 21
    assert R.y[0, 0] == 21
    assert R.z[0, 0] == 101
    assert R.w[0, 0] == 120
예제 #16
0
파일: stencil.py 프로젝트: stkaplan/legion
def main():
    print_once('Running stencil.py')

    conf = parse_args(pygion.input_args(True))

    nbloated = np.array([conf.nx, conf.ny])
    nt = np.array([conf.ntx, conf.nty])
    init = conf.init

    n = nbloated - 2 * RADIUS
    assert np.all(n >= nt), "grid too small"

    grid = Ispace(n + nt * 2 * RADIUS)
    tiles = Ispace(nt)

    point = Fspace(OrderedDict([
        ('input', DTYPE),
        ('output', DTYPE),
    ]))

    points = Region(grid, point)

    private = make_private_partition(points, tiles, n, nt)
    interior = make_interior_partition(points, tiles, n, nt)
    exterior = make_exterior_partition(points, tiles, n, nt)

    xm = Region([nt[0] * RADIUS, n[1]], point)
    xp = Region([nt[0] * RADIUS, n[1]], point)
    ym = Region([n[0], nt[1] * RADIUS], point)
    yp = Region([n[0], nt[1] * RADIUS], point)
    pxm_in = make_ghost_x_partition(xm, tiles, n, nt, -1)
    pxp_in = make_ghost_x_partition(xp, tiles, n, nt, 1)
    pym_in = make_ghost_y_partition(ym, tiles, n, nt, -1)
    pyp_in = make_ghost_y_partition(yp, tiles, n, nt, 1)
    pxm_out = make_ghost_x_partition(xm, tiles, n, nt, 0)
    pxp_out = make_ghost_x_partition(xp, tiles, n, nt, 0)
    pym_out = make_ghost_y_partition(ym, tiles, n, nt, 0)
    pyp_out = make_ghost_y_partition(yp, tiles, n, nt, 0)

    init = conf.init

    for r in [points, xm, xp, ym, yp]:
        for f in ['input', 'output']:
            pygion.fill(r, f, init)

    tsteps = conf.tsteps + 2 * conf.tprune
    tprune = conf.tprune

    trace = Trace()
    for t in range(tsteps):
        if t == tprune:
            pygion.execution_fence(block=True)
            start_time = pygion.c.legion_get_current_time_in_nanos()
        with trace:
            if _constant_time_launches:
                index_launch(tiles, stencil, private[ID], interior[ID],
                             pxm_in[ID], pxp_in[ID], pym_in[ID], pyp_in[ID],
                             False)
                index_launch(tiles, increment, private[ID], exterior[ID],
                             pxm_out[ID], pxp_out[ID], pym_out[ID],
                             pyp_out[ID], False)
            else:
                for i in IndexLaunch(tiles):
                    stencil(private[i], interior[i], pxm_in[i], pxp_in[i],
                            pym_in[i], pyp_in[i], False)
                for i in IndexLaunch(tiles):
                    increment(private[i], exterior[i], pxm_out[i], pxp_out[i],
                              pym_out[i], pyp_out[i], False)
        if t == tsteps - tprune - 1:
            pygion.execution_fence(block=True)
            stop_time = pygion.c.legion_get_current_time_in_nanos()

    if _constant_time_launches:
        index_launch(tiles, check, private[ID], interior[ID], tsteps, init)
    else:
        for i in IndexLaunch(tiles):
            check(private[i], interior[i], tsteps, init)

    print_once('ELAPSED TIME = %7.3f s' % ((stop_time - start_time) / 1e9))
예제 #17
0
def main():
    R = pygion.Region([0, 0], {'x': pygion.float64})
    pygion.fill(R, 'x', 3.14)

    hello(R)
예제 #18
0
def main():
    print_once('Running pennant_fast.py')

    conf = read_config().get()

    zone = Fspace(
        OrderedDict([
            ('zxp_x', pygion.float64),
            ('zxp_y', pygion.float64),
            ('zx_x', pygion.float64),
            ('zx_y', pygion.float64),
            ('zareap', pygion.float64),
            ('zarea', pygion.float64),
            ('zvol0', pygion.float64),
            ('zvolp', pygion.float64),
            ('zvol', pygion.float64),
            ('zdl', pygion.float64),
            ('zm', pygion.float64),
            ('zrp', pygion.float64),
            ('zr', pygion.float64),
            ('ze', pygion.float64),
            ('zetot', pygion.float64),
            ('zw', pygion.float64),
            ('zwrate', pygion.float64),
            ('zp', pygion.float64),
            ('zss', pygion.float64),
            ('zdu', pygion.float64),
            ('zuc_x', pygion.float64),
            ('zuc_y', pygion.float64),
            ('z0tmp', pygion.float64),
            ('znump', pygion.uint8),
        ]))

    point = Fspace(
        OrderedDict([
            ('px0_x', pygion.float64),
            ('px0_y', pygion.float64),
            ('pxp_x', pygion.float64),
            ('pxp_y', pygion.float64),
            ('px_x', pygion.float64),
            ('px_y', pygion.float64),
            ('pu0_x', pygion.float64),
            ('pu0_y', pygion.float64),
            ('pu_x', pygion.float64),
            ('pu_y', pygion.float64),
            ('pap_x', pygion.float64),
            ('pap_y', pygion.float64),
            ('pf_x', pygion.float64),
            ('pf_y', pygion.float64),
            ('pmaswt', pygion.float64),
            ('has_bcx', pygion.bool_),
            ('has_bcy', pygion.bool_),
        ]))

    side = Fspace(
        OrderedDict([
            ('mapsz', pygion.int1d),
            ('mapsp1', pygion.int1d),
            ('mapsp1_r', pygion.uint8),
            ('mapsp2', pygion.int1d),
            ('mapsp2_r', pygion.uint8),
            ('mapss3', pygion.int1d),
            ('mapss4', pygion.int1d),
            ('sareap', pygion.float64),
            ('sarea', pygion.float64),
            ('svolp', pygion.float64),
            ('svol', pygion.float64),
            ('ssurfp_x', pygion.float64),
            ('ssurfp_y', pygion.float64),
            ('smf', pygion.float64),
            ('sfp_x', pygion.float64),
            ('sfp_y', pygion.float64),
            ('sft_x', pygion.float64),
            ('sft_y', pygion.float64),
            ('sfq_x', pygion.float64),
            ('sfq_y', pygion.float64),
            ('exp_x', pygion.float64),
            ('exp_y', pygion.float64),
            ('ex_x', pygion.float64),
            ('ex_y', pygion.float64),
            ('elen', pygion.float64),
            ('carea', pygion.float64),
            ('cevol', pygion.float64),
            ('cdu', pygion.float64),
            ('cdiv', pygion.float64),
            ('ccos', pygion.float64),
            ('cqe1_x', pygion.float64),
            ('cqe1_y', pygion.float64),
            ('cqe2_x', pygion.float64),
            ('cqe2_y', pygion.float64),
        ]))

    span = Fspace(
        OrderedDict([
            ('start', pygion.int64),
            ('stop', pygion.int64),
            ('internal', pygion.bool_),
        ]))

    zones = Region([conf.nz], zone)
    points = Region([conf.np], point)
    sides = Region([conf.ns], side)

    assert conf.par_init, 'parallel initialization required'

    old_seq_init = conf.seq_init
    if conf.seq_init:
        print('Warning: Sequential initialization not supported, skipping')
        # Since we aren't actually doing sequential intialization, we
        # have to turn this off or the verification in parallel
        # initialization will fail.
        conf.seq_init = False

    assert conf.par_init
    partitions = read_partitions(zones, points, sides, conf).get()

    conf.nspans_zones = partitions.nspans_zones
    conf.nspans_points = partitions.nspans_points

    pieces = Ispace([conf.npieces])

    zones_part = create_partition(True, zones, partitions.rz_all_p, pieces)

    points_part = create_partition(True, points, partitions.rp_all_p, [2])
    private = points_part[0]
    ghost = points_part[1]

    private_part = create_partition(True, private, partitions.rp_all_private_p,
                                    pieces)
    ghost_part = create_partition(False, ghost, partitions.rp_all_ghost_p,
                                  pieces)
    shared_part = create_partition(True, ghost, partitions.rp_all_shared_p,
                                   pieces)

    sides_part = create_partition(True, sides, partitions.rs_all_p, pieces)

    zone_spans = Region([conf.npieces * conf.nspans_zones], span)
    zone_spans_part = Partition.equal(zone_spans, pieces)

    private_spans = Region([conf.npieces * conf.nspans_points], span)
    private_spans_part = Partition.equal(private_spans, pieces)

    shared_spans = Region([conf.npieces * conf.nspans_points], span)
    shared_spans_part = Partition.equal(shared_spans, pieces)

    side_spans = Region([conf.npieces * conf.nspans_zones], span)
    side_spans_part = Partition.equal(side_spans, pieces)

    for region in [zone_spans, private_spans, shared_spans, side_spans]:
        for field in ['start', 'stop']:
            pygion.fill(region, field, 0)

    if old_seq_init:
        # FIXME: These fields are actually never used, fill them here
        # just to avoid validation errors later.
        pygion.fill(points, 'pap_x', 0)
        pygion.fill(points, 'pap_y', 0)
        pygion.fill(sides, 'svolp', 0)
        pygion.fill(sides, 'svol', 0)
        pygion.fill(sides, 'ssurfp_x', 0)
        pygion.fill(sides, 'ssurfp_y', 0)

    if conf.par_init:
        for i in IndexLaunch(pieces):
            initialize_topology(conf, int(i), zones_part[i], private_part[i],
                                shared_part[i], ghost_part[i], sides_part[i])

        for i in IndexLaunch(pieces):
            initialize_spans(conf, int(i), zone_spans_part[i],
                             private_spans_part[i], shared_spans_part[i],
                             side_spans_part[i])

    for i in IndexLaunch(pieces):
        init_pointers(zones_part[i], private_part[i], ghost_part[i],
                      sides_part[i], side_spans_part[i])

    for i in IndexLaunch(pieces):
        init_mesh_zones(zones_part[i], zone_spans_part[i])

    for i in IndexLaunch(pieces):
        calc_centers_full(zones_part[i], private_part[i], ghost_part[i],
                          sides_part[i], side_spans_part[i], True)

    for i in IndexLaunch(pieces):
        calc_volumes_full(zones_part[i], private_part[i], ghost_part[i],
                          sides_part[i], side_spans_part[i], True)

    for i in IndexLaunch(pieces):
        init_side_fracs(zones_part[i], private_part[i], ghost_part[i],
                        sides_part[i], side_spans_part[i])

    for i in IndexLaunch(pieces):
        init_hydro(zones_part[i], zone_spans_part[i], conf.rinit, conf.einit,
                   conf.rinitsub, conf.einitsub, conf.subregion[0],
                   conf.subregion[1], conf.subregion[2], conf.subregion[3])

    for i in IndexLaunch(pieces):
        init_radial_velocity(private_part[i], private_spans_part[i],
                             conf.uinitradial)

    for i in IndexLaunch(pieces):
        init_radial_velocity(shared_part[i], shared_spans_part[i],
                             conf.uinitradial)

    cycle = 0
    cstop = conf.cstop + 2 * conf.prune
    time = 0.0
    dt = Future(conf.dtmax, pygion.float64)
    dthydro = conf.dtmax
    while cycle < cstop and time < conf.tstop:
        if cycle == conf.prune:
            pygion.execution_fence(block=True)
            start_time = pygion.c.legion_get_current_time_in_nanos()

        dt = calc_global_dt(dt, conf.dtfac, conf.dtinit, conf.dtmax, dthydro,
                            time, conf.tstop, cycle)

        for i in IndexLaunch(pieces):
            adv_pos_half(private_part[i], private_spans_part[i], dt, True,
                         False)

        for i in IndexLaunch(pieces):
            adv_pos_half(shared_part[i], shared_spans_part[i], dt, True, False)

        for i in IndexLaunch(pieces):
            calc_everything(zones_part[i], private_part[i], ghost_part[i],
                            sides_part[i], zone_spans_part[i],
                            side_spans_part[i], conf.alfa, conf.gamma,
                            conf.ssmin, dt, conf.q1, conf.q2, True)

        for i in IndexLaunch(pieces):
            adv_pos_full(private_part[i], private_spans_part[i], dt, True)

        for i in IndexLaunch(pieces):
            adv_pos_full(shared_part[i], shared_spans_part[i], dt, True)

        for i in IndexLaunch(pieces):
            calc_everything_full(zones_part[i], private_part[i], ghost_part[i],
                                 sides_part[i], zone_spans_part[i],
                                 side_spans_part[i], dt, True)

        futures = []
        for i in IndexLaunch(pieces):
            futures.append(
                calc_dt_hydro(zones_part[i], zone_spans_part[i], dt,
                              conf.dtmax, conf.cfl, conf.cflv, True, False))

        dthydro = conf.dtmax
        dthydro = min(dthydro, *list(map(lambda x: x.get(), futures)))

        cycle += 1
        time += dt.get()

        if cycle == conf.cstop - conf.prune:
            pygion.execution_fence(block=True)
            stop_time = pygion.c.legion_get_current_time_in_nanos()

    if old_seq_init:
        validate_output_sequential(zones, points, sides, conf)
    else:
        print_once("Warning: Skipping sequential validation")

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