Author: Remi Meier <[email protected]>
Branch: multithread-runner
Changeset: r353:2b8918b59cb7
Date: 2016-05-27 09:34 +0200
http://bitbucket.org/pypy/benchmarks/changeset/2b8918b59cb7/

Log:    add timeout and config-as-parameter

diff --git a/multithread/common/abstract_threading.py 
b/multithread/common/abstract_threading.py
--- a/multithread/common/abstract_threading.py
+++ b/multithread/common/abstract_threading.py
@@ -5,7 +5,7 @@
 try:
     from pypystm import atomic, getsegmentlimit, hint_commit_soon
 except ImportError:
-    raise
+    print "NON-STM EXECUTION"
     atomic = RLock()
     def getsegmentlimit():
         return 1
@@ -144,9 +144,9 @@
     def _task(self, func, *args, **kwargs):
         with self._cond:
             try:
-                hint_commit_soon()
+                #hint_commit_soon()
                 self._result = func(*args, **kwargs)
-                hint_commit_soon()
+                #hint_commit_soon()
             except Exception as e:
                 self._exception = e
             finally:
@@ -173,10 +173,10 @@
     def _task(self, func, *args, **kwargs):
         with self._cond:
             try:
-                hint_commit_soon()
+                #hint_commit_soon()
                 with atomic:
                     self._result = func(*args, **kwargs)
-                hint_commit_soon()
+                #hint_commit_soon()
             except Exception as e:
                 self._exception = e
             finally:
diff --git a/multithread/config-raytrace.json b/multithread/config-raytrace.json
new file mode 100644
--- /dev/null
+++ b/multithread/config-raytrace.json
@@ -0,0 +1,21 @@
+{
+    "defaults": {
+        "file": null,
+        "threads": [1, 2, 4, 8],
+        "vmstarts": 3,
+        "warmiters": 5,
+        "PYTHONPATH": ".",
+        "args": [],
+        "cwd": "."
+    },
+
+    "benchs": {
+        "raytrace": {
+            "file": "raytrace/raytrace.py",
+            "PYTHONPATH": "..",
+            "vmstarts": 5,
+            "warmiters": 3,
+            "args": ["512", "4096"]
+        }
+    }
+}
diff --git a/multithread/raytrace/raytrace.py b/multithread/raytrace/raytrace.py
--- a/multithread/raytrace/raytrace.py
+++ b/multithread/raytrace/raytrace.py
@@ -136,8 +136,7 @@
 
 
 
