How to use the pytools.ImmutableRecord function in pytools

To help you get started, we’ve selected a few pytools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github inducer / loopy / loopy / schedule / __init__.py View on Github external
self.elapsed_store += time()-self.start_time

    def start(self):
        from time import time
        self.start_time = time()


class ScheduleDebugInput(Exception):
    pass

# }}}


# {{{ scheduling algorithm

class SchedulerState(ImmutableRecord):
    """
    .. attribute:: kernel

    .. attribute:: loop_nest_around_map

    .. attribute:: loop_priority

        See :func:`loop_nest_around_map`.

    .. attribute:: breakable_inames

    .. attribute:: ilp_inames

    .. attribute:: vec_inames

    .. attribute:: parallel_inames
github inducer / loopy / loopy / schedule / __init__.py View on Github external
def __init__(self, source, target, dep_descr, variable, var_kind):
        ImmutableRecord.__init__(self,
                source=source,
                target=target,
                dep_descr=dep_descr,
                variable=variable,
                var_kind=var_kind)
github inducer / loopy / loopy / schedule / __init__.py View on Github external
def __init__(self, source, target, dep_descr, variable, var_kind):
        ImmutableRecord.__init__(self,
                source=source,
                target=target,
                dep_descr=dep_descr,
                variable=variable,
                var_kind=var_kind)
github inducer / loopy / loopy / program.py View on Github external
resolved_function_marker.map_kernel(kernel))
    # collect the update callables_table
    callables_table = resolved_function_marker.callables_table

    callable_kernel = CallableKernel(kernel_with_functions_resolved)

    # add the callable kernel to the callables_table
    callables_table, _ = callables_table.with_added_callable(
            Variable(kernel.name), callable_kernel)

    return callables_table


# {{{ program

class Program(ImmutableRecord):
    """
    Records the information about all the callables in a :mod:`loopy` program.

    .. attribute:: name

        An instance of :class:`str`, also the name of the top-most level
        :class:`loopy.LoopKernel`.

    .. attribute:: callables_table

        An instance of :class:`loopy.program.CallablesTable`.

    .. attribute:: target

        An instance of :class:`loopy.target.TargetBase`.
github inducer / loopy / loopy / kernel / __init__.py View on Github external
# Kill all variable dependencies
            dom_intersect_assumptions = dom_intersect_assumptions.project_out_except(
                    [iname], [dim_type.param, dim_type.set])

        iname_idx = dom_intersect_assumptions.get_var_dict()[iname][1]

        lower_bound_pw_aff = (
                self.cache_manager.dim_min(
                    dom_intersect_assumptions, iname_idx)
                .coalesce())
        upper_bound_pw_aff = (
                self.cache_manager.dim_max(
                    dom_intersect_assumptions, iname_idx)
                .coalesce())

        class BoundsRecord(ImmutableRecord):
            pass

        size = (upper_bound_pw_aff - lower_bound_pw_aff + 1)
        size = size.gist(assumptions)

        return BoundsRecord(
                lower_bound_pw_aff=lower_bound_pw_aff,
                upper_bound_pw_aff=upper_bound_pw_aff,
                size=size)
github inducer / loopy / loopy / kernel / data.py View on Github external
def update_persistent_hash(self, key_hash, key_builder):
        """Custom hash computation function for use with
        :class:`pytools.persistent_dict.PersistentDict`.
        """

        key_builder.rec(key_hash, self.name)
        key_builder.rec(key_hash, self.arguments)
        key_builder.update_for_pymbolic_expression(key_hash, self.expression)

# }}}


# {{{ function call mangling

class CallMangleInfo(ImmutableRecord):
    """
    .. attribute:: target_name

        A string. The name of the function to be called in the
        generated target code.

    .. attribute:: result_dtypes

        A tuple of :class:`LoopyType` instances indicating what
        types of values the function returns.

    .. attribute:: arg_dtypes

        A tuple of :class:`LoopyType` instances indicating what
        types of arguments the function actually receives.
    """
