From cdb280b3ab6b7f0e52c8121020fe0ca71306d339 Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Fri, 30 Mar 2018 17:46:58 -0500 Subject: [PATCH] handles minor errors. --- loopy/kernel/creation.py | 4 ++-- loopy/preprocess.py | 14 ++++++++------ loopy/symbolic.py | 3 +++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/loopy/kernel/creation.py b/loopy/kernel/creation.py index 3a2f888f8..f324645a9 100644 --- a/loopy/kernel/creation.py +++ b/loopy/kernel/creation.py @@ -2009,12 +2009,12 @@ def scope_functions(kernel): new_insns = [] for insn in kernel.instructions: - if isinstance(insn, (MultiAssignmentBase, CInstruction)): + if isinstance(insn, MultiAssignmentBase): new_insn = insn.copy(expression=function_scoper(insn.expression)) new_scoped_functions.update(scoped_function_collector( new_insn.expression)) new_insns.append(new_insn) - elif isinstance(insn, _DataObliviousInstruction): + elif isinstance(insn, (_DataObliviousInstruction, CInstruction)): new_insns.append(insn) else: raise NotImplementedError("scope_functions not implemented for %s" % diff --git a/loopy/preprocess.py b/loopy/preprocess.py index 4309f9ae1..8b4cfb1de 100644 --- a/loopy/preprocess.py +++ b/loopy/preprocess.py @@ -2215,6 +2215,8 @@ class ArgDescriptionInferer(CombineMapper): def map_call(self, expr, **kwargs): from loopy.kernel.function_interface import ValueArgDescriptor from loopy.symbolic import SubArrayRef + if not isinstance(expr.function, ScopedFunction): + return CombineMapper.map_call(self, expr, **kwargs) # descriptors for the args arg_id_to_descr = dict((i, @@ -2317,10 +2319,10 @@ def infer_arg_descr(kernel): pymbolic_calls_to_functions.update( arg_description_modifier(insn.expression, assignees=insn.assignees)) - elif isinstance(insn, (MultiAssignmentBase, CInstruction)): + elif isinstance(insn, MultiAssignmentBase): pymbolic_calls_to_functions.update(arg_description_modifier( insn.expression)) - elif isinstance(insn, _DataObliviousInstruction): + elif isinstance(insn, (_DataObliviousInstruction, CInstruction)): pass else: raise NotImplementedError("arg_descr_inference for %s instruction" % @@ -2379,7 +2381,7 @@ class ReadyForCodegen(CombineMapper): map_tagged_variable = map_constant -def specializing_incomplete_callables(kernel): +def specialize_incomplete_callables(kernel): """ Transformation necessary to type-specialize the callables which are missed in type inference. For example consider: @@ -2406,7 +2408,7 @@ def specializing_incomplete_callables(kernel): inferred_functions = {} for insn in kernel.instructions: - if isinstance(insn, (MultiAssignmentBase, CInstruction)): + if isinstance(insn, MultiAssignmentBase): expr = subst_expander(insn.expression) if not ready_for_codegen(expr): # only trying to specialize the functions which are not ready @@ -2414,7 +2416,7 @@ def specializing_incomplete_callables(kernel): type_inf_mapper(expr) inferred_functions.update(type_inf_mapper.specialized_functions) - elif isinstance(insn, (_DataObliviousInstruction)): + elif isinstance(insn, (_DataObliviousInstruction, CInstruction)): pass else: NotImplementedError("Unknown Instruction") @@ -2505,7 +2507,7 @@ def preprocess_kernel(kernel, device=None): kernel = infer_arg_descr(kernel) # try specializing callables one last time. - kernel = specializing_incomplete_callables(kernel) + kernel = specialize_incomplete_callables(kernel) # Ordering restriction: # add_axes_to_temporaries_for_ilp because reduction accumulators diff --git a/loopy/symbolic.py b/loopy/symbolic.py index 62de58e76..5374303fb 100644 --- a/loopy/symbolic.py +++ b/loopy/symbolic.py @@ -565,6 +565,9 @@ class Reduction(p.Expression): init_arg_names = ("function", "inames", "expr", "allow_simultaneous") def __init__(self, function, inames, expr, allow_simultaneous=False): + if isinstance(function, str): + function = p.Variable(function) + assert isinstance(function, p.Variable) if isinstance(inames, str): -- GitLab