Created
July 29, 2011 22:00
-
-
Save Neppord/1114837 to your computer and use it in GitHub Desktop.
ackerman
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Timer] Timings: | |
[Timer] annotate --- 0.7 s | |
[Timer] rtype_lltype --- 0.9 s | |
[Timer] backendopt_lltype --- 0.1 s | |
[Timer] stackcheckinsertion_lltype --- 0.0 s | |
[Timer] database_c --- 9.1 s | |
[Timer] source_c --- 1.5 s | |
[Timer] compile_c --- 1.1 s | |
[Timer] ========================================= | |
[Timer] Total: --- 13.6 s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[translation:ERROR] Error: | |
[translation:ERROR] Traceback (most recent call last): | |
[translation:ERROR] File "../pypy/pypy/translator/goal/translate.py", line 308, in main | |
[translation:ERROR] drv.proceed(goals) | |
[translation:ERROR] File "/Users/neppord/pypy/pypy/translator/driver.py", line 810, in proceed | |
[translation:ERROR] return self._execute(goals, task_skip = self._maybe_skip()) | |
[translation:ERROR] File "/Users/neppord/pypy/pypy/translator/tool/taskengine.py", line 116, in _execute | |
[translation:ERROR] res = self._do(goal, taskcallable, *args, **kwds) | |
[translation:ERROR] File "/Users/neppord/pypy/pypy/translator/driver.py", line 286, in _do | |
[translation:ERROR] res = func() | |
[translation:ERROR] File "/Users/neppord/pypy/pypy/translator/driver.py", line 397, in task_pyjitpl_lltype | |
[translation:ERROR] backend_name=self.config.translation.jit_backend, inline=True) | |
[translation:ERROR] File "/Users/neppord/pypy/pypy/jit/metainterp/warmspot.py", line 42, in apply_jit | |
[translation:ERROR] **kwds) | |
[translation:ERROR] File "/Users/neppord/pypy/pypy/jit/metainterp/warmspot.py", line 170, in __init__ | |
[translation:ERROR] self.find_portals() | |
[translation:ERROR] File "/Users/neppord/pypy/pypy/jit/metainterp/warmspot.py", line 226, in find_portals | |
[translation:ERROR] self.split_graph_and_record_jitdriver(*jit_merge_point_pos) | |
[translation:ERROR] File "/Users/neppord/pypy/pypy/jit/metainterp/warmspot.py", line 246, in split_graph_and_record_jitdriver | |
[translation:ERROR] checkgraph(graph) | |
[translation:ERROR] File "/Users/neppord/pypy/pypy/objspace/flow/model.py", line 577, in checkgraph | |
[translation:ERROR] usevar(v, in_link=link) | |
[translation:ERROR] File "/Users/neppord/pypy/pypy/objspace/flow/model.py", line 487, in usevar | |
[translation:ERROR] assert v in vars | |
[translation:ERROR] AssertionError | |
[translation:ERROR] Processing block: | |
[translation:ERROR] block@-1 is a Block at some unknown location | |
[translation:ERROR] containing the following operations: | |
[translation:ERROR] v1 = jit_marker(('jit_merge_point'), (<pypy.rlib.jit.JitDriv...165b90>), n_0, m_0, v0, m_1_0, node_0, self_0) | |
[translation:ERROR] v2 = malloc((GcStruct main.AckermanNode), ({'flavor': 'gc'})) | |
[translation:ERROR] v3 = cast_pointer(v2) | |
[translation:ERROR] v4 = setfield(v3, ('typeptr'), (<* struct object_vtabl...=... }>)) | |
[translation:ERROR] v5 = direct_call((<* fn AckermanNode.__init__>), v2, m_1_0, node_0) | |
[translation:ERROR] --end-- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pypy.rlib.jit import JitDriver | |
jitdriver = JitDriver(greens=[], reds=["n","m","i","m_1","node","self"]) | |
def jitpolicy(driver): | |
from pypy.jit.codewriter.policy import JitPolicy | |
return JitPolicy() | |
class AckermanNode(object): | |
def __init__(self, n, next=None): | |
self.n = n | |
self.next = next | |
def step(self): | |
m = self.next.n | |
n = self.n | |
node = self.next.next | |
if m == 0: | |
return AckermanNode(n + 1, node) | |
elif m > 0 and n == 0: | |
return AckermanNode(1, AckermanNode(m - 1, node)) | |
else: | |
m_1 = m - 1 | |
for i in range(n): | |
jitdriver.jit_merge_point(i=i, m_1=m_1, n=n, m=m, node=node, self=self) | |
node = AckermanNode(m_1, node) | |
#jitdriver.can_enter_jit(i=i) | |
return AckermanNode(0, AckermanNode(m, node)) | |
def solve(self): | |
node = self | |
while not node.next is None: | |
#jitdriver.jit_merge_point(m=node.next.n, node=node) | |
node = node.step() | |
#jitdriver.can_enter_jit(node=node) | |
return node.n | |
def ackerman(m, n): | |
if m == 0: | |
return n + 1 | |
elif m > 0 and n == 0: | |
ret = ackerman(m - 1, 1) | |
return ret | |
else: | |
ret = ackerman(m - 1, ackerman(m, n - 1)) | |
return ret | |
def function_entry_point(argv): | |
print "function" | |
print ackerman(int(argv[1]), int(argv[2])) | |
return 0 | |
def oo_entry_point(argv): | |
print "oo" | |
print AckermanNode(int(argv[2]), AckermanNode(int(argv[1]))).solve() | |
return 0 | |
def target(translator, args): | |
if "function" in args: | |
return function_entry_point, None | |
else: | |
return oo_entry_point, None | |
if __name__ == "__main__": | |
import sys | |
oo_entry_point(sys.argv) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
malus:ackerman neppord$ time ./func-c 3 12 | |
function | |
32765 | |
real 0m19.129s | |
user 0m18.413s | |
sys 0m0.704s | |
malus:ackerman neppord$ time ./main-c 3 12 | |
oo | |
32765 | |
real 0m6.978s | |
user 0m6.598s | |
sys 0m0.369s | |
malus:ackerman neppord$ time ../pypy-c-jit-45137-65b1ed60d7da-osx64/bin/pypy main.py 3 12 | |
oo | |
32765 | |
real 0m15.801s | |
user 0m13.973s | |
sys 0m1.613s | |
malus:ackerman neppord$ time python main.py 3 12 | |
oo | |
32765 | |
real 13m42.581s | |
user 13m28.536s | |
sys 0m14.650s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment