from legion import index_launch, print_once, task, Fspace, Future, IndexLaunch, Ipartition, Ispace, ID, N, Partition, R, Reduce, Region, RW root_dir = os.path.dirname(__file__) try: prefix_dir = legion.prefix_dir except AttributeError: prefix_dir, legion_h_path = legion.find_legion_header() pennant_header = subprocess.check_output([ "gcc", "-I", prefix_dir, "-DLEGION_USE_PYTHON_CFFI", "-E", "-P", os.path.join(root_dir, "pennant_config.h") ]).decode("utf-8") ffi = legion.ffi ffi.cdef(pennant_header) mesh_colorings = legion.Type( np.dtype([('bytes', np.void, ffi.sizeof('mesh_colorings'))]), 'mesh_colorings') 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)
from __future__ import print_function import legion from legion import task, Future, Region, RW import numpy # Define a custom struct type. legion.ffi.cdef(r''' typedef struct mystruct { int x; double y; int8_t z; } mystruct; ''') mystruct_np = numpy.dtype([('x', numpy.intc), ('y', numpy.double), ('z', numpy.byte)], align=True) mystruct = legion.Type(mystruct_np, 'mystruct') @task def main(): myvalue_root = legion.ffi.new('mystruct *') myvalue = myvalue_root[0] myvalue.x = 123 myvalue.y = 3.14 myvalue.z = 65 # Make a future with the custom struct type. g = Future(myvalue, mystruct) print("value of g.get() is %s" % g.get()) assert g.get().x == 123 # Make a region with the custom struct type.
import numpy as np import os import subprocess import legion from legion import disjoint_complete, index_launch, task, Domain, Fspace, Ispace, IndexLaunch, ID, Partition, N, R, Reduce, Region, RW, WD root_dir = os.path.dirname(__file__) circuit_header = subprocess.check_output([ "gcc", "-D", "__attribute__(x)=", "-E", "-P", os.path.join(root_dir, "circuit_config.h") ]).decode("utf-8") ffi = legion.ffi ffi.cdef(circuit_header) Config = legion.Type(np.dtype([('bytes', np.void, ffi.sizeof('Config'))]), 'Config') def parse_args(argv): parser = argparse.ArgumentParser(argv[0]) parser.add_argument('-l', dest='num_loops', type=int, default=5) parser.add_argument('-p', dest='num_pieces', type=int, default=4) parser.add_argument('-pps', dest='pieces_per_superpiece', type=int, default=1) parser.add_argument('-npp', dest='nodes_per_piece', type=int, default=4) parser.add_argument('-wpp', dest='wires_per_piece', type=int, default=8) parser.add_argument('-pct', dest='pct_wire_in_piece', type=int, default=80) parser.add_argument('-s', dest='random_seed', type=int, default=12345) parser.add_argument('-i', dest='steps', type=int, default=10000)
import sys import time import legion from legion import index_launch, task, Domain, Fspace, Ispace, ID, Partition, R, Region, RW, Trace, WD root_dir = os.path.dirname(os.path.dirname(__file__)) core_header = subprocess.check_output([ "gcc", "-D", "__attribute__(x)=", "-E", "-P", os.path.join(root_dir, "core/core_c.h") ]).decode("utf-8") ffi = legion.ffi ffi.cdef(core_header) c = legion.c task_graph = legion.Type( np.dtype([('bytes', np.void, ffi.sizeof('task_graph_t'))]), 'task_graph_t') max_fields = 2 max_args = 5 use_native = os.environ.get('TASK_BENCH_USE_NATIVE') == '1' def once_only(): return c.legion_context_get_shard_id(legion._my.ctx.runtime, legion._my.ctx.context, True) == 0 def app_create(args): c_args = [] c_argv = ffi.new("char *[]", len(args) + 1)