def test_really_run(): """ This test checks whether output of jitprof did not change. It'll explode when someone touches jitprof.py """ mydriver = JitDriver(reds = ['i', 'n'], greens = []) def f(n): i = 0 while i < n: mydriver.can_enter_jit(i=i, n=n) mydriver.jit_merge_point(i=i, n=n) i += 1 cap = py.io.StdCaptureFD() try: ll_meta_interp(f, [10], CPUClass=runner.LLtypeCPU, type_system='lltype', ProfilerClass=Profiler) finally: out, err = cap.reset() log = parse_log(err.splitlines(True)) err_sections = list(extract_category(log, 'jit-summary')) [err1] = err_sections # there should be exactly one jit-summary assert err1.count("\n") == JITPROF_LINES info = parse_prof(err1) # assert did not crash # asserts below are a bit delicate, possibly they might be deleted assert info.tracing_no == 1 assert info.backend_no == 1 assert info.ops.total == 2 assert info.recorded_ops.total == 2 assert info.recorded_ops.calls == 0 assert info.guards == 1 assert info.opt_ops == 13 assert info.opt_guards == 2 assert info.forcings == 0
def meta_interp(self, f, args, policy=None): return ll_meta_interp(f, args, optimizer=self.optimizer, policy=policy, CPUClass=self.CPUClass, type_system=self.type_system)
def meta_interp(self, func, args, **kwds): return ll_meta_interp(func, args, optimizer=OPTIMIZER_SIMPLE, CPUClass=self.CPUClass, type_system=self.type_system, **kwds)
def meta_interp(self, f, args, policy=None): return ll_meta_interp(f, args, enable_opts=self.enable_opts, policy=policy, CPUClass=self.CPUClass, type_system=self.type_system)
def test_really_run(): """ This test checks whether output of jitprof did not change. It'll explode when someone touches jitprof.py """ mydriver = JitDriver(reds=['i', 'n'], greens=[]) def f(n): i = 0 while i < n: mydriver.can_enter_jit(i=i, n=n) mydriver.jit_merge_point(i=i, n=n) i += 1 cap = py.io.StdCaptureFD() try: ll_meta_interp(f, [10], CPUClass=runner.LLtypeCPU, type_system='lltype', ProfilerClass=Profiler, debug_level=DEBUG_PROFILE) finally: out, err = cap.reset() err = "\n".join(err.splitlines()[-JITPROF_LINES:]) print err assert err.count("\n") == JITPROF_LINES - 1 info = parse_prof(err) # assert did not crash # asserts below are a bit delicate, possibly they might be deleted assert info.tracing_no == 1 assert info.asm_no == 1 assert info.blackhole_no == 1 assert info.backend_no == 1 assert info.ops.total == 2 assert info.ops.calls == 0 assert info.ops.pure_calls == 0 assert info.recorded_ops.total == 2 assert info.recorded_ops.calls == 0 assert info.recorded_ops.pure_calls == 0 assert info.guards == 1 assert info.blackholed_ops.total == 0 assert info.blackholed_ops.pure_calls == 0 assert info.opt_ops == 6 assert info.opt_guards == 1 assert info.forcings == 0 assert info.trace_too_long == 0 assert info.bridge_abort == 0
def test_stuff_translates(self): # this is a basic test that tries to hit a number of features and their # translation: # - jitting of loops and bridges # - virtualizables # - set_param interface # - profiler # - full optimizer # - jitdriver hooks class Frame(object): _virtualizable2_ = ['i'] def __init__(self, i): self.i = i class JitCellCache: entry = None jitcellcache = JitCellCache() def set_jitcell_at(entry): jitcellcache.entry = entry def get_jitcell_at(): return jitcellcache.entry def get_printable_location(): return '(hello world)' def can_inline(): return False jitdriver = JitDriver(greens = [], reds = ['frame', 'total'], virtualizables = ['frame'], get_jitcell_at=get_jitcell_at, set_jitcell_at=set_jitcell_at, get_printable_location=get_printable_location, can_inline=can_inline) def f(i): for param in unroll_parameters: defl = PARAMETERS[param] jitdriver.set_param(param, defl) jitdriver.set_param("threshold", 3) jitdriver.set_param("trace_eagerness", 2) total = 0 frame = Frame(i) while frame.i > 3: jitdriver.can_enter_jit(frame=frame, total=total) jitdriver.jit_merge_point(frame=frame, total=total) total += frame.i if frame.i >= 20: frame.i -= 2 frame.i -= 1 return total * 10 res = ll_meta_interp(f, [40], CPUClass=self.CPUClass, type_system=self.type_system) assert res == f(40) res = rpython_ll_meta_interp(f, [40], loops=2, CPUClass=self.CPUClass, type_system=self.type_system, optimizer=OPTIMIZER_FULL, ProfilerClass=Profiler) assert res == f(40)
def test_really_run(): """ This test checks whether output of jitprof did not change. It'll explode when someone touches jitprof.py """ mydriver = JitDriver(reds = ['i', 'n'], greens = []) def f(n): i = 0 while i < n: mydriver.can_enter_jit(i=i, n=n) mydriver.jit_merge_point(i=i, n=n) i += 1 cap = py.io.StdCaptureFD() try: ll_meta_interp(f, [10], CPUClass=runner.LLtypeCPU, type_system='lltype', ProfilerClass=Profiler, debug_level=DEBUG_PROFILE) finally: out, err = cap.reset() err = "\n".join(err.splitlines()[-JITPROF_LINES:]) print err assert err.count("\n") == JITPROF_LINES - 1 info = parse_prof(err) # assert did not crash # asserts below are a bit delicate, possibly they might be deleted assert info.tracing_no == 1 assert info.asm_no == 1 assert info.blackhole_no == 1 assert info.backend_no == 1 assert info.ops.total == 2 assert info.ops.calls == 0 assert info.ops.pure_calls == 0 assert info.recorded_ops.total == 2 assert info.recorded_ops.calls == 0 assert info.recorded_ops.pure_calls == 0 assert info.guards == 1 assert info.blackholed_ops.total == 0 assert info.blackholed_ops.pure_calls == 0 assert info.opt_ops == 6 assert info.opt_guards == 1 assert info.forcings == 0 assert info.trace_too_long == 0 assert info.bridge_abort == 0
def meta_interp(self, *args, **kwds): kwds['CPUClass'] = self.CPUClass kwds['type_system'] = self.type_system if "backendopt" not in kwds: kwds["backendopt"] = False old = codewriter.CodeWriter.debug try: codewriter.CodeWriter.debug = True return ll_meta_interp(*args, **kwds) finally: codewriter.CodeWriter.debug = old
def test_really_run(): """ This test checks whether output of jitprof did not change. It'll explode when someone touches jitprof.py """ mydriver = JitDriver(reds=['i', 'n'], greens=[]) def f(n): i = 0 while i < n: mydriver.can_enter_jit(i=i, n=n) mydriver.jit_merge_point(i=i, n=n) i += 1 cap = py.io.StdCaptureFD() try: ll_meta_interp(f, [10], CPUClass=runner.LLtypeCPU, type_system='lltype', ProfilerClass=Profiler) finally: out, err = cap.reset() log = parse_log(err.splitlines(True)) err_sections = list(extract_category(log, 'jit-summary')) [err1] = err_sections # there should be exactly one jit-summary assert err1.count("\n") == JITPROF_LINES info = parse_prof(err1) # assert did not crash # asserts below are a bit delicate, possibly they might be deleted assert info.tracing_no == 1 assert info.backend_no == 1 assert info.ops.total == 2 assert info.recorded_ops.total == 2 assert info.recorded_ops.calls == 0 assert info.guards == 1 assert info.opt_ops == 13 assert info.opt_guards == 2 assert info.forcings == 0
def test_external_exception_handling_translates(self): jitdriver = JitDriver(greens=[], reds=['n', 'total']) @dont_look_inside def f(x): if x > 20: return 2 raise ValueError @dont_look_inside def g(x): if x > 15: raise ValueError return 2 def main(i): jitdriver.set_param("threshold", 3) jitdriver.set_param("trace_eagerness", 2) total = 0 n = i while n > 3: jitdriver.can_enter_jit(n=n, total=total) jitdriver.jit_merge_point(n=n, total=total) try: total += f(n) except ValueError: total += 1 try: total += g(n) except ValueError: total -= 1 n -= 1 return total * 10 res = ll_meta_interp(main, [40], CPUClass=self.CPUClass, type_system=self.type_system) assert res == main(40) res = rpython_ll_meta_interp(main, [40], loops=2, CPUClass=self.CPUClass, type_system=self.type_system, optimizer=OPTIMIZER_FULL, ProfilerClass=Profiler) assert res == main(40)
def test_external_exception_handling_translates(self): jitdriver = JitDriver(greens = [], reds = ['n', 'total']) @dont_look_inside def f(x): if x > 20: return 2 raise ValueError @dont_look_inside def g(x): if x > 15: raise ValueError return 2 def main(i): set_param(jitdriver, "threshold", 3) set_param(jitdriver, "trace_eagerness", 2) total = 0 n = i while n > 3: jitdriver.can_enter_jit(n=n, total=total) jitdriver.jit_merge_point(n=n, total=total) try: total += f(n) except ValueError: total += 1 try: total += g(n) except ValueError: total -= 1 n -= 1 return total * 10 res = ll_meta_interp(main, [40], CPUClass=self.CPUClass, type_system=self.type_system) assert res == main(40) res = rpython_ll_meta_interp(main, [40], CPUClass=self.CPUClass, type_system=self.type_system, enable_opts='', ProfilerClass=Profiler) assert res == main(40)
def test_stuff_translates(self): # this is a basic test that tries to hit a number of features and their # translation: # - jitting of loops and bridges # - virtualizables # - set_param interface # - profiler # - full optimizer # - jitdriver hooks # - two JITs # - string concatenation, slicing and comparison # - jit hooks interface class Frame(object): _virtualizable2_ = ['l[*]'] def __init__(self, i): self = hint(self, fresh_virtualizable=True, access_directly=True) self.l = [i] class OtherFrame(object): _virtualizable2_ = ['i', 'l[*]'] def __init__(self, i): self = hint(self, fresh_virtualizable=True, access_directly=True) self.i = i self.l = [float(i)] class JitCellCache: entry = None jitcellcache = JitCellCache() def set_jitcell_at(entry): jitcellcache.entry = entry def get_jitcell_at(): return jitcellcache.entry def get_printable_location(): return '(hello world)' jitdriver = JitDriver(greens = [], reds = ['total', 'frame'], virtualizables = ['frame'], get_jitcell_at=get_jitcell_at, set_jitcell_at=set_jitcell_at, get_printable_location=get_printable_location) def f(i): for param, defl in unroll_parameters: set_param(jitdriver, param, defl) set_param(jitdriver, "threshold", 3) set_param(jitdriver, "trace_eagerness", 2) total = 0 frame = Frame(i) while frame.l[0] > 3: jitdriver.can_enter_jit(frame=frame, total=total) jitdriver.jit_merge_point(frame=frame, total=total) total += frame.l[0] if frame.l[0] >= 20: frame.l[0] -= 2 frame.l[0] -= 1 return total * 10 # myjitdriver2 = JitDriver(greens = ['g'], reds = ['m', 's', 'f', 'float_s'], virtualizables = ['f']) def f2(g, m, x): s = "" f = OtherFrame(x) float_s = 0.0 while m > 0: myjitdriver2.can_enter_jit(g=g, m=m, f=f, s=s, float_s=float_s) myjitdriver2.jit_merge_point(g=g, m=m, f=f, s=s, float_s=float_s) s += 'xy' if s[:2] == 'yz': return -666 m -= 1 f.i += 3 float_s += f.l[0] return f.i # def main(i, j): op = resop_new(rop.INT_ADD, [boxint_new(3), boxint_new(5)], boxint_new(8)) return f(i) - f2(i+j, i, j) + resop_getopnum(op) res = ll_meta_interp(main, [40, 5], CPUClass=self.CPUClass, type_system=self.type_system, listops=True) assert res == main(40, 5) res = rpython_ll_meta_interp(main, [40, 5], CPUClass=self.CPUClass, type_system=self.type_system, ProfilerClass=Profiler, listops=True) assert res == main(40, 5)
def meta_interp(self, *args, **kwds): kwds['CPUClass'] = self.CPUClass kwds['type_system'] = self.type_system if "backendopt" not in kwds: kwds["backendopt"] = False return ll_meta_interp(*args, **kwds)
def test_stuff_translates(self): # this is a basic test that tries to hit a number of features and their # translation: # - jitting of loops and bridges # - virtualizables # - set_param interface # - profiler # - full optimizer # - jitdriver hooks class Frame(object): _virtualizable2_ = ['i'] def __init__(self, i): self.i = i class JitCellCache: entry = None jitcellcache = JitCellCache() def set_jitcell_at(entry): jitcellcache.entry = entry def get_jitcell_at(): return jitcellcache.entry def get_printable_location(): return '(hello world)' def can_inline(): return False jitdriver = JitDriver(greens=[], reds=['frame', 'total'], virtualizables=['frame'], get_jitcell_at=get_jitcell_at, set_jitcell_at=set_jitcell_at, get_printable_location=get_printable_location, can_inline=can_inline) def f(i): for param in unroll_parameters: defl = PARAMETERS[param] jitdriver.set_param(param, defl) jitdriver.set_param("threshold", 3) jitdriver.set_param("trace_eagerness", 2) total = 0 frame = Frame(i) while frame.i > 3: jitdriver.can_enter_jit(frame=frame, total=total) jitdriver.jit_merge_point(frame=frame, total=total) total += frame.i if frame.i >= 20: frame.i -= 2 frame.i -= 1 return total * 10 res = ll_meta_interp(f, [40], CPUClass=self.CPUClass, type_system=self.type_system) assert res == f(40) res = rpython_ll_meta_interp(f, [40], loops=2, CPUClass=self.CPUClass, type_system=self.type_system, optimizer=OPTIMIZER_FULL, ProfilerClass=Profiler) assert res == f(40)