def typed_repr(python_fn, args, optimize = True): typed_fn, _ = specialize(python_fn, args) if optimize: from ..transforms import pipeline return pipeline.high_level_optimizations.apply(typed_fn) else: return typed_fn
def __call__(self, *args, **kwargs): if '_backend' in kwargs: backend_name = kwargs['_backend'] del kwargs['_backend'] else: backend_name = None if self.untyped is None: import ast_conversion self.untyped = ast_conversion.translate_function_value(self.fn) typed_fn, linear_args = specialize(self.untyped, args, kwargs) return run_typed_fn(typed_fn, linear_args, backend_name)
def find_broken_transform(fn, inputs, expected, print_transforms = True, print_functions = True, last_phase = loopify): from .. import interp fn, args = specialize(fn, inputs, optimize=False) try: interp_result = interp.eval(fn, args) except: print "[Diagnose] Runtime before any optimizations while trying to run", fn raise if not eq(interp_result, expected): print "[Diagnose] Expected:", expected print "[Diagnose] Result:", interp_result print "[Diagnose] This function was busted before we optimized anything!" return None transforms = get_transform_list(fn, last_phase = last_phase) print "[Diagnose] Full list of transforms:" for (name, t) in transforms: print " -> ", name old_fn = fn for (name, t) in transforms: print "[Diagnose] Running %s..." % (name, ) # in case t is just a class, instantiate it if not isinstance(t, Transform): t = t() assert isinstance(t, Transform) cloner = CloneFunction(parent_transform = t) new_fn = t.apply(cloner.apply(old_fn)) if print_functions: print new_fn result = interp.eval(new_fn, args) if not eq(result, expected): print "[Diagnose] Expected %s but got %s " % (expected, result) print "[Diagnose] After running ", t print "[Diagnose] Old function ", old_fn print "[Diagnose] Transformed function ", new_fn print "[Diagnose] The culprit was:", name return t old_fn = new_fn print "[Diagnose] No problems found!"
def find_broken_transform(fn, inputs, expected, print_transforms=True, print_functions=True, last_phase=loopify): from .. import interp fn, args = specialize(fn, inputs, optimize=False) try: interp_result = interp.eval(fn, args) except: print "[Diagnose] Runtime before any optimizations while trying to run", fn raise if not eq(interp_result, expected): print "[Diagnose] Expected:", expected print "[Diagnose] Result:", interp_result print "[Diagnose] This function was busted before we optimized anything!" return None transforms = get_transform_list(fn, last_phase=last_phase) print "[Diagnose] Full list of transforms:" for (name, t) in transforms: print " -> ", name old_fn = fn for (name, t) in transforms: print "[Diagnose] Running %s..." % (name, ) # in case t is just a class, instantiate it if not isinstance(t, Transform): t = t() assert isinstance(t, Transform) cloner = CloneFunction(parent_transform=t) new_fn = t.apply(cloner.apply(old_fn)) if print_functions: print new_fn result = interp.eval(new_fn, args) if not eq(result, expected): print "[Diagnose] Expected %s but got %s " % (expected, result) print "[Diagnose] After running ", t print "[Diagnose] Old function ", old_fn print "[Diagnose] Transformed function ", new_fn print "[Diagnose] The culprit was:", name return t old_fn = new_fn print "[Diagnose] No problems found!"