Skip to content

Commit

Permalink
Enable F841 unused-variable lint, fix
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Dec 4, 2024
1 parent 355ba53 commit 56936b1
Show file tree
Hide file tree
Showing 34 changed files with 128 additions and 139 deletions.
1 change: 0 additions & 1 deletion contrib/c-integer-semantics.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ def main():
func.argtypes = [ctypes.c_longlong, ctypes.c_longlong]
func.restype = ctypes.c_longlong

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
Expand Down
2 changes: 1 addition & 1 deletion loopy/kernel/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ def _count_open_paren_symbols(s):
for c in s:
val = _PAREN_PAIRS.get(c)
if val is not None:
increment, cls = val
increment, _cls = val
result += increment

return result
Expand Down
6 changes: 3 additions & 3 deletions loopy/kernel/function_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ def with_added_arg(self, arg_dtype, arg_descr):
*self.subkernel.args,
ValueArg(var_name, arg_dtype, self.subkernel.target)])

kw_to_pos, pos_to_kw = get_kw_pos_association(subknl)
kw_to_pos, _pos_to_kw = get_kw_pos_association(subknl)

if self.arg_id_to_dtype is None:
arg_id_to_dtype = {}
Expand Down Expand Up @@ -887,7 +887,7 @@ def with_added_arg(self, arg_dtype, arg_descr):

def with_packing_for_args(self):
from loopy.kernel.data import AddressSpace
kw_to_pos, pos_to_kw = get_kw_pos_association(self.subkernel)
_kw_to_pos, pos_to_kw = get_kw_pos_association(self.subkernel)

arg_id_to_descr = {}

Expand Down Expand Up @@ -955,7 +955,7 @@ def emit_call_insn(self, insn, target, expression_to_code_mapper):

parameters = list(parameters)
par_dtypes = [self.arg_id_to_dtype[i] for i, _ in enumerate(parameters)]
kw_to_pos, pos_to_kw = get_kw_pos_association(self.subkernel)
_kw_to_pos, _pos_to_kw = get_kw_pos_association(self.subkernel)

