Code Generation

loopy Target

pytato.generate_loopy(result: typing.Union[pytato.array.Array, pytato.array.DictOfNamedArrays, typing.Dict[str, pytato.array.Array]], target: typing.Optional[] = None, options: typing.Optional[loopy.options.Options] = None, *, cl_device: typing.Optional[pyopencl._cl.Device] = None, array_tag_t_to_not_propagate: typing.FrozenSet[typing.Type[pytools.tag.Tag]] = frozenset({<class 'pytato.tags.PrefixNamed'>, <class 'pytato.tags.ImplStored'>, <class 'pytato.tags.Named'>}), axis_tag_t_to_not_propagate: typing.FrozenSet[typing.Type[pytools.tag.Tag]] = frozenset({}))[source]

Code generation entry point.

  • result – Outputs of the computation.

  • target – Code generation target.

  • options – Code generation options for the kernel.


A wrapping the generated loopy program.

If result is a dict or a pytato.DictOfNamedArrays and options is not supplied, then the Loopy option return_dict will be set to True. If it is supplied, return_dict must already be set to True.


pytato metadata \(\mapsto\) loopy metadata semantics:

  • Inames that index over an Array’s axis in the allocation instruction are tagged with the corresponding Axis’s tags. The caller may choose to not propagate axis tags of type axis_tag_t_to_not_propagate.

  • pytato.Array.tags of inputs/outputs in outputs would be copied over to the tags of the corresponding loopy.ArrayArg. The caller may choose to not propagate array tags of type array_tag_t_to_not_propagate.

  • Arrays tagged with pytato.tags.ImplStored would have their tags copied over to the tags of corresponding loopy.TemporaryVariable. The caller may choose to not propagate array tags of type array_tag_t_to_not_propagate.


An loopy target.


Return the corresponding loopy target.

class Optional[pyopencl._cl.Device] = None)[source]

A pyopencl code generation target.


The pyopencl device used to construct the loopy.PyOpenCLTarget, or None.

class Any, bound_arguments: Mapping[str, Any], target:[source]

A wrapper around a loopy kernel for execution with pyopencl.

__call__(queue: pyopencl._cl.CommandQueue, allocator=None, wait_for=None, out_host=None, entrypoint='_pt_kernel', **kwargs: Any) Any[source]

Convenience function for launching a pyopencl computation.

copy(*, program: Optional[loopy.translation_unit.TranslationUnit] = None, bound_arguments: Optional[Mapping[str, Any]] = None, target: Optional[] = None)[source]
with_transformed_program(f: Callable[[loopy.translation_unit.TranslationUnit], loopy.translation_unit.TranslationUnit])[source]

Returns a copy of self with an f-transformed loopy translation unit.

Generic target support

Code Generation Targets


An abstract code generation target.

bind_program(program: Any, bound_arguments: Mapping[str, Any])[source]

Create a BoundProgram for this code generation target.

  • program – the loopy program

  • bound_arguments – a mapping from argument names to outputs

class Any, bound_arguments: Mapping[str, Any], target:[source]

A container for the result of code generation along with data bindings for already-bound arguments.


The code generation target.


Description of the program as per


A map from names to pre-bound kernel arguments.


It is expected that every concrete subclass of this class have a __call__ method to run the generated code, however interfaces may vary based on the specific subclass.