Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions loopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import os
from typing import TYPE_CHECKING
from warnings import warn

from pytools import strtobool

Expand Down Expand Up @@ -217,7 +218,7 @@
from loopy.translation_unit import TranslationUnit, for_each_kernel, make_program
from loopy.type_inference import infer_unknown_types
from loopy.types import LoopyType, NumpyType, ToLoopyTypeConvertible, to_loopy_type
from loopy.typing import PreambleGenerator, auto
from loopy.typing import AUTO, PreambleGenerator
from loopy.version import MOST_RECENT_LANGUAGE_VERSION, VERSION


Expand All @@ -226,6 +227,7 @@


__all__ = [
"AUTO",
"MOST_RECENT_LANGUAGE_VERSION",
"VERSION",
"ASTBuilderBase",
Expand Down Expand Up @@ -308,7 +310,6 @@
"allocate_temporaries_for_base_storage",
"assignment_to_subst",
"assume",
"auto",
"auto_test_vs_ref",
"buffer_array",
"c_preprocess",
Expand Down Expand Up @@ -587,7 +588,7 @@ def make_copy_kernel(new_dim_tags, old_dim_tags=None):
"output[%s] = input[%s]"
% (command_indices, command_indices),
lang_version=MOST_RECENT_LANGUAGE_VERSION,
default_offset=auto)
default_offset=AUTO)

result = tag_array_axes(result, "input", old_dim_tags)
result = tag_array_axes(result, "output", new_dim_tags)
Expand Down Expand Up @@ -707,4 +708,11 @@ def _set_up_default_target():
# }}}


def __getattr__(name: str):
if name == "auto":
warn("auto is deprecated and will be removed in 2027.x. Use AUTO.",
DeprecationWarning, stacklevel=2)
return AUTO


# vim: foldmethod=marker
24 changes: 12 additions & 12 deletions loopy/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
check_each_kernel,
)
from loopy.type_inference import TypeReader
from loopy.typing import auto, not_none
from loopy.typing import AUTO, not_none