# insert the assignees at the required positions
assignee_write_count = -1
Expand Down
2 changes: 1 addition & 1 deletion loopy/kernel/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def add_dtypes(


def _add_dtypes_overdetermined(kernel, dtype_dict):
dtype_dict_remainder, new_args, new_temp_vars = _add_dtypes(kernel, dtype_dict)
_dtype_dict_remainder, new_args, new_temp_vars = _add_dtypes(kernel, dtype_dict)
# do not throw error for unused args
return kernel.copy(args=new_args, temporary_variables=new_temp_vars)

Expand Down
2 changes: 1 addition & 1 deletion loopy/library/reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def neutral_element(self, scalar_dtype, segment_flag_dtype,
from loopy.library.function import MakeTupleCallable
from loopy.translation_unit import add_callable_to_table

scalar_neutral_element, calables_table = (
scalar_neutral_element, _calables_table = (
self.inner_reduction.neutral_element(
scalar_dtype, callables_table, target))

Expand Down
2 changes: 1 addition & 1 deletion loopy/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ def _tuple_or_none(s):
raise NotImplementedError()
new_callable, clbl_inf_ctx = t_unit.callables_table[e].with_descrs(
arg_id_to_descr, clbl_inf_ctx)
clbl_inf_ctx, new_name = clbl_inf_ctx.with_callable(e, new_callable,
clbl_inf_ctx, _new_name = clbl_inf_ctx.with_callable(e, new_callable,
is_entrypoint=True)

return clbl_inf_ctx.finish_program(t_unit)
Expand Down
2 changes: 1 addition & 1 deletion loopy/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2238,7 +2238,7 @@ def gather_access_footprint_bytes(program, ignore_uncountable=False):
ignore_uncountable=ignore_uncountable)

for key, var_fp in fp.items():
vname, direction = key
vname, _direction = key

var_descr = kernel.get_var_descriptor(vname)
bytes_transferred = (
Expand Down
6 changes: 3 additions & 3 deletions loopy/symbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,7 @@ def map_remainder(self, expr):
raise TypeError("modulo non-constant in '%s' not supported "
"for as-pwaff evaluation" % expr)

(s, denom_aff), = denom.get_pieces()
(_s, denom_aff), = denom.get_pieces()
denom = denom_aff.get_constant_val()

return num.mod_val(denom)
Expand All @@ -1866,7 +1866,7 @@ def aff_from_expr(space: isl.Space, expr: Expression, vars_to_zero=None) -> isl.

pieces = pwaff.get_pieces()
if len(pieces) == 1:
(s, aff), = pieces
(_s, aff), = pieces
return aff
else:
from loopy.diagnostic import ExpressionNotAffineError
Expand Down Expand Up @@ -1970,7 +1970,7 @@ def qpolynomial_from_expr(space, expr):

pieces = pw_qpoly.get_pieces()
if len(pieces) == 1:
(s, qpoly), = pieces
(_s, qpoly), = pieces
return qpoly
else:
raise RuntimeError("expression '%s' could not be converted to a "
Expand Down
2 changes: 0 additions & 2 deletions loopy/target/c/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,8 +945,6 @@ def get_temporary_decls(self, codegen_state, schedule_index):
sub_knl_temps
| supporting_temporary_names(kernel, sub_knl_temps))

ecm = self.get_expression_to_code_mapper(codegen_state)

for tv_name in sorted(sub_knl_temps):
tv = kernel.temporary_variables[tv_name]
if not tv.base_storage:
Expand Down
2 changes: 1 addition & 1 deletion loopy/target/c/c_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def build(self, name, code, debug=False, wait_on_error=None,
c_fname = self._tempname("code." + self.source_suffix)

# build object
_, mod_name, ext_file, recompiled = \
_, _mod_name, ext_file, recompiled = \
compile_from_string(
self.toolchain.copy(
cflags=self.toolchain.cflags+list(extra_build_options)),
Expand Down
2 changes: 1 addition & 1 deletion loopy/target/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def cuda_with_types(self, arg_id_to_dtype, callables_table):

input_dtype = arg_id_to_dtype[0]

scalar_dtype, offset, field_name = input_dtype.fields["x"]
scalar_dtype, _offset, _field_name = input_dtype.fields["x"]
return_dtype = scalar_dtype
return self.copy(arg_id_to_dtype={0: input_dtype, 1: input_dtype,
-1: return_dtype})
Expand Down
4 changes: 2 additions & 2 deletions loopy/target/ispc.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def map_subscript(self, expr, type_context):
and ary.address_space == AddressSpace.PRIVATE):
# generate access code for access to private-index temporaries

gsize, lsize = self.kernel.get_grid_size_upper_bounds_as_exprs()
_gsize, lsize = self.kernel.get_grid_size_upper_bounds_as_exprs()
if lsize:
lsize, = lsize
from pymbolic import evaluate
Expand Down Expand Up @@ -174,7 +174,7 @@ class ISPCTarget(CFamilyTarget):
device_program_name_suffix = "_inner"

def pre_codegen_entrypoint_check(self, kernel, callables_table):
gsize, lsize = kernel.get_grid_size_upper_bounds_as_exprs(
_gsize, lsize = kernel.get_grid_size_upper_bounds_as_exprs(
callables_table)
if len(lsize) > 1:
for ls_i in lsize[1:]:
Expand Down
2 changes: 1 addition & 1 deletion loopy/target/opencl.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def with_types(self, arg_id_to_dtype, callables_table):
callables_table)

dtype = arg_id_to_dtype[0]
scalar_dtype, offset, field_name = dtype.numpy_dtype.fields["s0"]
scalar_dtype, _offset, _field_name = dtype.numpy_dtype.fields["s0"]
return (
self.copy(name_in_target=name, arg_id_to_dtype={-1:
NumpyType(scalar_dtype), 0: dtype, 1: dtype}),
Expand Down
2 changes: 1 addition & 1 deletion loopy/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def address_from_numpy(obj):
if ary_intf is None:
raise RuntimeError("no array interface")

buf_base, is_read_only = ary_intf["data"]
buf_base, _is_read_only = ary_intf["data"]
return buf_base + ary_intf.get("offset", 0)


Expand Down
2 changes: 1 addition & 1 deletion loopy/transform/callable.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def _inline_call_instruction(caller_knl, callee_knl, call_insn):
parameters = call_insn.expression.parameters # reads

from loopy.kernel.function_interface import get_kw_pos_association
kw_to_pos, pos_to_kw = get_kw_pos_association(callee_knl)
_kw_to_pos, pos_to_kw = get_kw_pos_association(callee_knl)

for i, par in enumerate(parameters):
arg_map[pos_to_kw[i]] = par
Expand Down
2 changes: 1 addition & 1 deletion loopy/type_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ def infer_unknown_types(
t_unit[e].args if arg.dtype not in (None, auto)}
new_callable, clbl_inf_ctx = t_unit.callables_table[e].with_types(
arg_id_to_dtype, clbl_inf_ctx)
clbl_inf_ctx, new_name = clbl_inf_ctx.with_callable(e, new_callable,
clbl_inf_ctx, _new_name = clbl_inf_ctx.with_callable(e, new_callable,
is_entrypoint=True)
if expect_completion:
from loopy.types import LoopyType
Expand Down
1 change: 0 additions & 1 deletion proto-tests/test_sem.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ def test_advect_dealias(ctx_factory):
K_sym = var("K") # noqa

field_shape = (N, N, N, K_sym)
interim_field_shape = (M, M, M, K_sym)

# 1. direction-by-direction similarity transform on u
# 2. invert diagonal
Expand Down
1 change: 0 additions & 1 deletion proto-tests/test_sem_tim.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ def test_advect_dealias(ctx_factory):
K_sym = var("K") # noqa

field_shape = (N, N, N, K_sym)
interim_field_shape = (M, M, M, K_sym)

# 1. direction-by-direction similarity transform on u
# 2. invert diagonal
Expand Down
4 changes: 0 additions & 4 deletions proto-tests/test_tim.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ def test_tim2d(ctx_factory):
],
name="semlap2D", assumptions="K>=1")

unroll = 32

seq_knl = knl
knl = lp.add_prefetch(knl, "D", ["m", "j", "i", "o"], default_tag="l.auto")
knl = lp.add_prefetch(knl, "u", ["i", "j", "o"], default_tag="l.auto")
Expand Down Expand Up @@ -107,8 +105,6 @@ def test_red2d(ctx_factory):
],
name="semlap2D", assumptions="K>=1")

unroll = 32

seq_knl = knl
knl = lp.add_prefetch(knl, "D", ["m", "j", "i", "o"], default_tag="l.auto")
knl = lp.add_prefetch(knl, "u", ["i", "j", "o"], default_tag="l.auto")
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ extend-ignore = [
# FIXME
"NPY002", # numpy rng
"C408", # unnecssary dict() -> literal
"F841", # local variable unused
]

[tool.ruff.lint.per-file-ignores]
Expand Down
2 changes: 1 addition & 1 deletion test/test_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def test_fd_demo():

knl = lp.set_options(knl, write_code=True)
knl = lp.add_and_infer_dtypes(knl, dict(u=np.float32))
code, inf = lp.generate_code(knl)
code, _inf = lp.generate_code(knl)
print(code)

assert "double" not in code
Expand Down
2 changes: 1 addition & 1 deletion test/test_c_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def test_one_length_loop():

def test_scalar_global_args():
n = np.random.default_rng().integers(30, 100)
evt, (out,) = lp.make_kernel(
_evt, (out,) = lp.make_kernel(
"{[i]: 0<=i<n}",
"res = sum(i, i)",
target=lp.ExecutableCTarget())(n=n)
Expand Down
Loading

0 comments on commit 56936b1

Please sign in to comment.