Optimization of Python-bindings Wim T.L.P. Lavrijsen, LBNL ROOT Meeting, CERN; 01/15/10 C O M P U T A T I O N A L R E S E A R C H D I V I S I O N.

Slides:



Advertisements
Similar presentations
Optional Static Typing Guido van Rossum (with Paul Prescod, Greg Stein, and the types-SIG)
Advertisements

Runtime Feedback in a Meta-Tracing JIT for Efficient Dynamic Languages Writer: Carl Friedrich Bolz Introduced by Ryotaro IKEDA at 2011/09/06.
Garbage collection David Walker CS 320. Where are we? Last time: A survey of common garbage collection techniques –Manual memory management –Reference.
8. Static Single Assignment Form Marcus Denker. © Marcus Denker SSA Roadmap  Static Single Assignment Form (SSA)  Converting to SSA Form  Examples.
P3 / 2004 Register Allocation. Kostis Sagonas 2 Spring 2004 Outline What is register allocation Webs Interference Graphs Graph coloring Spilling Live-Range.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Program Representations. Representing programs Goals.
Malloc Recitation Section K (Kevin Su) November 5 th, 2012.
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
LLVM-based C++ Interpreter For ROOT Axel Naumann, CERN Lukasz Janyst, CERN Philippe Canal, Fermilab.
Trace-based Just-in-Time Type Specialization for Dynamic Languages Andreas Gal, Brendan Eich, Mike Shaver, David Anderson, David Mandelin, Mohammad R.
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
Intermediate code generation. Code Generation Create linear representation of program Result can be machine code, assembly code, code for an abstract.
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
1 Chapter 7: Expressions Expressions are the fundamental means of specifying computations in a programming language To understand expression evaluation,
Software Language Levels Machine Language (Binary) Assembly Language –Assembler converts Assembly into machine High Level Languages (C, Perl, Shell)
3/17/2008Prof. Hilfinger CS 164 Lecture 231 Run-time organization Lecture 23.
CS 536 Spring Code generation I Lecture 20.
Java for High Performance Computing Jordi Garcia Almiñana 14 de Octubre de 1998 de la era post-internet.
Previous finals up on the web page use them as practice problems look at them early.
1 Pertemuan 20 Run-Time Environment Matakuliah: T0174 / Teknik Kompilasi Tahun: 2005 Versi: 1/6.
10. The PyPy translation tool chain Toon Verwaest Thanks to Carl Friedrich Bolz for his kind permission to reuse and adapt his notes.
Chapter 12: Adding Functionality to Your Classes.
Learners Support Publications Pointers, Virtual Functions and Polymorphism.
High level & Low level language High level programming languages are more structured, are closer to spoken language and are more intuitive than low level.
CS3012: Formal Languages and Compilers The Runtime Environment After the analysis phases are complete, the compiler must generate executable code. The.
JIT in webkit. What’s JIT See time_compilation for more info. time_compilation.
Copyright 2001 Oxford Consulting, Ltd1 January Storage Classes, Scope and Linkage Overview Focus is on the structure of a C++ program with –Multiple.
ICD-C Compiler Framework Dr. Heiko Falk  H. Falk, ICD/ES, 2008 ICD-C Compiler Framework 1.Highlights and Features 2.Basic Concepts 3.Extensions.
CSC 310 – Imperative Programming Languages, Spring, 2009 Virtual Machines and Threaded Intermediate Code (instead of PR Chapter 5 on Target Machine Architecture)
Chapter 6: User-Defined Functions
Java Virtual Machine Case Study on the Design of JikesRVM.
1 ENERGY 211 / CME 211 Lecture 26 November 19, 2008.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
Basic Semantics Associating meaning with language entities.
CSC 508 – Theory of Programming Languages, Spring, 2009 Week 3: Data Abstraction and Object Orientation.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Templates ©Bruce M. Reynolds & Cliff Green1 C++ Programming Certificate University of Washington Cliff Green.
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Xin Yuan.
Compiler Principles Fall Compiler Principles Lecture 0: Local Optimizations Roman Manevich Ben-Gurion University.
COMP3190: Principle of Programming Languages
C Functions Three major differences between C and Java functions: –Functions are stand-alone entities, not part of objects they can be defined in a file.
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
CS412/413 Introduction to Compilers and Translators April 14, 1999 Lecture 29: Linking and loading.
FORTRAN History. FORTRAN - Interesting Facts n FORTRAN is the oldest Language actively in use today. n FORTRAN is still used for new software development.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 11: Functions and stack frames.
Object Oriented Software Development 4. C# data types, objects and references.
Introduction to OOP CPS235: Introduction.
CS412/413 Introduction to Compilers Radu Rugina Lecture 18: Control Flow Graphs 29 Feb 02.
1 Control Flow Graphs. 2 Optimizations Code transformations to improve program –Mainly: improve execution time –Also: reduce program size Can be done.
AUTO-GC: Automatic Translation of Data Mining Applications to GPU Clusters Wenjing Ma Gagan Agrawal The Ohio State University.
CINT & Reflex – The Future CINT’s Future Layout Reflex API Work In Progress: Use Reflex to store dictionary data Smaller memory footprint First step to.
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
Procedures and Functions Procedures and Functions – subprograms – are named fragments of program they can be called from numerous places  within a main.
LLVM IR, File - Praakrit Pradhan. Overview The LLVM bitcode has essentially two things A bitstream container format Encoding of LLVM IR.
Single Static Assignment Intermediate Representation (or SSA IR) Many examples and pictures taken from Wikipedia.
Constructors and Destructors
COMP 2100 From Python to Java
Visit for more Learning Resources
Intro to ETEC Java.
Component 1.6.
Static Single Assignment
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
National Energy Research Scientific Computing Center (NERSC)
The HP OpenVMS Itanium® Calling Standard
For Example: User level quicksort program Three address code.
Towards JIT compiler for IO language Dynamic mixin optimization
Constructors and Destructors
Computer Organization and Design Assembly & Compilation
SPL – PS1 Introduction to C++.
Presentation transcript:

