TranslationUnit

class loopy.TranslationUnit(entrypoints=frozenset({}), callables_table=None, target=None, func_id_to_in_knl_callable_mappers=None)[source]

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

An instance of TranslationUnit is the object that gets lowered for a loopy.target.TargetBase.

entrypoints

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

default_entrypoint

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.

callables_table

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

target

An instance of loopy.target.TargetBase.

func_id_to_in_knl_callables_mappers

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

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

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

Parameters

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

copy(**kwargs)[source]
__getitem__(name)[source]

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

with_kernel(kernel)[source]

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.

Parameters

kernel – An instance of loopy.LoopKernel.

Returns

Copy of self with updated callable kernels.

Note

Reference

class loopy.translation_unit.CallablesInferenceContext(callables, clbl_name_gen, renames=None, new_entrypoints=frozenset({}))[source]

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

callables

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

renames

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

new_entrypoints

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.

Parameters
Returns

(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.

finish_program(program)[source]

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.

__getitem__(name)[source]
loopy.translation_unit.make_program(kernel)[source]

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

loopy.translation_unit.for_each_kernel(transform)[source]

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.