Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More pymbolic 2024.2 #885

Merged
merged 5 commits into from
Nov 25, 2024
Merged
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
23 changes: 0 additions & 23 deletions MANIFEST.in

This file was deleted.

4 changes: 2 additions & 2 deletions contrib/c-integer-semantics.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ def main():
func.argtypes = [ctypes.c_longlong, ctypes.c_longlong]
func.restype = ctypes.c_longlong

cdiv = int_exp.cdiv # noqa
cmod = int_exp.cmod # noqa
cdiv = int_exp.cdiv
cmod = int_exp.cmod
int_floor_div = int_exp.loopy_floor_div_int64
int_floor_div_pos_b = int_exp.loopy_floor_div_pos_b_int64
int_mod_pos_b = int_exp.loopy_mod_pos_b_int64
Expand Down
6 changes: 3 additions & 3 deletions contrib/mem-pattern-explorer/pattern_vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, gsize, lsize, subgroup_size=32, decay_constant=0.75):

self.arrays = []

def l(self, index): # noqa: E741,E743
def l(self, index): # noqa: E743
subscript = [np.newaxis] * self.ind_length
subscript[len(self.gsize) + index] = slice(None)

Expand Down Expand Up @@ -147,7 +147,7 @@ def get_plot_data(self):
div_ceil(nelements, self.elements_per_row),
self.elements_per_row,)
shaped_array = np.zeros(
base_shape + (self.nattributes,),
(*base_shape, self.nattributes),
dtype=np.float32)
shaped_array.reshape(-1, self.nattributes)[:nelements] = self.array

Expand All @@ -160,7 +160,7 @@ def get_plot_data(self):
else:
subgroup.fill(1)

rgb_array = np.zeros(base_shape + (3,))
rgb_array = np.zeros((*base_shape, 3))
if 1:
if len(self.ctx.gsize) > 1:
# g.0 -> red
Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from urllib.request import urlopen


_conf_url = "https://raw.githubusercontent.com/inducer/sphinxconfig/main/sphinxconfig.py" # noqa
_conf_url = "https://raw.githubusercontent.com/inducer/sphinxconfig/main/sphinxconfig.py"
with urlopen(_conf_url) as _inf:
exec(compile(_inf.read(), _conf_url, "exec"), globals())

Expand Down
4 changes: 2 additions & 2 deletions doc/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1681,15 +1681,15 @@ Each line of output will look roughly like::
data type accessed.

- lid_strides: A :class:`dict` of **{** :class:`int` **:**
:attr:`~pymbolic.typing.Expression` or :class:`int` **}** that specifies
:data:`~pymbolic.typing.Expression` or :class:`int` **}** that specifies
local strides for each local id in the memory access index. Local ids not
found will not be present in ``lid_strides.keys()``. Uniform access (i.e.
work-items within a sub-group access the same item) is indicated by setting
``lid_strides[0]=0``, but may also occur when no local id 0 is found, in
which case the 0 key will not be present in lid_strides.

- gid_strides: A :class:`dict` of **{** :class:`int` **:**
:attr:`~pymbolic.typing.Expression` or :class:`int` **}** that specifies
:data:`~pymbolic.typing.Expression` or :class:`int` **}** that specifies
global strides for each global id in the memory access index. Global ids not
found will not be present in ``gid_strides.keys()``.

Expand Down
2 changes: 1 addition & 1 deletion examples/python/ispc-stream-harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def transform(knl, vars, stream_dtype):

knl = lp.add_and_infer_dtypes(knl, dict.fromkeys(vars, stream_dtype))

knl = lp.set_argument_order(knl, vars + ["n"])
knl = lp.set_argument_order(knl, [*vars, "n"])

return knl

Expand Down
4 changes: 2 additions & 2 deletions loopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def register_preamble_generators(kernel: LoopKernel, preamble_generators):
"and would thus disrupt loopy's caches"
% pgen)

new_pgens = (pgen,) + new_pgens
new_pgens = (pgen, *new_pgens)

return kernel.copy(preamble_generators=new_pgens)

Expand All @@ -483,7 +483,7 @@ def register_symbol_manglers(kernel, manglers):
"and would disrupt loopy's caches"
% m)

new_manglers = (m,) + new_manglers
new_manglers = (m, *new_manglers)

return kernel.copy(symbol_manglers=new_manglers)