Optimization of Python-bindings Wim T.L.P. Lavrijsen, LBNL ROOT Meeting, CERN; 01/15/10 C O M P U T A T I O N A L R E S E A R C H D I V I S I O N

Introductory words... More wish than plan  No clear idea of time expenditure this year Based on proposal hatched last Summer  Very low change of funding (< 1%)  Originally mainly looked to PyPy Have prototype to play with  Unladen Swallow may be better direction At least initially: less ambitious short term No work done on it yet

PyPy “Python interpreter written in Python”  Makes Python code first-class objects Allows for analysis and manipulation of code, including the full interpreter Full-fledged translation framework  Extensible with external types  Fully customizable with new back-ends  Transformations such as “stackless” Python as high-level description of intent  Target multi-core, Green Flash, etc.

Optimizations in Python-based Analysis4 PyPy Architecture.py.c.cli.class.mfl Annotator Generator Optimizer LLTypeSystemOOTypeSystem Builds flow graphs and code blocks; derives static types Uses flow graphs to optimize calls and reduce temporaries Employs specific back-ends to write code or VM bytecode Python code is translated into lower level, more static code + High-Level Reflex Info + Low-Level Reflex Info

Optimizations in Python-based Analysis5 Feeding the Annotator MethodProxy_1 MethodProxy_2... Bound Class im_func func_code 1. Pretend to be real Python code 2. Return emulated function 3. Construct appropriate bytecode 4. Allow annotator to analyse (all on-the-fly for minimal memory impact) co_argcount co_code... func_code Generated bytecode delivered: def method_1( self, *args ): lvar = long(self) return ext_func( lvar, *args )

Optimizations in Python-based Analysis6 Feeding the Generator CppCodeDict.so compilation info ExternalCompilationInfo (ECI) CppCodeDict.so type info function ptr rffi.llexternal definition 1. Get headers, link libraries, paths => for compilation of generated C code 2. Get argument, return types, ptr => for FFI calls (e.g. through ctypes) 3. Combine in a definition available to the generator. Used directly by PyPy Generator as appropriate

Optimizations in Python-based Analysis7 Unladen Swallow “Google-sponsored” project  Basically 2 Google engineers + OS bazaar Goal is to make Python 5x faster  Leverage LLVM and JIT technology  Get rid of Global Interpreter Lock  Remain compatible with CPython Three releases based on p2.6 If CINT is LLVM, and Python is LLVM … :^)

Optimizations in Python-based Analysis8 Bonus Material

PyPy Annotation Start with known or given types  Constants and built-ins (known)  Function arguments (given [when called]) Calculate flow graphs  Locate joint points  Consolidate code in blocks Fill in all known types  Derived from initial known/given ones  Add information from dictionary } graph structure of possible flows and outcomes =>

Annotation Example >>> def doFillMyHisto( h, val ):... x = ROOT.gRandom.Gaus() * val... return h.Fill( x )... >>> t = Translation( doFillMyHisto ) >>> t.annotate( [ TH1F, int ] ) -- type(h) is TH1F and type(val) is int -- type(x) is float, because: Gaus is TRandom::Gaus() which yields (C++)double mul( (python)float, int ) yields (python)float -- result is None, because: Fill is TH1F::Fill which yields (C++)void >>> doFillMyHisto = t.compile_c() >>> h, val = TH1F('hpx','px',100,-4,4), 10 >>> doFillMyHisto( h, val ) # normal call Explicitly in translation or at runtime; different (non-)choices can coexist user behind the scenes

PyPy Optimizer Function inlining  Equivalent to its C++ brother  May allow further optimizations Malloc removal  Use values rather than objects Esp. for loop variables and iterators  Dict special case: remove method objects Escape analysis and stack allocation  Use stack for scope-lifetime objects All for free from PyPy!

PyPy Generation Two type systems  “Low Level” and “Object Oriented” result = method( self, *args ) result = self.method( *args ) Two kinds of back-ends  Code generation (e.g. C, JS, Lisp)  VM bytecodes (e.g. CLI/.Net and Java) Customizable  Covers cross-language calls (FFI)  Add information from dictionary

Optimizations in Python-based Analysis13 Current Limitations PyPy is rather slow in run/use  Code mgmt needed of compiled functions  Develop/compile/run cycle unwanted anyway Loss of type information => loss of offsets  No virtual inheritance  No support of heterogeneous containers  In need of a solution... No overloading resolution  Can be (partly) resolved with Python types  Complication of implicit conversions