Translation Units

class loopy.translation_unit.FunctionIdT

A type for a function identifier. A ReductionOpFunction or a str.

class loopy.translation_unit.CallablesTable

A type alias for callables tables, mapping from FunctionIdT to InKernelCallable

class loopy.TranslationUnit(callables_table: Map[str | ReductionOpFunction, InKernelCallable], target: TargetBase, entrypoints: FrozenSet[str])[source]

Records the information about all the callables in a loopy program.

An instance of TranslationUnit is the object that gets lowered for a


A frozenset of the names of the kernels which could be called from the host.


The LoopKernel representing the main entrypoint of the program, if defined. Currently, this attribute may only be accessed if there is exactly one entrypoint in the translation unit.


An instance of pyrsistent.PMap mapping the function identifiers in a kernel to their associated instances of InKernelCallable.


An instance of


A frozenset of functions of the signature (target: TargetBase, function_indentifier: str) that returns an instance of loopy.kernel.function_interface.InKernelCallable or None.

executor(*args, entrypoint: str | None = None, **kwargs) ExecutorBase[source]

Return an object that hosts caches of compiled code for execution (i.e. a subclass of ExecutorBase, specific to an execution environment (e.g. an OpenCL context) and a given entrypoint.


entrypoint – The name of the entrypoint callable to be called. Defaults to default_entrypoint. An error will result if multiple entrypoints exist and no entrypoint is specified.

The variable arguments to this are target-specific. The PyOpenCLTarget takes a Context or a CommandQueue.

__call__(*args, **kwargs)[source]

Builds and calls the entrypoint kernel, if is an executable target.


entrypoint – The name of the entrypoint callable to be called. Defaults to default_entrypoint.


While this was the main execution interface for loopy for many years (and reasonably efficient), the caches that made this so kept lots of expensive ‘stuff’ (such as OpenCL contexts) alive for no good reason, leading to major inefficiencies. See executor() for an efficient, cached way to invoke kernels.


For the callable named name, return a loopy.LoopKernel if it’s a CallableKernel otherwise return the callable itself.


If self contains a callable kernel with kernel’s name, replaces its subkernel and returns a copy of self. Else records a new callable kernel with kernel as its subkernel.


kernel – An instance of loopy.LoopKernel.


Copy of self with updated callable kernels.


class loopy.translation_unit.CallablesInferenceContext(callables: ~typing.Mapping[str, ~loopy.kernel.function_interface.InKernelCallable], clbl_name_gen: ~typing.Callable[[str], str], renames: ~typing.Mapping[str, ~typing.FrozenSet[str]] = <factory>, new_entrypoints: ~typing.FrozenSet[str] = frozenset({}))[source]

Helper class for housekeeping a loopy.TranslationUnit.callables_table while traversing through callables of loopy.TranslationUnit.


A mapping from the callable names to instances of loopy.kernel.function_interface.InKernelCallable.


A mapping from old function identifiers to a frozenset of new function identifiers.


A frozenset of renamed entrypoint names.

with_callable(old_function_id, new_clbl, is_entrypoint=False)[source]

Updates the callable referred by function_id’s in self’s namespace to new_clbl.


(new_self, new_function_id) is a copy of self with new_clbl in its namespace. new_clbl would be referred by new_function_id in new_self’s namespace.


Returns a copy of program with rollback renaming of the callables done whenever possible.

For example: If all the sin function ids diverged as sin_0, sin_1, then all the renaming is done such that one of the flavors of the callable is renamed back to sin.

loopy.translation_unit.make_program(kernel: LoopKernel) TranslationUnit[source]

Returns an instance of loopy.TranslationUnit with kernel as the only callable kernel.


Function wrapper for transformations of the type transform(kernel: LoopKernel, *args, **kwargs) -> LoopKernel. Returns a function that would apply transform to all callable kernels in a loopy.TranslationUnit.