Translation Units¶
- class loopy.translation_unit.FunctionIdT¶
A type for a function identifier. A
ReductionOpFunction
or astr
.
- class loopy.translation_unit.CallablesTable¶
A type alias for callables tables, mapping from
FunctionIdT
toInKernelCallable
- 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 aloopy.target.TargetBase
.- 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. Will raise an error if the default entrypoint is not aLoopKernel
.
- callables_table¶
An instance of
pyrsistent.PMap
mapping the function identifiers in a kernel to their associated instances ofInKernelCallable
.
- target¶
An instance of
loopy.target.TargetBase
.
- func_id_to_in_knl_callables_mappers¶
A
frozenset
of functions of the signature(target: TargetBase, function_identifier: str)
that returns an instance ofloopy.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.- Parameters:
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 aContext
or aCommandQueue
.
- __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
.
Warning
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.
- __getitem__(name) LoopKernel [source]¶
For the callable named name, return a
loopy.LoopKernel
. if it’s aCallableKernel
otherwise return the callable itself.
- with_kernel(kernel: LoopKernel) Self [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
To create an instance of
loopy.TranslationUnit
, it is recommended to go throughloopy.make_kernel()
.This data structure and its attributes should be considered immutable, any modifications should be done through
copy()
.
- 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 ofloopy.TranslationUnit
.- callables¶
A mapping from the callable names to instances of
loopy.kernel.function_interface.InKernelCallable
.
- 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:
old_function_id – An instance of
pymbolic.primitives.Variable
orloopy.library.reduction.ReductionOpFunction
.new_clbl – An instance of
loopy.kernel.function_interface.InKernelCallable
.
- 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.
- loopy.translation_unit.make_program(kernel: LoopKernel) TranslationUnit [source]¶
Returns an instance of
loopy.TranslationUnit
with kernel as the only callable kernel.
- loopy.translation_unit.check_each_kernel(check: Callable[[Concatenate[LoopKernel, P]], None]) Callable[[Concatenate[TranslationUnit, P]], None] [source]¶
- loopy.translation_unit.for_each_kernel(transform: Callable[[Concatenate[LoopKernel, P]], LoopKernel]) Callable[[Concatenate[TUnitOrKernelT, P]], TUnitOrKernelT] [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 aloopy.TranslationUnit
.
- class loopy.translation_unit.TUnitOrKernelT¶
alias of TypeVar(‘TUnitOrKernelT’, ~loopy.kernel.LoopKernel, ~loopy.translation_unit.TranslationUnit)
- class loopy.translation_unit.P¶
A
typing.ParamSpec
for use in annotatingfor_each_kernel()
andcheck_each_kernel()
.