From 95489b1d1287bd39aa30ba23738d54ede2487c0e Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Sun, 2 May 2021 10:04:44 -0500 Subject: [PATCH] cleanup: gets rid of dead code/comments --- loopy/kernel/tools.py | 48 -------------------------------- loopy/preprocess.py | 11 ++++---- loopy/target/execution.py | 2 -- loopy/transform/make_scalar.py | 51 ---------------------------------- 4 files changed, 5 insertions(+), 107 deletions(-) delete mode 100644 loopy/transform/make_scalar.py diff --git a/loopy/kernel/tools.py b/loopy/kernel/tools.py index 8c12f1e35..e2e5747ef 100644 --- a/loopy/kernel/tools.py +++ b/loopy/kernel/tools.py @@ -1896,54 +1896,6 @@ def find_aliasing_equivalence_classes(kernel): # }}} -# {{{ callee kernel tools - -def get_direct_callee_kernels(kernel, callables_table, insn_ids=None,): - """ - Returns an instance of :class:`frozenset` of all the callee kernels - called in instructions in the *kernel* whose IDs are given in *insn_ids*. - - :arg kernel: An instance of :class:`LoopKernel`. - :arg insn_ids: An instance of :class:`frozenset`. - - If *insn_ids* is *None* returns all the callee kernels called by *kernel*. - """ - #FIXME: explain what "direct" means - - if insn_ids is None: - insn_ids = frozenset(insn.id for insn in kernel.instructions) - - def _get_callee_kernel_if_insn_has_callable_kernel(insn_id): - """Returns callee kernel if the instruction has a call to a - :class:`loopy.kernel.function_interface.CallableKernel`. Otherwise - returns *None*. - """ - insn = kernel.id_to_insn[insn_id] - from loopy.kernel.instruction import (CallInstruction, - MultiAssignmentBase, CInstruction, _DataObliviousInstruction) - from pymbolic.primitives import Call - if isinstance(insn, CallInstruction): - if isinstance(insn.expression, Call) and ( - insn.expression.function.name in callables_table): - in_knl_callable = callables_table[ - insn.expression.function.name] - if isinstance(in_knl_callable, CallableKernel): - return in_knl_callable.subkernel - elif isinstance(insn, (MultiAssignmentBase, - CInstruction, _DataObliviousInstruction)): - pass - else: - raise NotImplementedError("Unknown type of instruction %s." % - type(insn)) - - return None - - return frozenset([_get_callee_kernel_if_insn_has_callable_kernel(insn_id) - for insn_id in insn_ids]) - frozenset([None]) - -# }}} - - # {{{ direction helper tools def infer_args_are_input_output(kernel): diff --git a/loopy/preprocess.py b/loopy/preprocess.py index c28f14e80..4f3dc0773 100644 --- a/loopy/preprocess.py +++ b/loopy/preprocess.py @@ -2148,7 +2148,8 @@ def check_atomic_loads(kernel): class ArgDescrInferenceMapper(RuleAwareIdentityMapper): """ - Infers the :attr:`loopy` + Infers :attr:`~loopy.kernel.function_interface.arg_id_to_descr` of + callables visited in an expression. """ def __init__(self, rule_mapping_context, caller_kernel, clbl_inf_ctx): @@ -2339,7 +2340,6 @@ def infer_arg_descr(program): # {{{ inline_kernels_with_gbarriers - def inline_kernels_with_gbarriers(program): from loopy.kernel.instruction import BarrierInstruction from loopy.transform.callable import inline_callable_kernel @@ -2349,6 +2349,7 @@ def inline_kernels_with_gbarriers(program): and insn.synchronization_kind == "global") for insn in knl.instructions) + # FIXME: should traverse in call-graph's topological sort order callees_to_inline = [name for name, knl_clbl in program.callables_table.items() if (isinstance(knl_clbl, CallableKernel) and has_gbarrier(knl_clbl.subkernel))] @@ -2358,7 +2359,6 @@ def inline_kernels_with_gbarriers(program): return program - # }}} @@ -2377,7 +2377,7 @@ preprocess_cache = WriteOncePersistentDict( key_builder=LoopyKeyBuilder()) -def preprocess_single_kernel(kernel, callables_table, device=None): +def _preprocess_single_kernel(kernel, callables_table, device=None): from loopy.kernel import KernelState prepro_logger = ProcessLogger(logger, "%s: preprocess" % kernel.name) @@ -2498,7 +2498,7 @@ def preprocess_program(program, device=None): new_callables = {} for func_id, in_knl_callable in program.callables_table.items(): if isinstance(in_knl_callable, CallableKernel): - new_subkernel = preprocess_single_kernel( + new_subkernel = _preprocess_single_kernel( in_knl_callable.subkernel, program.callables_table, device) in_knl_callable = in_knl_callable.copy( @@ -2520,7 +2520,6 @@ def preprocess_program(program, device=None): # Ordering restriction: # callees with gbarrier in them must be inlined after inferrring arg_descr. - # inline_kernels_with_gbarriers does not recursively inline the callees. program = inline_kernels_with_gbarriers(program) # {{{ prepare for caching diff --git a/loopy/target/execution.py b/loopy/target/execution.py index fdd38278e..09ab1178a 100644 --- a/loopy/target/execution.py +++ b/loopy/target/execution.py @@ -632,8 +632,6 @@ class ExecutionWrapperGeneratorBase: """ options = program[entrypoint].options - #FIXME: endswith is ugly maybe make - # codegen_result.implemented_data_infos a dict? implemented_data_info = codegen_result.implemented_data_infos[entrypoint] from loopy.kernel.data import KernelArgument diff --git a/loopy/transform/make_scalar.py b/loopy/transform/make_scalar.py deleted file mode 100644 index b8db7f43f..000000000 --- a/loopy/transform/make_scalar.py +++ /dev/null @@ -1,51 +0,0 @@ -from pymbolic.primitives import Variable -from loopy.symbolic import (RuleAwareIdentityMapper, SubstitutionRuleMappingContext) -from loopy.kernel.data import ValueArg -from loopy.transform.iname import remove_unused_inames - - -class ScalarChanger(RuleAwareIdentityMapper): - def __init__(self, rule_mapping_context, var_name): - self.var_name = var_name - super().__init__(rule_mapping_context) - - def map_subscript(self, expr, expn_state): - if expr.aggregate.name == self.var_name: - return Variable(self.var_name) - - return super().map_subscript(expr, expn_state) - - -def make_scalar(kernel, var_name): - rule_mapping_context = SubstitutionRuleMappingContext(kernel.substitutions, - kernel.get_var_name_generator()) - - kernel = ScalarChanger(rule_mapping_context, var_name).map_kernel(kernel) - - new_args = [ValueArg(arg.name, arg.dtype, target=arg.target, - is_output=arg.is_output) if arg.name == var_name else arg for - arg in kernel.args] - new_temps = dict((tv.name, tv.copy(shape=(), dim_tags=None)) - if tv.name == var_name else (tv.name, tv) for tv in - kernel.temporary_variables.values()) - - return kernel.copy(args=new_args, temporary_variables=new_temps) - - -def remove_invariant_inames(kernel): - inames_used = set() - untagged_inames = ( - kernel.all_inames() - frozenset(kernel.iname_to_tags.keys())) - for insn in kernel.instructions: - for iname in ((insn.read_dependency_names() - | insn.write_dependency_names()) - & untagged_inames): - inames_used.add(iname) - - removable_inames = untagged_inames - inames_used - - new_insns = [insn.copy(within_inames=insn.within_inames-removable_inames) - for insn in kernel.instructions] - - return remove_unused_inames(kernel.copy(instructions=new_insns), - removable_inames) -- GitLab