-def task(img, x, h, cameraPos, objs, lightSource):
-    line = img[x]
+def task(line, x, h, cameraPos, objs, lightSource):
     for y in range(h):
         with atomic:
             ray = Ray(cameraPos,
@@ -173,10 +172,10 @@
         img.append([0.0] * h)
     parallel_time = time.time()
     for x in range(w):
-        future_dispatcher(ths, img, x, h, cameraPos, objs, lightSource)
+        future_dispatcher(ths, img[x], x, h, cameraPos, objs, lightSource)
 
     for f in futures:
-        print f()
+        f()
     del futures[:]
     parallel_time = time.time() - parallel_time
 
@@ -185,6 +184,29 @@
     return parallel_time
 
 
+def main(argv):
+    # warmiters threads args...
+    warmiters = int(argv[0])
+    threads = int(argv[1])
+    w, h = int(argv[2]), int(argv[3])
+
+    print "params (iters, threads, w, h):", warmiters, threads, w, h
+
+    print "do warmup:"
+    for i in range(5):
+        print "iter", i, "time:", run(threads, w, h)
+
+    print "turn off jit"
+    import pypyjit, gc
+    pypyjit.set_param("off")
+    pypyjit.set_param("threshold=999999999,trace_eagerness=99999999")
+    print "do", warmiters, "real iters:"
+    times = []
+    for i in range(warmiters):
+        gc.collect()
+        times.append(run(threads, w, h))
+    print "warmiters:", times
 
 if __name__ == '__main__':
-    run()
+    import sys
+    main(sys.argv[1:])
diff --git a/multithread/runner.py b/multithread/runner.py
--- a/multithread/runner.py
+++ b/multithread/runner.py
@@ -1,32 +1,7 @@
 #!/usr/bin/env python
-""" Usage: runner.py <result file> <path to pypy-c>
+""" Usage: runner.py <path to pypy-c> <config file> <result file>
 """
 
-config = {
-    "defaults": {
-        # global defaults:
-        "file": None,
-        "threads": [1, 2, 4, 8,],
-        "vmstarts": 3,
-        "warmiters": 5,
-        "args": [],
-        "cwd": ".", # relative to file
-        "PYTHONPATH": ".",
-    },
-
-    "benchs": {
-        # list of benchmarks:
-        "raytrace": {
-            "file": "raytrace/raytrace.py",
-            "PYTHONPATH": "..",
-            "vmstarts": 5,
-            "warmiters": 5,
-            "args": ["1024", "1024"] # w, h
-        },
-    },
-}
-
-
 import json
 import time
 import os, sys
@@ -35,10 +10,18 @@
 from subprocess import Popen, PIPE
 
 
+def extract_iter_times(stdout):
+    for line in stdout.split('\n'):
+        if "warmiters" in line:
+            # warmiters: [1.2,3.1,]
+            times = line.split(':')[1].strip()[1:-1]
+            return [float(t) for t in times.split(',')]
+    return None
+
 def run_benchmark(python_exec, bench_config):
     vmstarts = bench_config['vmstarts']
     threads = bench_config['threads']
-    print "## run_benchmark", bench_config['file']
+    print "## run_benchmark", bench_config
 
     failures = []
     timings = []
@@ -58,16 +41,24 @@
             cwd = os.path.join(cwd, bench_config['cwd'])
             env = os.environ.copy()
             env['PYTHONPATH'] = bench_config['PYTHONPATH']
-            print "running:", cmd_str, "in", cwd, "with PYTHONPATH=", 
env['PYTHONPATH']
+            print "running:", cmd_str
 
             try:
-                print env['PYTHONPATH']
                 p = Popen(cmd, stdout=PIPE, stderr=PIPE, env=env, cwd=cwd)
+                # XXX: process could deadlock if stdout pipe is full -> never 
terminate -> timeout
+                start_time = time.time()
+                while p.poll() is None:
+                    time.sleep(0.5)
+                    if time.time() - start_time > 30 * 60:
+                        # kill after 30min
+                        p.kill()
+
                 if p.wait() != 0:
                     # error
                     stdout, stderr = p.stdout.read(), p.stderr.read()
                     failure = {
                         'cmd': cmd_str,
+                        'exitcode': p.returncode,
                         'stdout': stdout,
                         'stderr': stderr,
                     }
@@ -75,6 +66,7 @@
                     print "failure:", failure
                 else:
                     stdout, stderr = p.stdout.read(), p.stderr.read()
+                    print stdout
                     iter_times = extract_iter_times(stdout)
                     times = {
                         'cmd': " ".join(cmd),
@@ -85,9 +77,14 @@
                         'warmiters': iter_times,
                     }
                     timings.append(times)
-                    print "timing:", times
-            finally:
-                pass
+                    print "warmiters:", times['warmiters']
+            except Exception as e:
+                failures.append({
+                    'cmd': cmd_str, 'exception': str(e)})
+            except KeyboardInterrupt as e:
+                failures.append({
+                    'cmd': cmd_str, 'exception': str(e)})
+                return failures, timings
     return failures, timings
 
 
@@ -116,8 +113,14 @@
 
 
 def main(argv):
-    result_file = argv[0]
-    python_exec = argv[1]
+    """ Usage: runner.py <path to pypy-c> <config file> <result file> """
+    python_exec = argv[0]
+    config_file = argv[1]
+    result_file = argv[2]
+
+    assert os.path.exists(config_file)
+    with open(config_file, 'r') as f:
+        config = json.loads(f.read())
 
     if os.path.exists(result_file):
         with open(result_file, 'r+') as f:
@@ -141,4 +144,4 @@
 if __name__ != '__main__': #FIXME: emacs bug?
     main(sys.argv[1:])
 else:
-    main(["results.json", "/usr/bin/python"])
+    main(["pypy-c", "config-raytrace.json", "results.json",])
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to