Exemple #1
0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from __future__ import print_function

from collections import OrderedDict
import legion

# FIXME: Need a better way to determine task IDs.
hello = legion.extern_task(
    task_id=10000,
    argument_types=[legion.int64, legion.float64],
    return_type=legion.int64,
    calling_convention='regent')

saxpy = legion.extern_task(
    task_id=10001,
    argument_types=[legion.Region, legion.float64],
    privileges=[legion.RW],
    calling_convention='regent')

@legion.task(task_id=2)
def main():
    print('hello from Python')
    x = hello(1234, 3.14)
    print('Python got result from Regent task: %s' % x.get())
Exemple #2
0

def create_partition(is_disjoint, region, c_partition, color_space):
    ipart = Ipartition(c_partition.index_partition, region.ispace, color_space)
    return Partition(region, ipart)


_constant_time_launches = False
if _constant_time_launches:
    extern_task = legion.extern_task_wrapper
else:
    extern_task = legion.extern_task

read_config = legion.extern_task(task_id=10000,
                                 argument_types=[],
                                 privileges=[],
                                 return_type=config,
                                 calling_convention='regent')

read_partitions = legion.extern_task(
    task_id=10001,
    argument_types=[Region, Region, Region, config],
    privileges=[N, N, N],
    return_type=mesh_partitions,
    calling_convention='regent')

initialize_topology = extern_task(task_id=10003,
                                  argument_types=[
                                      config, legion.int64, Region, Region,
                                      Region, Region, Region
                                  ],
Exemple #3
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from __future__ import print_function

from collections import OrderedDict
import legion

# FIXME: Need a better way to determine task IDs.
hello = legion.extern_task(task_id=10000,
                           argument_types=[legion.int64, legion.float64],
                           return_type=legion.int64,
                           calling_convention='regent')

saxpy = legion.extern_task(task_id=10001,
                           argument_types=[legion.Region, legion.float64],
                           privileges=[legion.RW],
                           calling_convention='regent')


@legion.task(task_id=2)
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')
Exemple #4
0
                        dest='num_neighbors',
                        type=int,
                        default=5)
    parser.add_argument('-window', dest='window', type=int, default=3)
    args = parser.parse_args(argv[1:])

    conf = ffi.new('Config *')
    for field, value in vars(args).items():
        setattr(conf, field, value)
    return conf


init_piece = legion.extern_task(task_id=10002,
                                argument_types=[
                                    legion.int32, Config, Region, Region,
                                    Region, Region, Region
                                ],
                                privileges=[None, None, WD, WD, WD, N, WD],
                                return_type=legion.void,
                                calling_convention='regent')

init_pointers = legion.extern_task(
    task_id=10003,
    argument_types=[Region, Region, Region, Region],
    privileges=[N, N, N,
                RW('in_ptr', 'in_ptr_r', 'out_ptr', 'out_ptr_r')],
    return_type=legion.void,
    calling_convention='regent')

