diff --git a/doc/ref_other.rst b/doc/ref_other.rst index e5059380dd8276155bf2723e4b46fdb82c3b0046..538f0cdb924507cb502a8eecf30a48ece3909f56 100644 --- a/doc/ref_other.rst +++ b/doc/ref_other.rst @@ -1,6 +1,11 @@ Reference: Other Functionality ============================== +Auxiliary Data Types +-------------------- + +.. automodule:: loopy.typing + Obtaining Kernel Performance Statistics --------------------------------------- diff --git a/loopy/kernel/array.py b/loopy/kernel/array.py index d6a0126d038370777ba25e22d393c73e9da603e1..884c26d2f5194d84066a3f6405e9dcf13ae751a0 100644 --- a/loopy/kernel/array.py +++ b/loopy/kernel/array.py @@ -1,5 +1,3 @@ -"""Implementation tagging of array axes.""" - from __future__ import annotations @@ -70,8 +68,6 @@ T = TypeVar("T") __doc__ = """ -.. currentmodule:: loopy.kernel.array - .. autoclass:: ArrayDimImplementationTag .. autoclass:: _StrideArrayDimTagBase @@ -85,6 +81,23 @@ __doc__ = """ .. autoclass:: VectorArrayDimTag .. autofunction:: parse_array_dim_tags + +Cross-references +---------------- + +(This section shouldn't exist: Sphinx should be able to resolve these on its own.) + +.. class:: ShapeType + + See :class:`loopy.typing.ShapeType` + +.. class:: ExpressionT + + See :class:`loopy.typing.ExpressionT` + +.. class:: Tag + + See :class:`pytools.tag.Tag` """ diff --git a/loopy/kernel/data.py b/loopy/kernel/data.py index aec7c6d97c654746715344285a70262f0cfe5c15..d2d80bedfc0b48163de4a91fcc36dc2d913cefa7 100644 --- a/loopy/kernel/data.py +++ b/loopy/kernel/data.py @@ -41,7 +41,8 @@ from typing import ( cast, ) -import numpy as np # noqa +import numpy # FIXME: imported as numpy to allow sphinx to resolve things +import numpy as np from immutables import Map from pytools import ImmutableRecord @@ -651,7 +652,7 @@ class TemporaryVariable(ArrayBase): will be created. """ - initializer: Optional[np.ndarray] + initializer: Optional[numpy.ndarray] """*None* or a :class:`numpy.ndarray` of data to be used to initialize the array. """ diff --git a/loopy/statistics.py b/loopy/statistics.py index 0bd1340c1161053acf81c726146b2dcfa9f3cad6..29ea91259d0834ed1f143c713b621a12ac6c0889 100755 --- a/loopy/statistics.py +++ b/loopy/statistics.py @@ -709,7 +709,7 @@ class MemAccess(ImmutableRecord): .. attribute:: variable_tags A :class:`frozenset` of subclasses of :class:`~pytools.tag.Tag` - that reflects :attr:`~loopy.symbolic.TaggedVariable.tags` of + that reflects :attr:`~loopy.TaggedVariable.tags` of an accessed variable. .. attribute:: count_granularity diff --git a/loopy/symbolic.py b/loopy/symbolic.py index f2f04f9ae16ccc496c38abb332c2b0c2b448fa98..22dbd3bf56b80777efdb51b78e384c1315d99962 100644 --- a/loopy/symbolic.py +++ b/loopy/symbolic.py @@ -35,6 +35,7 @@ import immutables import numpy as np import islpy as isl +import pymbolic.primitives # FIXME: also import by full name to allow sphinx to resolve import pymbolic.primitives as p import pytools.lex from islpy import dim_type @@ -60,7 +61,7 @@ from pymbolic.mapper.substitutor import ( from pymbolic.mapper.unifier import UnidirectionalUnifier as UnidirectionalUnifierBase from pymbolic.parser import Parser as ParserBase from pytools import ImmutableRecord, memoize, memoize_method, memoize_on_first_arg -from pytools.tag import Taggable +from pytools.tag import Tag, Taggable from loopy.diagnostic import ( ExpressionToAffineConversionError, @@ -76,8 +77,6 @@ if TYPE_CHECKING: __doc__ = """ -.. currentmodule:: loopy.symbolic - Loopy-specific expression types ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -89,6 +88,8 @@ Loopy-specific expression types .. autoclass:: TypedCSE +.. currentmodule:: loopy + .. autoclass:: TypeCast .. autoclass:: TaggedVariable @@ -97,6 +98,8 @@ Loopy-specific expression types .. autoclass:: LinearSubscript +.. currentmodule:: loopy.symbolic + .. autoclass:: RuleArgument .. autoclass:: ExpansionState @@ -686,13 +689,7 @@ class TaggedVariable(LoopyExpressionBase, p.Variable, Taggable): may then be used to address these uses--such as by prefetching only accesses tagged a certain way. - .. attribute:: tags - - A :class:`frozenset` of subclasses of :class:`pytools.tag.Tag` used to - provide metadata on this object. Legacy string tags are converted to - :class:`~loopy.LegacyStringInstructionTag` or, if they used to carry - a functional meaning, the tag carrying that same functional meaning - (e.g. :class:`~loopy.UseStreamingStoreTag`). + .. autoattribute:: tags Inherits from :class:`pymbolic.primitives.Variable` and :class:`pytools.tag.Taggable`. @@ -700,6 +697,14 @@ class TaggedVariable(LoopyExpressionBase, p.Variable, Taggable): init_arg_names = ("name", "tags") + tags: frozenset[Tag] + """A :class:`frozenset` of subclasses of :class:`pytools.tag.Tag` used to + provide metadata on this object. Legacy string tags are converted to + :class:`~loopy.LegacyStringInstructionTag` or, if they used to carry + a functional meaning, the tag carrying that same functional meaning + (e.g. :class:`~loopy.UseStreamingStoreTag`). + """ + def __init__(self, name, tags): p.Variable.__init__(self, name) if isinstance(tags, str): @@ -744,6 +749,7 @@ class Reduction(LoopyExpressionBase): expr: ExpressionT """An expression which may have tuple type. If the expression has tuple type, it must be one of the following: + * a :class:`tuple` of :class:`pymbolic.primitives.Expression`, or * a :class:`loopy.symbolic.Reduction`, or * a function call or substitution rule invocation. @@ -756,7 +762,8 @@ class Reduction(LoopyExpressionBase): def __init__(self, operation: ReductionOperation | str, - inames: tuple[str | p.Variable, ...] | p.Variable | str, + inames: (tuple[str | pymbolic.primitives.Variable, ...] + | pymbolic.primitives.Variable | str), expr: ExpressionT, allow_simultaneous: bool = False ) -> None: diff --git a/loopy/translation_unit.py b/loopy/translation_unit.py index 801ec296479a742dc26b20331bd7edc758d11d4e..5a4888936dd0c8868c04ccc852a0c93e17950e66 100644 --- a/loopy/translation_unit.py +++ b/loopy/translation_unit.py @@ -88,6 +88,7 @@ __doc__ = """ .. autofunction:: for_each_kernel +.. autoclass:: TUnitOrKernelT """ diff --git a/loopy/typing.py b/loopy/typing.py index 9486165784fe8562f7dce12d72888b00267f4a75..cbf417d2f2f0ac3fdaf63cb1b4af9b866ff45bb7 100644 --- a/loopy/typing.py +++ b/loopy/typing.py @@ -1,3 +1,15 @@ +""" +.. autoclass:: IntegralT +.. autoclass:: FloatT +.. autoclass:: ExpressionT +.. autoclass:: ShapeType +.. autoclass:: auto +""" + + +from __future__ import annotations + + __copyright__ = "Copyright (C) 2022 University of Illinois Board of Trustees" __license__ = """ @@ -24,25 +36,26 @@ THE SOFTWARE. from typing import Optional, Tuple, TypeVar, Union import numpy as np +from typing_extensions import TypeAlias from pymbolic.primitives import Expression -IntegralT = Union[int, np.int8, np.int16, np.int32, np.int64, np.uint8, +IntegralT: TypeAlias = Union[int, np.int8, np.int16, np.int32, np.int64, np.uint8, np.uint16, np.uint32, np.uint64] -FloatT = Union[float, complex, np.float32, np.float64, np.complex64, +FloatT: TypeAlias = Union[float, complex, np.float32, np.float64, np.complex64, np.complex128] -ExpressionT = Union[IntegralT, FloatT, Expression] -ShapeType = Tuple[ExpressionT, ...] -StridesType = ShapeType +ExpressionT: TypeAlias = Union[IntegralT, FloatT, Expression] +ShapeType: TypeAlias = Tuple[ExpressionT, ...] +StridesType: TypeAlias = ShapeType class auto: # noqa """A generic placeholder object for something that should be automatically determined. See, for example, the *shape* or *strides* argument of - :class:`ArrayArg`. + :class:`~loopy.ArrayArg`. """ diff --git a/pyproject.toml b/pyproject.toml index a0ec51c81ebb598107731069c1ea595444b2f42d..8d4d51cd8be89b922b33ddecd7b50f33800a1880 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,7 @@ dependencies = [ "pyrsistent", "immutables", - # for Self + # for Self, TypeAlias "typing-extensions>=4; python_version<'3.12'", ] [project.optional-dependencies]