Expand Down
4 changes: 2 additions & 2 deletions loopy/auto_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,12 @@ def auto_test_vs_ref(
if ref_entrypoint is None:
if len(ref_prog.entrypoints) != 1:
raise LoopyError("Unable to guess entrypoint for ref_prog.")
ref_entrypoint = list(ref_prog.entrypoints)[0]
ref_entrypoint = next(iter(ref_prog.entrypoints))

if test_entrypoint is None:
if len(test_prog.entrypoints) != 1:
raise LoopyError("Unable to guess entrypoint for ref_prog.")
test_entrypoint = list(test_prog.entrypoints)[0]
test_entrypoint = next(iter(test_prog.entrypoints))

ref_prog = lp.preprocess_kernel(ref_prog)
test_prog = lp.preprocess_kernel(test_prog)
Expand Down
15 changes: 8 additions & 7 deletions loopy/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,15 @@ def check_separated_array_consistency(kernel: LoopKernel) -> None:
for attr_name in ["address_space", "is_input", "is_output"]:
if getattr(arg, attr_name) != getattr(sub_arg, attr_name):
raise LoopyError(
"Attribute '{attr_name}' of "
f"Attribute '{attr_name}' of "
f"'{arg.name}' and associated sep array "
f"'{sub_arg.name}' is not consistent.")


@check_each_kernel
def check_offsets_and_dim_tags(kernel: LoopKernel) -> None:
from pymbolic.primitives import Expression, Variable
from pymbolic.primitives import ExpressionNode, Variable
from pymbolic.typing import Expression

from loopy.symbolic import DependencyMapper

Expand Down Expand Up @@ -241,7 +242,7 @@ def ensure_depends_only_on_arguments(
continue
if arg.offset is auto:
pass
elif isinstance(arg.offset, (int, np.integer, Expression, str)):
elif isinstance(arg.offset, (int, np.integer, ExpressionNode, str)):
ensure_depends_only_on_arguments(what, arg.offset)

else:
Expand All @@ -259,13 +260,13 @@ def ensure_depends_only_on_arguments(
if dim_tag.stride is auto:
pass
elif isinstance(
dim_tag.stride, (int, np.integer, Expression)):
dim_tag.stride, (int, np.integer, ExpressionNode)):
ensure_depends_only_on_arguments(what, dim_tag.stride)
else:
raise LoopyError(f"invalid value of {what}")

assert new_dim_tags is not None
new_dim_tags = new_dim_tags + (dim_tag,)
new_dim_tags = (*new_dim_tags, dim_tag)

arg = arg.copy(dim_tags=new_dim_tags)

Expand All @@ -281,7 +282,7 @@ def ensure_depends_only_on_arguments(
pass
if tv.offset is auto:
pass
elif isinstance(tv.offset, (int, np.integer, Expression, str)):
elif isinstance(tv.offset, (int, np.integer, ExpressionNode, str)):
ensure_depends_only_on_arguments(what, tv.offset)
else:
raise LoopyError(f"invalid value of offset for '{tv.name}'")
Expand All @@ -294,7 +295,7 @@ def ensure_depends_only_on_arguments(
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, Expression)):
elif isinstance(dim_tag.stride, (int, np.integer, ExpressionNode)):
ensure_depends_only_on_arguments(what, dim_tag.stride)
else:
raise LoopyError(f"invalid value of {what}")
Expand Down
6 changes: 3 additions & 3 deletions loopy/codegen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@


if getattr(sys, "_BUILDING_SPHINX_DOCS", False):
from loopy.codegen.result import GeneratedProgram # noqa: F811
from loopy.codegen.tools import CodegenOperationCacheManager # noqa: F811
from loopy.codegen.result import GeneratedProgram
from loopy.codegen.tools import CodegenOperationCacheManager


__doc__ = """
Expand Down Expand Up @@ -666,7 +666,7 @@ def generate_code_v2(t_unit: TranslationUnit) -> CodeGenerationResult:
# adding the callee fdecls to the device_programs
device_programs = ([device_programs[0].copy(
ast=t_unit.target.get_device_ast_builder().ast_module.Collection(
callee_fdecls+[device_programs[0].ast]))] +
[*callee_fdecls, device_programs[0].ast]))] +
device_programs[1:])

def not_reduction_op(name: str | ReductionOpFunction) -> str:
Expand Down
2 changes: 1 addition & 1 deletion loopy/codegen/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def gen_code(inner_codegen_state):

prev_gen_code = gen_code

def gen_code(inner_codegen_state): # noqa pylint:disable=function-redefined
def gen_code(inner_codegen_state): # pylint: disable=function-redefined
condition_exprs = [
constraint_to_cond_expr(cns)
for cns in bounds_checks] + list(pred_checks)
Expand Down
2 changes: 1 addition & 1 deletion loopy/codegen/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def generate_assignment_instruction_code(codegen_state, insn):
from pymbolic.mapper.stringifier import PREC_NONE
lhs_code = codegen_state.expression_to_code_mapper(insn.assignee, PREC_NONE)

from cgen import Statement as S # noqa
from cgen import Statement as S

gs, ls = kernel.get_grid_size_upper_bounds(codegen_state.callables_table)

Expand Down
4 changes: 1 addition & 3 deletions loopy/codegen/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,7 @@ def with_new_program(self, codegen_state, program):
assert program.is_device_program
return self.copy(
device_programs=(
list(self.device_programs[:-1])
+
[program]))
[*list(self.device_programs[:-1]), program]))
else:
assert program.name == codegen_state.gen_program_name
assert not program.is_device_program
Expand Down
2 changes: 1 addition & 1 deletion loopy/frontend/fortran/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def parse_transformed_fortran(source, free_form=True, strict=True,
prev_sys_path = sys.path
try:
if infile_dirname:
sys.path = prev_sys_path + [infile_dirname]
sys.path = [*prev_sys_path, infile_dirname]

if pre_transform_code is not None:
proc_dict["_MODULE_SOURCE_CODE"] = pre_transform_code
Expand Down
7 changes: 5 additions & 2 deletions loopy/frontend/fortran/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
"""

import re
from collections.abc import Mapping
from sys import intern
from typing import ClassVar

import numpy as np

import pytools.lex
from pymbolic.parser import Parser as ExpressionParserBase

from loopy.frontend.fortran.diagnostic import TranslationError
from loopy.symbolic import LexTable


_less_than = intern("less_than")
Expand Down Expand Up @@ -65,7 +68,7 @@ def tuple_to_complex_literal(expr):
# {{{ expression parser

class FortranExpressionParser(ExpressionParserBase):
lex_table = [
lex_table: ClassVar[LexTable] = [
(_less_than, pytools.lex.RE(r"\.lt\.", re.I)),
(_greater_than, pytools.lex.RE(r"\.gt\.", re.I)),
(_less_equal, pytools.lex.RE(r"\.le\.", re.I)),
Expand Down Expand Up @@ -142,7 +145,7 @@ def parse_terminal(self, pstate):
return ExpressionParserBase.parse_terminal(
self, pstate)

COMP_MAP = {
COMP_MAP: ClassVar[Mapping[str, str]] = {
_less_than: "<",
_less_equal: "<=",
_greater_than: ">",
Expand Down
11 changes: 6 additions & 5 deletions loopy/frontend/fortran/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import re
from sys import intern
from typing import ClassVar
from warnings import warn

import numpy as np
Expand Down Expand Up @@ -53,7 +54,7 @@ def __init__(self, scope):
super().__init__()

def get_cache_key(self, expr):
return super().get_cache_key(expr) + (self.scope,)
return (*super().get_cache_key(expr), self.scope)

def map_subscript(self, expr):
from pymbolic.primitives import Variable
Expand Down Expand Up @@ -441,7 +442,7 @@ def map_Implicit(self, node):
def map_Equivalence(self, node):
raise NotImplementedError("equivalence")

TYPE_MAP = {
TYPE_MAP: ClassVar[dict[tuple[str, str], type[np.generic]]] = {
("real", ""): np.float32,
("real", "4"): np.float32,
("real", "8"): np.float64,
Expand All @@ -455,9 +456,9 @@ def map_Equivalence(self, node):
("integer", "8"): np.int64,
}
if hasattr(np, "float128"):
TYPE_MAP[("real", "16")] = np.float128 # pylint:disable=no-member
TYPE_MAP["real", "16"] = np.float128 # pylint:disable=no-member
if hasattr(np, "complex256"):
TYPE_MAP[("complex", "32")] = np.complex256 # pylint:disable=no-member
TYPE_MAP["complex", "32"] = np.complex256 # pylint:disable=no-member

def dtype_from_stmt(self, stmt):
length, kind = stmt.selector
Expand All @@ -471,7 +472,7 @@ def dtype_from_stmt(self, stmt):
else:
raise RuntimeError("both length and kind specified")

return np.dtype(self.TYPE_MAP[(type(stmt).__name__.lower(), length)])
return np.dtype(self.TYPE_MAP[type(stmt).__name__.lower(), length])

def map_type_decl(self, node):
scope = self.scope_stack[-1]
Expand Down
2 changes: 1 addition & 1 deletion loopy/frontend/fortran/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def rec(self, expr, *args, **kwargs):
r"^(?P<name>[_0-9a-zA-Z]+)\s*"
r"(\((?P<shape>[-+*/0-9:a-zA-Z, \t]+)\))?"
r"(\s*=\s*(?P<initializer>.+))?"
"$")
r"$")

def parse_dimension_specs(self, node, dim_decls):
def parse_bounds(bounds_str):
Expand Down
7 changes: 4 additions & 3 deletions loopy/kernel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
TYPE_CHECKING,
Any,
Callable,
ClassVar,
Dict,
FrozenSet,
Iterator,
Expand Down Expand Up @@ -85,7 +86,7 @@

# {{{ loop kernel object

class KernelState(IntEnum): # noqa
class KernelState(IntEnum):
INITIAL = 0
CALLS_RESOLVED = 1
PREPROCESSED = 2
Expand Down Expand Up @@ -199,7 +200,7 @@ class LoopKernel(Taggable):
were applied to the kernel. These are stored so that they may be repeated
on expressions the user specifies later.
"""
index_dtype: NumpyType = NumpyType(np.dtype(np.int32))
index_dtype: NumpyType = NumpyType(np.dtype(np.int32)) # noqa: RUF009
silenced_warnings: FrozenSet[str] = frozenset()

# FIXME Yuck, this should go.
Expand Down Expand Up @@ -1310,7 +1311,7 @@ def __setstate__(self, state):

# {{{ persistent hash key generation / comparison

hash_fields = [
hash_fields: ClassVar[Sequence[str]] = [
"domains",
"instructions",
"args",
Expand Down
Loading
Loading