Author: Maciej Fijalkowski <[email protected]>
Branch: extradoc
Changeset: r5387:be99fc4a12c0
Date: 2014-08-20 19:21 +0200
http://bitbucket.org/pypy/extradoc/changeset/be99fc4a12c0/

Log:    Add a draft of UCT talk

diff --git a/talk/uct2014/example/demo1.py b/talk/uct2014/example/demo1.py
new file mode 100644
--- /dev/null
+++ b/talk/uct2014/example/demo1.py
@@ -0,0 +1,23 @@
+
+def adder(x, y):
+    return x + y
+
+def entry_point(argv):
+    if len(argv) != 3:
+        print "Wrong number of args"
+        return 1
+    try:
+        arg0 = int(argv[1])
+        arg1 = int(argv[2])
+    except ValueError:
+        print "Requires ints"
+        return 1
+    print "Added", arg0 + arg1
+    return 0
+
+def target(*args):
+    return entry_point
+
+if __name__ == '__main__':
+    import sys
+    entry_point(sys.argv)
diff --git a/talk/uct2014/example/demo2.py b/talk/uct2014/example/demo2.py
new file mode 100644
--- /dev/null
+++ b/talk/uct2014/example/demo2.py
@@ -0,0 +1,26 @@
+
+def adder(x, y):
+    return x + y
+
+def entry_point(argv):
+    if len(argv) != 3:
+        print "Wrong number of args"
+        return 1
+    try:
+        arg0 = int(argv[1])
+        arg1 = int(argv[2])
+    except ValueError:
+        print "Requires ints"
+        return 1
+    x = float(arg1)
+    for i in xrange(arg0):
+        x = adder(x, 1.2)
+    print "Result", x
+    return 0
+
+def target(*args):
+    return entry_point
+
+if __name__ == '__main__':
+    import sys
+    entry_point(sys.argv)
diff --git a/talk/uct2014/example/interp.py b/talk/uct2014/example/interp.py
new file mode 100644
--- /dev/null
+++ b/talk/uct2014/example/interp.py
@@ -0,0 +1,48 @@
+
+import time
+
+class InterpreterError(Exception):
+    def __init__(self, msg):
+        self.msg = msg
+
+def interp(bytecode, start_value):
+    i = 0
+    lgt = len(bytecode)
+    accumulator = start_value
+    while i < lgt:
+        c = bytecode[i]
+        if c == 'd':
+            accumulator -= 1
+            i += 1
+        elif c == 'l':
+            arg = ord(bytecode[i + 1])
+            i += 2
+            if accumulator > 0:
+                i -= arg + 2
+        else:
+            raise InterpreterError("Unknown char %s" % (c,))
+    return accumulator
+
+def entry_point(argv):
+    if len(argv) != 3:
+        print "Wrong number of args, requires bytecode and start_value"
+        return 1
+    bytecode = argv[1]
+    try:
+        acc = int(argv[2])
+    except ValueError:
+        print "Expected int, got %s" % (argv[2],)
+        return 2
+    try:
+        t0 = time.time()
+        res = interp(bytecode, acc)
+        tk = time.time()
+        dt = tk - t0
+    except InterpreterError, e:
+        print e.msg
+        return 3
+    print "Got %d, time %f" % (res, dt)
+    return 0
+
+def target(*args):
+    return entry_point
diff --git a/talk/uct2014/example/interp_jit.py 
b/talk/uct2014/example/interp_jit.py
new file mode 100644
--- /dev/null
+++ b/talk/uct2014/example/interp_jit.py
@@ -0,0 +1,61 @@
+
+import time
+from rpython.rlib import jit
+
+driver = jit.JitDriver(greens = ['i', 'lgt', 'start_value', 'bytecode'],
+                       reds = ['accumulator'])
+
+class InterpreterError(Exception):
+    def __init__(self, msg):
+        self.msg = msg
+
+def interp(bytecode, start_value):
+    i = 0
+    lgt = len(bytecode)
+    accumulator = start_value
+    while i < lgt:
+        driver.jit_merge_point(bytecode=bytecode, i=i, lgt=lgt,
+                               accumulator=accumulator, 
start_value=start_value)
+        c = bytecode[i]
+        if c == 'd':
+            accumulator -= 1
+            i += 1
+        elif c == 'l':
+            arg = ord(bytecode[i + 1])
+            i += 2
+            if accumulator > 0:
+                i -= arg + 2
+                driver.can_enter_jit(bytecode=bytecode, i=i, lgt=lgt,
+                                     accumulator=accumulator,
+                                     start_value=start_value)
+        else:
+            raise InterpreterError("Unknown char %s (%d)" % (c, ord(c)))
+    return accumulator
+
+def entry_point(argv):
+    if len(argv) != 3:
+        print "Wrong number of args, requires bytecode and start_value"
+        return 1
+    bytecode = argv[1]
+    try:
+        acc = int(argv[2])
+    except ValueError:
+        print "Expected int, got %s" % (argv[2],)
+        return 2
+    try:
+        t0 = time.time()
+        res = interp(bytecode, acc)
+        tk = time.time()
+        dt = tk - t0
+    except InterpreterError, e:
+        print e.msg
+        return 3
+    print "Got %d, time %f" % (res, dt)
+    return 0
+
+def target(*args):
+    return entry_point
+
+if __name__ == '__main__':
+    import sys
+    entry_point(sys.argv)
diff --git a/talk/uct2014/example/test_interp.py 
b/talk/uct2014/example/test_interp.py
new file mode 100644
--- /dev/null
+++ b/talk/uct2014/example/test_interp.py
@@ -0,0 +1,6 @@
+
+from interp import interp
+
+def test_interp():
+    assert interp('ddl\x02', 13) == -1
+    assert interp('ddl\x01', 13) == 0
diff --git a/talk/uct2014/talk.rst b/talk/uct2014/talk.rst
new file mode 100644
--- /dev/null
+++ b/talk/uct2014/talk.rst
@@ -0,0 +1,149 @@
+The PyPy project
+================
+
+What is this talk about?
+------------------------
+
+* short introduction to the PyPy project
+
+* short introduction to RPython
+
+* just in time compilation and other innovations
+
+* how virtual machines should be written
+
+* commercial vs open source (???)
+
+Who am I?
+---------
+
+* Maciej Fija&#322;kowski
+
+* PyPy core developer
+
+* own company - baroquesoftware.com
+
+What's PyPy?
+------------
+
+* a python interpreter
+
+* implements the full language (no restrictions!)
+
+* runs faster
+
+What makes PyPy different?
+--------------------------
+
+* not written in C/C++
+
+* has just in time compiler
+
+* runs fast
+
+* core interpreter does not know about the JIT (mostly)
+
+What's RPython?
+---------------
+
+* implementation language for PyPy (and other projects, topaz, hippyvm, ...)
+
+* a subset of Python that can be statically compiled
+
+* extensive static analysis and transformation (GC, JIT, ...)
+
+RPython example
+---------------
+
+* demo
+
+* like python, but can compile to C
+
+* quite a bit quicker
+
+RPython interpreter example
+---------------------------
+
+* RPython is an ugly language
+
+* mostly for writing interpreters
+
+* demo
+
+Classic compilation
+-------------------
+
+* you take a language X, parse it, compile it to assembler
+
+* works well for simple "static enough" languages
+
+Virtual Machine
+---------------
+
+* you take language X, compile it to imaginary computer
+
+* you implement that imaginary computer
+
+JIT - introduction
+------------------
+
+* you have a virtual machine from the previous slide
+
+* you compile bits and pieces of the code straight into assembler
+
+Tracing JIT - introduction
+--------------------------
+
+* instead of compiling e.g. function at a time you **trace**
+  what the interpreter does
+
+* follow steps one by one and generate assembler
+
+* very natural inlining, hot paths etc.
+
+Metatracing
+-----------
+
+* trace the **interpreter** instead of the program
+
+* for complicated languages, like Python, is essential
+
+* hints necessary to close the semantics gap
+
+* avoids duplication of code
+
+RPython interpreter example - JIT
+---------------------------------
+
+* demo
+
+* jit adding means adding a few hints (pypy has about 100)
+
+Recap on virtual machines
+-------------------------
+
+* don't write virtual machines by hand
+
+* don't write JITs in hand
+
+* use tools (PyPy/truffle)
+
+Q&A
+---
+
+* pypy.org
+
+* baroquesoftware.com
+
+* [email protected]
+
+* Any questions?
+
+Extra slide - what do I do for a living?
+----------------------------------------
+
+* selling pypy commercial support
+
+* various grants
+
+* implementing extra features
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to