calculate_new_currents = legion.extern_task(
    task_id=10004,
    argument_types=[
Exemple #5
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from __future__ import print_function

import legion
from legion import task, Fspace, IndexLaunch, Ispace, Region, RW
import numpy

# This task is defined in C++. See init_task in python_interop.cc.
init = legion.extern_task(task_id=3, privileges=[RW], return_type=legion.int64)


@task
def hello(i, j):
    print('hello %s %s' % (i, j))


# Define a Python task. This task takes two arguments: a region and a
# number, and increments every element of the region by that number.
@task(privileges=[RW])
def inc(R, step):
    # The fields of regions are numpy arrays, so you can call normal
    # numpy methods on them. Be careful about where the output is
    # directed if you want to avoid making extra copies of the data.
    print(R.x)
Exemple #6
0
mesh_partitions = legion.Type(
    np.dtype([('bytes', np.void, ffi.sizeof('mesh_partitions'))]),
    'mesh_partitions')

config = legion.Type(np.dtype([('bytes', np.void, ffi.sizeof('config'))]),
                     'config')


def create_partition(is_disjoint, region, c_partition, color_space):
    ipart = Ipartition(c_partition.index_partition, region.ispace, color_space)
    return Partition(region, ipart)


read_config = legion.extern_task(task_id=10000,
                                 argument_types=[],
                                 privileges=[],
                                 return_type=config,
                                 calling_convention='regent')

read_partitions = legion.extern_task(
    task_id=10001,
    argument_types=[Region, Region, Region, config],
    privileges=[N, N, N],
    return_type=mesh_partitions,
    calling_convention='regent')

initialize_spans = legion.extern_task(
    task_id=10002,
    argument_types=[config, legion.int64, Region, Region, Region, Region],
    privileges=[None, None, RW, RW, RW, RW],
    return_type=legion.void,
Exemple #7
0
        scratch_ptr = ffi.NULL
        scratch_size = 0

    c.task_graph_execute_point_scratch(graph, timestep, point, output_ptr,
                                       output_size, input_ptrs, input_sizes,
                                       len(inputs), scratch_ptr, scratch_size)


# Hack: Not sure it's possible to generate these programmatically, so
# until Legion supports variadic tasks this is what we have to do.

if use_native:
    execute_point_task_0_0 = legion.extern_task(
        task_id=2,
        argument_types=[
            task_graph, legion.uint32, legion.int32, legion.int32, Region
        ] + [Region] * 0,
        privileges=[None, None, None, None, RW('1')] + [R('0')] * 0,
        calling_convention='regent')
    execute_point_task_0_1 = legion.extern_task(
        task_id=3,
        argument_types=[
            task_graph, legion.uint32, legion.int32, legion.int32, Region
        ] + [Region] * 1,
        privileges=[None, None, None, None, RW('1')] + [R('0')] * 1,
        calling_convention='regent')
    execute_point_task_0_2 = legion.extern_task(
        task_id=4,
        argument_types=[
            task_graph, legion.uint32, legion.int32, legion.int32, Region
        ] + [Region] * 2,
Exemple #8
0
    ['gcc', '-E', '-P', native_kernels_h_path]).decode('utf-8')
lifeline_mapper_header = subprocess.check_output(
    ['gcc', '-E', '-P', lifeline_mapper_h_path]).decode('utf-8')

ffi = cffi.FFI()
ffi.cdef(native_kernels_header)
ffi.cdef(lifeline_mapper_header)
c = ffi.dlopen(native_kernels_so_path)

memory_bound_task_id = 101
cache_bound_task_id = 102
sum_task_id = 103
c.register_native_kernels_tasks(memory_bound_task_id, cache_bound_task_id,
                                sum_task_id)

memory_bound_task = legion.extern_task(task_id=memory_bound_task_id)
cache_bound_task = legion.extern_task(task_id=cache_bound_task_id)
sum_task = legion.extern_task(task_id=sum_task_id, privileges=[legion.RO])

if legion.is_script:
    print('WARNING: unable to set mapper in script mode')
else:
    c.register_lifeline_mapper()

kernel_kind = os.environ.get('KERNEL_KIND')
kernel_uses_raw = False
if kernel_kind == 'memory':
    kernel = memory_bound_task
elif kernel_kind == 'cachex':
    kernel = cache_bound_task
elif kernel_kind == 'sum':
Exemple #9
0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from __future__ import print_function

import legion

# FIXME: Need a better way to determine task IDs.
hello = legion.extern_task(task_id=10000,
                           argument_types=(legion.int64, legion.float64),
                           return_type=legion.int64,
                           calling_convention='regent')


@legion.task(task_id=2)
def main():
    print('hello from Python')
    x = hello(1234, 3.14)
    print('Python got result from Regent task: %s' % x.get())
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from __future__ import print_function

import legion
import numpy

# This task is defined in C++. See init_task in python_interop.cc.
init = legion.extern_task(task_id=3, privileges=[legion.RW], return_type=legion.int64)

@legion.task
def hello(i, j):
    print('hello %s %s' % (i, j))

# Define a Python task. This task takes two arguments: a region and a
# number, and increments every element of the region by that number.
@legion.task(privileges=[legion.RW])
def inc(R, step):
    # The fields of regions are numpy arrays, so you can call normal
    # numpy methods on them. Be careful about where the output is
    # directed if you want to avoid making extra copies of the data.
    print(R.x)
    numpy.add(R.x, step, out=R.x)
    print(R.x)
Exemple #11
0
        colors.rect[tile] = ([
            idx[0] * n[0] / nt[0],
            clamp((idx[1] + direction) * RADIUS, 0, nt[1] * RADIUS)
        ], [(idx[0] + 1) * n[0] / nt[0] - 1,
            clamp((idx[1] + 1 + direction) * RADIUS - 1, -1,
                  nt[1] * RADIUS - 1)])
    kind = disjoint_complete if direction == 0 else disjoint_incomplete
    return Partition.create_by_image(points, colors_part, 'rect', tiles, kind)


stencil = legion.extern_task(
    task_id=10001,
    argument_types=[
        Region, Region, Region, Region, Region, Region, legion.bool_
    ],
    privileges=[RW, N, R('input'),
                R('input'),
                R('input'),
                R('input')],
    return_type=legion.void,
    calling_convention='regent')

increment = legion.extern_task(task_id=10002,
                               argument_types=[
                                   Region, Region, Region, Region, Region,
                                   Region, legion.bool_
                               ],
                               privileges=[
                                   RW('input'), N,
                                   RW('input'),
                                   RW('input'),
Exemple #12
0
    ['gcc', '-E', '-P', native_kernels_h_path]).decode('utf-8')
lifeline_mapper_header = subprocess.check_output(
    ['gcc', '-E', '-P', lifeline_mapper_h_path]).decode('utf-8')

ffi = cffi.FFI()
ffi.cdef(native_kernels_header)
ffi.cdef(lifeline_mapper_header)
c = ffi.dlopen(native_kernels_so_path)

memory_bound_task_id = 101
cache_bound_task_id = 102
sum_task_id = 103
c.register_native_kernels_tasks(memory_bound_task_id, cache_bound_task_id,
                                sum_task_id)

memory_bound_task = legion.extern_task(task_id=memory_bound_task_id)
cache_bound_task = legion.extern_task(task_id=cache_bound_task_id)
sum_task = legion.extern_task(task_id=sum_task_id,
                              privileges=[legion.RO],
                              return_type=legion.int64)

# if legion.is_script:
#     print('WARNING: unable to set mapper in script mode')
# else:
#     c.register_lifeline_mapper()

kernel_kind = os.environ.get('KERNEL_KIND')
kernel_uses_raw = False
if kernel_kind == 'memory':
    kernel = memory_bound_task
elif kernel_kind == 'cachex':
Exemple #13
0
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from __future__ import print_function

import legion
import numpy

init = legion.extern_task(task_id=3, privileges=[legion.RW])


@legion.task
def f(x, y, z):
    print("inside task f%s" % ((x, y, z), ))
    return x + 1


@legion.task(privileges=[legion.RW], leaf=True)
def inc(R, step):
    print("inside task inc%s" % ((R, step), ))

    # Sanity check that the values written by init are here, and that
    # they follow the same array ordering.
    print(R.x)
Exemple #14
0
    import psana_mpi as psana_legion
    legion = None
else:
    import psana_legion
    import legion

# Get the analysis kernel to perform on each event
kernel_kind = os.environ.get('KERNEL_KIND')
kernel_uses_raw = False
if kernel_kind == 'memory_bound':
    import kernels
    kernel = kernels.make_memory_bound_kernel(
        int(os.environ.get('KERNEL_ROUNDS', 100)))
elif kernel_kind == 'memory_bound_native':
    if legion is not None:
        kernel = legion.extern_task(task_id=2)
    else:
        import native_kernels
        kernel = native_kernels.memory_bound_kernel
elif kernel_kind == 'cache_bound_native':
    if legion is not None:
        kernel = legion.extern_task(task_id=3)
    else:
        import native_kernels
        kernel = native_kernels.cache_bound_kernel
elif kernel_kind == 'sum':
    kernel_uses_raw = True
    if legion is not None:
        kernel = legion.extern_task(task_id=4, privileges=[legion.RO])
    else:
        assert False