if TYPE_CHECKING:
Expand Down Expand Up @@ -253,7 +253,7 @@ def ensure_depends_only_on_arguments(
what = f"offset of argument '{arg.name}'"
if arg.offset is None:
continue
if arg.offset is auto:
if arg.offset is AUTO:
pass
elif isinstance(arg.offset, (int, np.integer, ExpressionNode, str)):
ensure_depends_only_on_arguments(what, arg.offset)
Expand All @@ -270,7 +270,7 @@ def ensure_depends_only_on_arguments(
if isinstance(dim_tag, FixedStrideArrayDimTag):
what = (f"stride for axis {iaxis+1} (1-based) of "
f"of argument '{arg.name}'")
if dim_tag.stride is auto:
if dim_tag.stride is AUTO:
pass
elif isinstance(
dim_tag.stride, (int, np.integer, ExpressionNode)):
Expand All @@ -291,7 +291,7 @@ def ensure_depends_only_on_arguments(

for tv in kernel.temporary_variables.values():
what = f"offset of temporary '{tv.name}'"
if tv.offset is auto:
if tv.offset is AUTO:
pass
elif isinstance(tv.offset, (int, np.integer, ExpressionNode, str)):
ensure_depends_only_on_arguments(what, tv.offset)
Expand All @@ -303,7 +303,7 @@ def ensure_depends_only_on_arguments(
if isinstance(dim_tag, FixedStrideArrayDimTag):
what = ("axis stride for axis "
f"{iaxis+1} (1-based) of temporary '{tv.name}'")
if dim_tag.stride is auto:
if dim_tag.stride is AUTO:
raise LoopyError(f"The {what}" f" is 'auto', "
"which is not allowed.")
elif isinstance(dim_tag.stride, (int, np.integer, ExpressionNode)):
Expand Down Expand Up @@ -345,9 +345,9 @@ def map_subscript(self, expr):

def _check_for_integer_subscript_indices_inner(kernel, callables_table):

from loopy.kernel.data import auto
if any(arg.dtype in [None, auto] for arg in kernel.args) or (
any(tv.dtype in [None, auto]
from loopy.kernel.data import AUTO
if any(arg.dtype in [None, AUTO] for arg in kernel.args) or (
any(tv.dtype in [None, AUTO]
for tv in kernel.temporary_variables.values())):
# some types are not resolved => do not check.
return
Expand Down Expand Up @@ -571,11 +571,11 @@ def check_for_unused_inames(kernel: LoopKernel) -> None:

def _is_racing_iname_tag(tv: TemporaryVariable, tag: InameImplementationTag) -> bool:
from loopy.kernel.data import (
AUTO,
AddressSpace,
ConcurrentTag,
GroupInameTag,
LocalInameTagBase,
auto,
)

if tv.address_space == AddressSpace.PRIVATE:
Expand All @@ -591,7 +591,7 @@ def _is_racing_iname_tag(tv: TemporaryVariable, tag: InameImplementationTag) ->
elif tv.address_space == AddressSpace.GLOBAL:
return isinstance(tag, ConcurrentTag)

elif tv.address_space == auto:
elif tv.address_space == AUTO:
raise LoopyError("scope of temp var '%s' has not yet been"
"determined" % tv.name)

Expand Down Expand Up @@ -1045,7 +1045,7 @@ def declares_nosync_with(kernel, var_address_space, dep_a, dep_b):
return ab_nosync and ba_nosync


def _get_address_space(kernel: LoopKernel, var: str) -> AddressSpace | type[auto]:
def _get_address_space(kernel: LoopKernel, var: str) -> AddressSpace | AUTO:
from loopy.kernel.data import ArrayArg, ValueArg
if var in kernel.temporary_variables:
address_space = kernel.temporary_variables[var].address_space
Expand Down Expand Up @@ -1659,7 +1659,7 @@ def check_that_shapes_and_strides_are_arguments(kernel: LoopKernel) -> None:

for dim_tag in arg.dim_tags:
if isinstance(dim_tag, FixedStrideArrayDimTag):
if dim_tag.stride is lp.auto:
if dim_tag.stride is lp.AUTO:
continue

deps = get_dependencies(dim_tag.stride)
Expand Down
56 changes: 28 additions & 28 deletions loopy/kernel/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from loopy.diagnostic import LoopyError
from loopy.symbolic import flatten
from loopy.types import LoopyType
from loopy.typing import ShapeType, auto, is_integer
from loopy.typing import AUTO, ShapeType, is_integer


if TYPE_CHECKING:
Expand Down Expand Up @@ -160,7 +160,7 @@ def stringify(self, include_target_axis):
result += "N%d:" % self.layout_nesting_level

import loopy as lp
if self.stride is lp.auto:
if self.stride is lp.AUTO:
result += "stride:auto"
else:
result += "stride:"+str(self.stride)
Expand All @@ -173,21 +173,21 @@ def __str__(self):
return self.stringify(True)

def map_expr(self, mapper):
from loopy.kernel.data import auto
from loopy.kernel.data import AUTO

if self.stride is auto:
if self.stride is AUTO:
# lp.auto not an expr => do not map
return self

return self.copy(stride=mapper(self.stride))

def depends_on(self):
from loopy.kernel.data import auto
from loopy.kernel.data import AUTO
from loopy.symbolic import DependencyMapper
if self.stride is auto:
if self.stride is AUTO:
return frozenset()

return DependencyMapper(composite_leaves=auto)(self.stride)
return DependencyMapper(composite_leaves=AUTO)(self.stride)


class ComputedStrideArrayDimTag(_StrideArrayDimTagBase):
Expand Down Expand Up @@ -310,7 +310,7 @@ def _parse_array_dim_tag(tag, default_target_axis, nesting_levels):
return (
has_explicit_nesting_level, is_optional,
FixedStrideArrayDimTag(
lp.auto, target_axis,
lp.AUTO, target_axis,
layout_nesting_level=nesting_level))
else:
from loopy.symbolic import parse
Expand Down Expand Up @@ -489,7 +489,7 @@ def convert_computed_to_fixed_dim_tags(
name: str,
num_user_axes: int | None,
num_target_axes: int,
shape: ShapeType | type[auto] | None,
shape: ShapeType | AUTO | None,
dim_tags: Sequence[ArrayDimImplementationTag],
) -> Sequence[ArrayDimImplementationTag] | None:

Expand Down Expand Up @@ -544,7 +544,7 @@ def convert_computed_to_fixed_dim_tags(
if vector_dim is None:
stride_so_far = 1
else:
if shape is None or shape is lp.auto:
if shape is None or shape is lp.AUTO:
# unable to normalize without known shape
return None

Expand Down Expand Up @@ -581,7 +581,7 @@ def convert_computed_to_fixed_dim_tags(
target_axis=dim_tag.target_axis,
layout_nesting_level=dim_tag.layout_nesting_level)

if shape is None or shape is lp.auto:
if shape is None or shape is lp.AUTO:
# unable to normalize without known shape
return None
assert isinstance(shape, tuple)
Expand All @@ -601,7 +601,7 @@ def convert_computed_to_fixed_dim_tags(
elif isinstance(dim_tag, FixedStrideArrayDimTag):
stride_so_far = dim_tag.stride

if stride_so_far is lp.auto:
if stride_so_far is lp.AUTO:
stride_so_far = None

else:
Expand All @@ -617,20 +617,20 @@ def convert_computed_to_fixed_dim_tags(
# {{{ array base class (for arguments and temporary arrays)

ToShapeLikeConvertible: TypeAlias = (tuple[Expression | str, ...]
| Expression | type[auto] | str | tuple[str, ...])
| Expression | AUTO | str | tuple[str, ...])


def _parse_shape_or_strides(
x: ToShapeLikeConvertible,
) -> ShapeType | type[auto]:
) -> ShapeType | AUTO:
from pymbolic import parse

if x == "auto":
raise ValueError("use of 'auto' as a shape or stride won't work "
"any more--use loopy.auto instead")

if x is auto:
return auto
if x is AUTO:
return AUTO

x_parsed = x if not isinstance(x, str) else parse(x)

Expand All @@ -640,7 +640,7 @@ def _parse_shape_or_strides(
if isinstance(x_parsed, tuple):
x_tup: tuple[Expression | str, ...] = x_parsed
else:
assert x_parsed is not auto
assert x_parsed is not AUTO
x_tup = (cast("Expression", x_parsed),)

def parse_arith(x: Expression | str) -> ArithmeticExpression:
Expand Down Expand Up @@ -690,7 +690,7 @@ class ArrayBase(ImmutableRecord, Taggable):
cannot be performed without knowledge of the exact *dtype*.
"""

shape: ShapeType | type[auto] | None
shape: ShapeType | AUTO | None
"""
May be one of the following:

Expand Down Expand Up @@ -818,11 +818,11 @@ def __init__(self, name, dtype=None, shape=None, dim_tags=None, offset=0,
dtype = to_loopy_type(dtype, allow_auto=True, allow_none=True,
for_atomic=for_atomic)

if dtype is lp.auto:
if dtype is lp.AUTO:
raise ValueError("dtype may not be lp.auto")

strides_known = strides is not None and strides is not lp.auto
shape_known = shape is not None and shape is not lp.auto
strides_known = strides is not None and strides is not lp.AUTO
shape_known = shape is not None and shape is not lp.AUTO

if strides_known:
strides = _parse_shape_or_strides(strides)
Expand Down Expand Up @@ -1001,15 +1001,15 @@ def stringify(self, include_typename):
if include_typename:
info_entries.append(type(self).__name__)

assert self.dtype is not lp.auto
assert self.dtype is not lp.AUTO

type_str = "<auto/runtime>" if self.dtype is None else str(self.dtype)

info_entries.append("type: %s" % type_str)

if self.shape is None:
info_entries.append("shape: unknown")
elif self.shape is lp.auto:
elif self.shape is lp.AUTO:
info_entries.append("shape: auto")
else:
# shape is iterable
Expand Down Expand Up @@ -1067,8 +1067,8 @@ def num_target_axes(self):
return len(target_axes)

def num_user_axes(self, require_answer=True):
from loopy import auto
if self.shape not in (None, auto):
from loopy import AUTO
if self.shape is not None and self.shape is not AUTO:
return len(self.shape)
if self.dim_tags is not None:
return len(self.dim_tags)
Expand All @@ -1086,7 +1086,7 @@ def map_exprs(self, mapper: Callable[[Expression], Expression]) -> Self:
kwargs: dict[str, Any] = {}
import loopy as lp

if self.shape is not None and self.shape is not lp.auto:
if self.shape is not None and self.shape is not lp.AUTO:
assert isinstance(self.shape, tuple)

def none_pass_mapper(s: Expression | None) -> Expression | None:
Expand Down Expand Up @@ -1234,7 +1234,7 @@ def _apply_offset(sub: ArithmeticExpression, ary: ArrayBase) -> ArithmeticExpres
# is declared.
return sub

if ary.offset is lp.auto:
if ary.offset is lp.AUTO:
raise AssertionError(
f"Offset for '{ary.name}' should have been replaced "
"with an actual argument by "
Expand Down Expand Up @@ -1346,7 +1346,7 @@ def eval_expr_assert_integer_constant(i, expr) -> int:
"vector (%d)"
% (ary.name, i, dim_tag.stride, vector_size))

elif stride is lp.auto:
elif stride is lp.AUTO:
raise AssertionError(
f"Stride for axis {i+1} (1-based) of "
"'{array_name}' should have been replaced "
Expand Down
Loading