Skip to content
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
2,718 changes: 171 additions & 2,547 deletions .basedpyright/baseline.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/python/ispc-stream-harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def make_knl(name, insn, vars):
# "--opt=fast-math",
# "--opt=disable-fma",
]
+ (["--addressing=64"] if INDEX_DTYPE == np.int64 else [])
+ (["--addressing=64"] if np.int64 == INDEX_DTYPE else [])
),
# ispc_bin="/home/andreask/pack/ispc-v1.9.0-linux/ispc",
quiet=False,
Expand Down
10 changes: 2 additions & 8 deletions loopy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ def main():
from os.path import abspath, dirname

infile_dirname = dirname(args.infile)
if infile_dirname:
infile_dirname = abspath(infile_dirname)
else:
infile_dirname = getcwd()
infile_dirname = abspath(infile_dirname) if infile_dirname else getcwd()

sys.path.append(infile_dirname)

Expand Down Expand Up @@ -198,10 +195,7 @@ def main():
t_unit = lp.preprocess_kernel(t_unit)
cgr = lp.generate_code_v2(t_unit)

if args.outfile is not None:
outfile = args.outfile
else:
outfile = "-"
outfile = args.outfile if args.outfile is not None else "-"

code = cgr.device_code()

Expand Down
10 changes: 2 additions & 8 deletions loopy/codegen/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,7 @@ def get_required_predicates(
raise RuntimeError("unexpected schedule item type: %s"
% type(sched_item))

if result is None:
result = my_preds
else:
result = result & my_preds
result = my_preds if result is None else result & my_preds

if result is None:
result = frozenset()
Expand Down Expand Up @@ -276,10 +273,7 @@ def build_loop_nest(
assert i <= codegen_state.schedule_index_end, \
"schedule block extends beyond schedule_index_end"

elif isinstance(sched_item, Barrier):
i += 1

elif isinstance(sched_item, RunInstruction):
elif isinstance(sched_item, (Barrier, RunInstruction)):
i += 1
else:
raise RuntimeError("unexpected schedule item type: %s"
Expand Down
5 changes: 2 additions & 3 deletions loopy/codegen/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,8 @@ def generate_call_code(codegen_state, insn):

# {{{ vectorization handling

if codegen_state.vectorization_info:
if insn.atomicity:
raise UnvectorizableError("atomic operation")
if codegen_state.vectorization_info and insn.atomicity:
raise UnvectorizableError("atomic operation")

# }}}

Expand Down
5 changes: 1 addition & 4 deletions loopy/codegen/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,7 @@ def all_code(self):
def current_program(
self, codegen_state: CodeGenerationState) -> GeneratedProgram:
if codegen_state.is_generating_device_code:
if self.device_programs:
result = self.device_programs[-1]
else:
result = None
result = self.device_programs[-1] if self.device_programs else None
else:
result = self.host_program

Expand Down
5 changes: 1 addition & 4 deletions loopy/diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ def warn_with_kernel(
text += (" (add '%s' to silenced_warnings kernel attribute to disable)"
% id)

if stacklevel is None:
stacklevel = 2
else:
stacklevel = stacklevel + 1
stacklevel = 2 if stacklevel is None else stacklevel + 1
from warnings import warn
warn(f"in kernel {kernel.name}: {text}", type, stacklevel=stacklevel)

Expand Down
10 changes: 2 additions & 8 deletions loopy/frontend/fortran/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,7 @@ def parse_transformed_fortran(source, free_form=True, strict=True,
require_leading_newline=False,
ignore_lines_starting_with="#")

if transform_code_context is None:
proc_dict = {}
else:
proc_dict = transform_code_context.copy()
proc_dict = {} if transform_code_context is None else transform_code_context.copy()

import numpy as np

Expand All @@ -219,10 +216,7 @@ def parse_transformed_fortran(source, free_form=True, strict=True,
from os.path import abspath, dirname

infile_dirname = dirname(filename)
if infile_dirname:
infile_dirname = abspath(infile_dirname)
else:
infile_dirname = getcwd()
infile_dirname = abspath(infile_dirname) if infile_dirname else getcwd()

import sys
prev_sys_path = sys.path
Expand Down
23 changes: 7 additions & 16 deletions loopy/frontend/fortran/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ def tuple_to_complex_literal(expr):
i = np.array(i)[()]

dtype = (r.dtype.type(0) + i.dtype.type(0))
if dtype == np.float32:
dtype = np.complex64
else:
dtype = np.complex128
dtype = np.complex64 if dtype == np.float32 else np.complex128

return dtype(float(r) + float(i)*1j)

Expand Down Expand Up @@ -103,10 +100,7 @@ def parse_terminal(self, pstate):
next_tag = pstate.next_tag()
if next_tag is _float:
value = pstate.next_str_and_advance().lower()
if "d" in value:
dtype = np.float64
else:
dtype = np.float32
dtype = np.float64 if "d" in value else np.float32

value = value.replace("d", "e")
if value.startswith("."):
Expand All @@ -131,10 +125,7 @@ def parse_terminal(self, pstate):
pstate.advance()
pstate.expect_not_end()

if scope.is_known(name):
cls = Subscript
else:
cls = Call
cls = Subscript if scope.is_known(name) else Call

if pstate.next_tag is _closepar:
pstate.advance()
Expand Down Expand Up @@ -185,22 +176,22 @@ def parse_postfix(self, pstate, min_precedence, left_exp):
from pymbolic.primitives import Comparison, LogicalAnd, LogicalOr

next_tag = pstate.next_tag()
if next_tag is _openpar and _PREC_CALL > min_precedence:
if next_tag is _openpar and min_precedence < _PREC_CALL:
raise TranslationError("parenthesis operator only works on names")

elif next_tag in self.COMP_MAP and _PREC_COMPARISON > min_precedence:
elif next_tag in self.COMP_MAP and min_precedence < _PREC_COMPARISON:
pstate.advance()
left_exp = Comparison(
left_exp,
self.COMP_MAP[next_tag],
self.parse_expression(pstate, _PREC_COMPARISON))
did_something = True
elif next_tag is _and and _PREC_LOGICAL_AND > min_precedence:
elif next_tag is _and and min_precedence < _PREC_LOGICAL_AND:
pstate.advance()
left_exp = LogicalAnd((left_exp,
self.parse_expression(pstate, _PREC_LOGICAL_AND)))
did_something = True
elif next_tag is _or and _PREC_LOGICAL_OR > min_precedence:
elif next_tag is _or and min_precedence < _PREC_LOGICAL_OR:
pstate.advance()
left_exp = LogicalOr((left_exp,
self.parse_expression(pstate, _PREC_LOGICAL_OR)))
Expand Down
4 changes: 1 addition & 3 deletions loopy/frontend/fortran/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,7 @@ def dtype_from_stmt(self, stmt):

if kind and not length:
length = kind
elif length and not kind:
pass
elif not length and not kind:
elif (length and not kind) or (not length and not kind):
pass
else:
raise RuntimeError("both length and kind specified")
Expand Down
5 changes: 2 additions & 3 deletions loopy/isl_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
if i == j:
continue

if aff_i.gist(dom_j).is_equal(aff_j):

Check warning on line 198 in loopy/isl_helpers.py

View workflow job for this annotation

GitHub Actions / Conda Pytest without arg check

Aff.is_equal with implicit conversion of self to PwAff is deprecated and will stop working in 2026. Explicitly convert to PwAff, using .to_pw_aff().

Check warning on line 198 in loopy/isl_helpers.py

View workflow job for this annotation

GitHub Actions / Conda Pytest without arg check

Aff.is_equal with implicit conversion of self to PwAff is deprecated and will stop working in 2026. Explicitly convert to PwAff, using .to_pw_aff().

Check warning on line 198 in loopy/isl_helpers.py

View workflow job for this annotation

GitHub Actions / Conda Pytest without arg check

Aff.is_equal with implicit conversion of self to PwAff is deprecated and will stop working in 2026. Explicitly convert to PwAff, using .to_pw_aff().

Check warning on line 198 in loopy/isl_helpers.py

View workflow job for this annotation

GitHub Actions / Conda Pytest (ubuntu-latest)

Aff.is_equal with implicit conversion of self to PwAff is deprecated and will stop working in 2026. Explicitly convert to PwAff, using .to_pw_aff().

Check warning on line 198 in loopy/isl_helpers.py

View workflow job for this annotation

GitHub Actions / Conda Pytest (ubuntu-latest)

Aff.is_equal with implicit conversion of self to PwAff is deprecated and will stop working in 2026. Explicitly convert to PwAff, using .to_pw_aff().

Check warning on line 198 in loopy/isl_helpers.py

View workflow job for this annotation

GitHub Actions / Conda Pytest (ubuntu-latest)

Aff.is_equal with implicit conversion of self to PwAff is deprecated and will stop working in 2026. Explicitly convert to PwAff, using .to_pw_aff().

Check warning on line 198 in loopy/isl_helpers.py

View workflow job for this annotation

GitHub Actions / Conda Pytest (ubuntu-latest)

Aff.is_equal with implicit conversion of self to PwAff is deprecated and will stop working in 2026. Explicitly convert to PwAff, using .to_pw_aff().

Check warning on line 198 in loopy/isl_helpers.py

View workflow job for this annotation

GitHub Actions / Conda Pytest (ubuntu-latest)

Aff.is_equal with implicit conversion of self to PwAff is deprecated and will stop working in 2026. Explicitly convert to PwAff, using .to_pw_aff().

Check warning on line 198 in loopy/isl_helpers.py

View workflow job for this annotation

GitHub Actions / Conda Pytest (ubuntu-latest)

Aff.is_equal with implicit conversion of self to PwAff is deprecated and will stop working in 2026. Explicitly convert to PwAff, using .to_pw_aff().

Check warning on line 198 in loopy/isl_helpers.py

View workflow job for this annotation

GitHub Actions / Conda Pytest (ubuntu-latest)

Aff.is_equal with implicit conversion of self to PwAff is deprecated and will stop working in 2026. Explicitly convert to PwAff, using .to_pw_aff().

Check warning on line 198 in loopy/isl_helpers.py

View workflow job for this annotation

GitHub Actions / Conda Pytest (ubuntu-latest)

Aff.is_equal with implicit conversion of self to PwAff is deprecated and will stop working in 2026. Explicitly convert to PwAff, using .to_pw_aff().

Check warning on line 198 in loopy/isl_helpers.py

View workflow job for this annotation

GitHub Actions / Conda Pytest (macos-latest)

Aff.is_equal with implicit conversion of self to PwAff is deprecated and will stop working in 2026. Explicitly convert to PwAff, using .to_pw_aff().

Check warning on line 198 in loopy/isl_helpers.py

View workflow job for this annotation

GitHub Actions / Conda Pytest (macos-latest)

Aff.is_equal with implicit conversion of self to PwAff is deprecated and will stop working in 2026. Explicitly convert to PwAff, using .to_pw_aff().

Check warning on line 198 in loopy/isl_helpers.py

View workflow job for this annotation

GitHub Actions / Conda Pytest (macos-latest)

Aff.is_equal with implicit conversion of self to PwAff is deprecated and will stop working in 2026. Explicitly convert to PwAff, using .to_pw_aff().

Check warning on line 198 in loopy/isl_helpers.py

View workflow job for this annotation

GitHub Actions / Conda Pytest (macos-latest)

Aff.is_equal with implicit conversion of self to PwAff is deprecated and will stop working in 2026. Explicitly convert to PwAff, using .to_pw_aff().

Check warning on line 198 in loopy/isl_helpers.py

View workflow job for this annotation

GitHub Actions / Conda Pytest (macos-latest)

Aff.is_equal with implicit conversion of self to PwAff is deprecated and will stop working in 2026. Explicitly convert to PwAff, using .to_pw_aff().

Check warning on line 198 in loopy/isl_helpers.py

View workflow job for this annotation

GitHub Actions / Conda Pytest (macos-latest)

Aff.is_equal with implicit conversion of self to PwAff is deprecated and will stop working in 2026. Explicitly convert to PwAff, using .to_pw_aff().

Check warning on line 198 in loopy/isl_helpers.py

View workflow job for this annotation

GitHub Actions / Conda Pytest (macos-latest)

Aff.is_equal with implicit conversion of self to PwAff is deprecated and will stop working in 2026. Explicitly convert to PwAff, using .to_pw_aff().

Check warning on line 198 in loopy/isl_helpers.py

View workflow job for this annotation

GitHub Actions / Conda Pytest (macos-latest)

Aff.is_equal with implicit conversion of self to PwAff is deprecated and will stop working in 2026. Explicitly convert to PwAff, using .to_pw_aff().
# aff_i is sufficient to cover aff_j, eliminate aff_j
new_pieces = pieces[:]
if i < j:
Expand Down Expand Up @@ -509,9 +509,8 @@

def obj_involves_variable(obj, var_name):
loc = obj.get_var_dict().get(var_name)
if loc is not None:
if not obj.get_coefficient_val(*loc).is_zero():
return True
if loc is not None and not obj.get_coefficient_val(*loc).is_zero():
return True

for idiv in obj.dim(dim_type.div):
if obj_involves_variable(obj.get_div(idiv), var_name):
Expand Down
25 changes: 5 additions & 20 deletions loopy/kernel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,7 @@ def parents_per_domain(self) -> Sequence[int | None]:
if discard_level_count:
iname_set_stack = iname_set_stack[:-discard_level_count]

if result:
parent = len(result)-1
else:
parent = None
parent = len(result) - 1 if result else None

for _i in range(discard_level_count):
assert parent is not None
Expand All @@ -384,10 +381,7 @@ def parents_per_domain(self) -> Sequence[int | None]:
# found this domain's parent
result.append(parent)

if iname_set_stack:
parent_inames = iname_set_stack[-1]
else:
parent_inames = set()
parent_inames = iname_set_stack[-1] if iname_set_stack else set()
iname_set_stack.append(parent_inames | inames)

return result
Expand Down Expand Up @@ -1002,10 +996,7 @@ def to_dim_tuple(size_dict, which):
sorted_axes = sorted(size_dict.keys())

while sorted_axes:
if sorted_axes:
cur_axis = sorted_axes.pop(0)
else:
cur_axis = None
cur_axis = sorted_axes.pop(0) if sorted_axes else None

assert cur_axis is not None

Expand Down Expand Up @@ -1231,10 +1222,7 @@ def stringify(self, what=None, with_dependencies=False, use_separators=True,

kernel = self

if use_separators:
sep = [75*"-"]
else:
sep = []
sep = [75 * "-"] if use_separators else []

if "name" in what:
lines.extend(sep)
Expand Down Expand Up @@ -1262,10 +1250,7 @@ def stringify(self, what=None, with_dependencies=False, use_separators=True,
for iname in natsorted(kernel.all_inames()):
tags = kernel.iname_tags(iname)

if not tags:
tags_str = "None"
else:
tags_str = ", ".join(str(tag) for tag in tags)
tags_str = "None" if not tags else ", ".join(str(tag) for tag in tags)

line = f"{iname}: {tags_str}"
lines.append(line)
Expand Down
25 changes: 5 additions & 20 deletions loopy/kernel/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,20 +348,14 @@ def _parse_array_dim_tag(tag, default_target_axis, nesting_levels):
raise LoopyError("may not specify 'C' array order with explicit "
"layout nesting level")

if ta_nesting_levels:
nesting_level = min(ta_nesting_levels)-1
else:
nesting_level = 0
nesting_level = min(ta_nesting_levels) - 1 if ta_nesting_levels else 0

elif tag in ["f", "F"]:
if nesting_level is not None:
raise LoopyError("may not specify 'C' array order with explicit "
"layout nesting level")

if ta_nesting_levels:
nesting_level = max(ta_nesting_levels)+1
else:
nesting_level = 0
nesting_level = max(ta_nesting_levels) + 1 if ta_nesting_levels else 0

elif tag == "":
if nesting_level is None:
Expand Down Expand Up @@ -651,10 +645,7 @@ def _parse_shape_or_strides(
if x is auto:
return auto

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

if isinstance(x_parsed, list):
raise ValueError("shape can't be a list")
Expand All @@ -666,10 +657,7 @@ def _parse_shape_or_strides(
x_tup = (cast("Expression", x_parsed),)

def parse_arith(x: Expression | str) -> ArithmeticExpression:
if isinstance(x, str):
res = parse(x)
else:
res = x
res = parse(x) if isinstance(x, str) else x

# The Fortran parser may do this, but this is (deliberately) outside
# the behavior allowed by types, because the hope is to phase it out.
Expand Down Expand Up @@ -1028,10 +1016,7 @@ def stringify(self, include_typename):

assert self.dtype is not lp.auto

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

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

Expand Down
36 changes: 13 additions & 23 deletions loopy/kernel/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@
_IDENTIFIER_RE = re.compile(r"\b([a-zA-Z_][a-zA-Z0-9_]*)\b")

# source: check_keywords() in isl_stream.c, ISL version 0.17
_ISL_KEYWORDS = frozenset("""
exists and or implies not infty infinity NaN min max rat true false ceild
floord mod ceil floor""".split())
_ISL_KEYWORDS = frozenset([
"exists", "and", "or", "implies", "not", "infty", "infinity", "NaN", "min",
"max", "rat", "true", "false", "ceild", "floord", "mod", "ceil", "floor"])


def _gather_isl_identifiers(s: str):
Expand Down Expand Up @@ -1211,10 +1211,9 @@ def guess_kernel_args_if_requested(self, kernel_args):
from loopy.kernel.data import ArrayBase
from loopy.symbolic import get_dependencies
for arg in kernel_args:
if isinstance(arg, ArrayBase):
if isinstance(arg.shape, tuple):
self.all_names.update(
get_dependencies(arg.shape))
if isinstance(arg, ArrayBase) and isinstance(arg.shape, tuple):
self.all_names.update(
get_dependencies(arg.shape))

new_arg_names = (self.all_names | self.all_params) - not_new_arg_names

Expand Down Expand Up @@ -1312,10 +1311,7 @@ def map_common_subexpression(self, expr, additional_inames):
return self.expr_to_var[expr.child]
except KeyError:
from loopy.symbolic import TypedCSE
if isinstance(expr, TypedCSE):
dtype = expr.dtype
else:
dtype = None
dtype = expr.dtype if isinstance(expr, TypedCSE) else None

child = self.rec(expr.child, additional_inames)
from pymbolic.primitives import Variable
Expand Down Expand Up @@ -1630,10 +1626,7 @@ def guess_arg_shape_if_requested(kernel, default_order):
if isinstance(arg, ArrayBase) and arg.shape is lp.auto:
var_names.append(arg.name)

if var_names:
shapes = guess_var_shape(kernel, var_names)
else:
shapes = []
shapes = guess_var_shape(kernel, var_names) if var_names else []

count = 0
for arg in kernel.args:
Expand Down Expand Up @@ -1897,20 +1890,17 @@ def normalize_slice_params(slice: Slice, dimension_length: ArithmeticExpression)
if step is None:
step = 1

if not isinstance(step, int):
raise ValueError("step must be an integer")

if step == 0:
raise LoopyError("Slice cannot have 0 step size.")

if start is None:
if step > 0:
start = 0
else:
start = dimension_length-1
start = 0 if step > 0 else dimension_length - 1

if stop is None:
if step > 0:
stop = dimension_length
else:
stop = -1
stop = dimension_length if step > 0 else -1

# }}}

Expand Down
Loading
Loading