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

Merge upstream #30

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
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
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
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -62,7 +62,7 @@
["py:class", r"immutables\.(.+)"],

# Reference not found from "<unknown>"? I'm not even sure where to look.
["py:class", r"Expression"],
["py:class", r"ExpressionNode"],
]

autodoc_type_aliases = {
Expand Down
2 changes: 1 addition & 1 deletion doc/ref_kernel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ consist of arithmetic operations and calls to functions.
If the outermost operation of the RHS expression is a function call,
the RHS value may be a tuple, and multiple (still scalar) arrays appear
as LHS values. (This is the only sense in which tuple types are supported.)
Each statement is parametrized by zero or more loop variables ("inames").
Each statement is parameterized by zero or more loop variables ("inames").
A statement is executed once for each integer point defined by the domain
forest for the iname tuple given for that statement
(:attr:`loopy.InstructionBase.within_inames`). Each execution of a
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` **:**
:class:`pymbolic.primitives.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` **:**
:class:`pymbolic.primitives.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
19 changes: 10 additions & 9 deletions loopy/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
check_each_kernel,
)
from loopy.type_inference import TypeReader
from loopy.typing import ExpressionT, not_none
from loopy.typing import not_none


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -206,22 +206,23 @@ 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

arg_name_vars = {Variable(name) for name in kernel.arg_dict}
dep_mapper = DependencyMapper()

def ensure_depends_only_on_arguments(
what: str, expr: Union[str, ExpressionT]) -> None:
what: str, expr: Union[str, Expression]) -> None:
if isinstance(expr, str):
expr = Variable(expr)

Expand All @@ -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
18 changes: 9 additions & 9 deletions loopy/codegen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
from loopy.target import TargetBase
from loopy.tools import LoopyKeyBuilder, caches
from loopy.types import LoopyType
from loopy.typing import ExpressionT
from loopy.typing import Expression
from loopy.version import DATA_MODEL_VERSION


Expand All @@ -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 All @@ -90,9 +90,9 @@

References
^^^^^^^^^^
.. class:: Expression
.. class:: ExpressionNode

See :class:`pymbolic.Expression`.
See :class:`pymbolic.primitives.ExpressionNode`.
"""


Expand Down Expand Up @@ -200,14 +200,14 @@ class CodeGenerationState:
kernel: LoopKernel
target: TargetBase
implemented_domain: isl.Set
implemented_predicates: FrozenSet[Union[str, ExpressionT]]
implemented_predicates: FrozenSet[Union[str, Expression]]

# /!\ mutable
seen_dtypes: Set[LoopyType]
seen_functions: Set[SeenFunction]
seen_atomic_dtypes: Set[LoopyType]

var_subst_map: Map[str, ExpressionT]
var_subst_map: Map[str, Expression]
allow_complex: bool
callables_table: CallablesTable
is_entrypoint: bool
Expand All @@ -231,7 +231,7 @@ def copy(self, **kwargs: Any) -> "CodeGenerationState":
return replace(self, **kwargs)

def copy_and_assign(
self, name: str, value: ExpressionT) -> "CodeGenerationState":
self, name: str, value: Expression) -> "CodeGenerationState":
"""Make a copy of self with variable *name* fixed to *value*."""
return self.copy(var_subst_map=self.var_subst_map.set(name, value))

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: 0 additions & 2 deletions loopy/codegen/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@


__doc__ = """
.. currentmodule:: loopy.codegen.tools

.. autoclass:: KernelProxyForCodegenOperationCacheManager

.. autoclass:: CodegenOperationCacheManager
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
Loading
Loading