github OP2 / PyOP2 / pyop2 / gpu / tile.py View on Github external
assert tv.address_space != lp.AddressSpace.PRIVATE
    arg = lp.ArrayArg(
            name=tv.name,
            dtype=tv.dtype,
            shape=tv.shape,
            dim_tags=tv.dim_tags,
            offset=tv.offset,
            dim_names=tv.dim_names,
            order=tv.order,
            alignment=tv.alignment,
            address_space=tv.address_space,
            is_output_only=not tv.read_only)
    return arg


class KernelMetadata(ImmutableRecord):
    def __init__(self, **kwargs):
        assert isinstance(kwargs['quad_iname'], str)
        assert isinstance(kwargs['doF_inames_in_quad_stage2inputDoFs'], dict)
        assert isinstance(kwargs['coords'], str)
        assert isinstance(kwargs['outputDoF'], str)
        assert isinstance(kwargs['outputDoF_init_iname'], str)
        assert isinstance(kwargs['doF_inames_in_quad_stage'], list)
        assert isinstance(kwargs['doF_iname_in_basis_stage'], str)
        assert isinstance(kwargs['scatter_iname'], str)
        assert isinstance(kwargs['nquad'], int)
        assert isinstance(kwargs['n_inputDoFs'], list)
        assert isinstance(kwargs['n_outputDoF'], int)
        assert isinstance(kwargs["op_matrices"], frozenset)
        assert isinstance(kwargs["quad_weights"], str)
        assert isinstance(kwargs["matvec_stage_to_op_matrices"], list)
        assert isinstance(kwargs["evaluation_variables"], frozenset)
github inducer / loopy / loopy / symbolic.py View on Github external
dep_mapper = DependencyMapper(composite_leaves=False)
    return frozenset(dep.name for dep in dep_mapper(expr))


# {{{ rule-aware mappers

def parse_tagged_name(expr):
    if isinstance(expr, TaggedVariable):
        return expr.name, expr.tag
    elif isinstance(expr, p.Variable):
        return expr.name, None
    else:
        raise RuntimeError("subst rule name not understood: %s" % expr)


class ExpansionState(ImmutableRecord):
    """
    .. attribute:: kernel
    .. attribute:: instruction

    .. attribute:: stack

        a tuple representing the current expansion stack, as a tuple
        of (name, tag) pairs.

    .. attribute:: arg_context

        a dict representing current argument values
    """

    @property
    def insn_id(self):
github inducer / loopy / loopy / transform / callable.py View on Github external
[func_id_to_in_knl_callable_mapper])

    program = _resolve_callables_from_function_lookup(program,
            func_id_to_in_knl_callable_mapper)

    new_program = program.copy(
            func_id_to_in_knl_callable_mappers=new_func_id_mappers)

    return new_program

# }}}


# {{{ register_callable_kernel

class _RegisterCalleeKernel(ImmutableRecord):
    """
    Helper class to make the function scoper from
    :func:`loopy.transform.register_callable_kernel` picklable. As python
    cannot pickle lexical closures.
    """
    fields = set(['callable_kernel'])

    def __init__(self, callable_kernel):
        self.callable_kernel = callable_kernel

    def __call__(self, target, identifier):
        if identifier == self.callable_kernel.subkernel.name:
            return self.callable_kernel
        return None
github inducer / loopy / loopy / schedule / __init__.py View on Github external
result.append(Barrier(
                    kind=insn.kind,
                    originating_insn_id=insn.id,
                    comment="Barrier inserted due to %s" % insn.id))
                continue

        result.append(sched_item)

    return result

# }}}


# {{{ barrier insertion/verification

class DependencyRecord(ImmutableRecord):
    """
    .. attribute:: source

        A :class:`loopy.InstructionBase` instance.

    .. attribute:: target

        A :class:`loopy.InstructionBase` instance.

    .. attribute:: dep_descr

        A string containing a phrase describing the dependency. The variables
        '{src}' and '{tgt}' will be replaced by their respective instruction IDs.

    .. attribute:: variable