Vineet Kumar and Laurie Hendren McGill University MiX10 First steps to compiling MATLAB to X10.

Slides:



Advertisements
Similar presentations
Vineet Kumar and Laurie Hendren McGill University MiX10 Compiling MATLAB for High Peformance Computing.
Advertisements

Inpainting Assigment – Tips and Hints Outline how to design a good test plan selection of dimensions to test along selection of values for each dimension.
Chapter 1: An Overview of Computers and Programming Languages
McLab Tutorial Part 8 – Wrap Up Summary Ongoing and Future Work Further Sources 6/4/2011Wrap Up- 1McLab Tutorial, Laurie Hendren,
AUTOMATIC GENERATION OF CODE OPTIMIZERS FROM FORMAL SPECIFICATIONS Vineeth Kumar Paleri Regional Engineering College, calicut Kerala, India. (Currently,
Lecture 01 - Introduction Eran Yahav 1. 2 Who? Eran Yahav Taub 734 Tel: Monday 13:30-14:30
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
Telescoping Languages: A Compiler Strategy for Implementation of High-Level Domain-Specific Programming Systems Ken Kennedy Rice University.
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
COMP1170 Midterm Preparation (March 17 th 2009) Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education.
Building An Interpreter After having done all of the analysis, it’s possible to run the program directly rather than compile it … and it may be worth it.
Language Issues Misunderstimated? Sublimable? Hopefuller? "I know how hard it is for you to put food on your family.” "I know the human being and fish.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages Updated by: Dr\Ali-Alnajjar.
McLab Tutorial Laurie Hendren, Rahul Garg and Nurudeen Lameed Other McLab team members: Andrew Casey, Jesse Doherty, Anton Dubrau,
McLab Tutorial Part 6 – Introduction to the McLab Backends MATLAB-to-MATLAB MATLAB-to-Fortran90 (McFor) McVM with JIT 6/4/2011Backends-
Introduction to MATLAB adapted from Dr. Rolf Lakaemper.
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
Multi-Dimensional Arrays
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Overview of the Course Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
Computing with C# and the.NET Framework Chapter 1 An Introduction to Computing with C# ©2003, 2011 Art Gittleman.
Java Programming Introduction & Concepts. Introduction to Java Developed at Sun Microsystems by James Gosling in 1991 Object Oriented Free Compiled and.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Which Language is Better?
Programming Language C++ Xulong Peng CSC415 Programming Languages.
ImageJ EE4H, M.Sc Computer Vision Dr. Mike Spann
Eng Ship Structures 1 Introduction to Matlab.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Code Optimization 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture of a.
1.  10% Assignments/ class participation  10% Pop Quizzes  05% Attendance  25% Mid Term  50% Final Term 2.
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Xin Yuan.
1CPSD Software Infrastructure for Application Development Laxmikant Kale David Padua Computer Science Department.
Evaluating Python as an Introductory Programming Language A. Thomas and H.L. Liang UNISA.
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
CS 460/660 Compiler Construction. Class 01 2 Why Study Compilers? Compilers are important – –Responsible for many aspects of system performance Compilers.
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Overview of Compilers and JikesRVM John.
Compilers: Overview/1 1 Compiler Structures Objective – –what are the main features (structures) in a compiler? , Semester 1,
Siena Computational Crystallography School 2005
Fitting image transformations Prof. Noah Snavely CS1114
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
CIS 601 Fall 2003 Introduction to MATLAB Longin Jan Latecki Based on the lectures of Rolf Lakaemper and David Young.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Improving Matlab Performance CS1114
CSC 4181 Compiler Construction
1 HPJAVA I.K.UJJWAL 07M11A1217 Dept. of Information Technology B.S.I.T.
CIS 595 MATLAB First Impressions. MATLAB This introduction will give Some basic ideas Main advantages and drawbacks compared to other languages.
“Moh’d Sami” AshhabSummer 2008University of Jordan MATLAB By (Mohammed Sami) Ashhab University of Jordan Summer 2008.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
1 Titanium Review: Language and Compiler Amir Kamil Titanium Language and Compiler Changes Amir Kamil U.C. Berkeley September.
Software Engineering Algorithms, Compilers, & Lifecycle.
Objective of the course Understanding the fundamentals of the compilation technique Assist you in writing you own compiler (or any part of compiler)
DGrid: A Library of Large-Scale Distributed Spatial Data Structures Pieter Hooimeijer,
Dr. Hussien Sharaf Dr Emad Nabil. Dr. Hussien M. Sharaf 2 position := initial + rate * Lexical analyzer 2. Syntax analyzer id 1 := id 2 + id 3 *
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.
COMP 2100 From Python to Java
Chapter 1: An Overview of Computers and Programming Languages
Chapter 1: An Overview of Computers and Programming Languages
C# and the .NET Framework
Introduction to MATLAB
Chapter 1: An Overview of Computers and Programming Languages
All You Ever Wanted to Know About Dynamic Taint Analysis & Forward Symbolic Execution (but might have been afraid to ask) Edward J. Schwartz, Thanassis.
Introduction CSC 111.
Chapter 1: An Overview of Computers and Programming Languages
Tonga Institute of Higher Education IT 141: Information Systems
Simulation And Modeling
Tonga Institute of Higher Education IT 141: Information Systems
Dynamic Binary Translators and Instrumenters
Introduction to Methods and Interfaces
Presentation transcript:

Vineet Kumar and Laurie Hendren McGill University MiX10 First steps to compiling MATLAB to X10

In this talk 1WHY? 2WHAT? 3WOW!

Why? Why not ! motivation and challenges 1

Why MATLAB to X10? I wish my program could run faster ! I wish I could make better use of that super computer ! I wish I had time to learn that cool new language I read about! What do I do about all the programs that I are already written ?

Captain MiX10 comes to rescue Keep programming in MATLAB and translate your MATLAB programs to X10 Run your programs faster No need to learn X10 Make good use of your supercomputing resources

Over 1 million MATLAB users in 2004 and numbers doubling every 1.5 to 2 years. Even more MATLAB users who use free systems Octave or SciLab million monthly google searches for “MATLAB”. Thousands of MATLAB/Simulink books. Users from disciplines in science, engineering and economics in academia as well as industry. Why do we care about MATLAB?

MATLAB no formal language specification dynamically typed flexible syntax unconventional semantics everything is a matrix huge builtin library The job’s not easy MiX10

2 What? Under the hood The McLab project, specific technical challenges and useful X10 features

Frontend McSAFTamerX10 backend Fortran backend Dynamic analysis McVM MATLAB Aspect MATLAB McIR McSAF IR, Kind analysis Tame IR, Callgraph, Analyses The McLab project overview

Source code Apply gradient and filter to an image function[x,y] = rgbFilter(h,w,c,p,g) % h : height of the image % w : width of the image % c : colour of the filter % p : pixel matrix of the image % g : gradient factor filter=ones(h,w); filter=filter*c; %applyFilter=filter; %x = i; for i=1:w x = p(:,i); x = x+gradient(w,g); end x = p; y = applyFilter(p,filter); end Create a filter Apply gradient Apply filter

function[x,y] = rgbFilter(h,w,c,p,g) % h : height of the image % w : width of the image % c : colour of the filter % p : pixel matrix of the image % g : gradient factor filter=ones(h,w); filter=filter*c; %applyFilter=filter; x = i; % for i=1:w %x = p(:,i); %x = x+gradient(w,g); %end x = p; y = applyFilter(p,filter); end McSAF Static Analysis Framework function[x,y] = rgbFilter(h,w,c,p,g) % h : height of the image % w : width of the image % c : colour of the filter % p : pixel matrix of the image % g : gradient factor filter=ones(h,w); filter=filter*c; %applyFilter=filter; %x = i; for i=1:w x = p(:,i); x = x+gradient(w,g); end x = p; y = applyFilter(p,filter); end What happens if we uncomment %applyFilter=filter; ? Is this an error ? McSAF A low-level IR Kind analysis y = applyFilter(p,filter); becomes an array access No, it’s a call to the builtin i();

Tamer function[x,y] = rgbFilter(h,w,c,p,g) % h : height of the image % w : width of the image % c : colour of the filter % p : pixel matrix of the image % g : gradient factor filter=ones(h,w); filter=filter*c; %applyFilter=filter; %x = i; for i=1:w x = p(:,i); x = x+gradient(w,g); end x = p; y = applyFilter(p,filter); end What are the types of h, w, c, p and g ? Is ones(h,w) builtin or user-defined? What is the shape of filter ? Is g real or complex ? What are the types of x and y ?

Tamer function[x,y] = rgbFilter(h,w,c,p,g) % h : height of the image % w : width of the image % c : colour of the filter % p : pixel matrix of the image % g : gradient factor filter=ones(h,w); filter=filter*c; %applyFilter=filter; %x = i; for i=1:w x = p(:,i); x = x+gradient(w,g); end x = p; y = applyFilter(p,filter); end Tamer Very low-level IR Callgraph Type analysis Shape analysis IsComplex analysis

Frontend McSAFTamerX10 backend Fortran backend Dynamic analysis McVM MATLAB Aspect MATLAB McIR McSAF IR, Kind analysis Tame IR, Callgraph, Analyses The McLab project overview

MiX10 IR generator Code transformations Code printer Builtin handler Mix10.x10.x10 Tamer Ir Callgraph Analyses Mix10 IR Transformed IR MiX10 builtins.xml

Builtin methods x = mtimes(a,b); % same as x = a+b; //1 public static def mtimes( a: Array[Double], b:Array[Double]) {a.rank == b.rank}{ val x = new Array[Double](a.region); for (p in a.region){ x(p) = a(p)* b(p); } return x; } //2 public static def mtimes(a:Double, b:Array[Double]){ val x = new Array[Double](b.region); for (p in b.region){ x(p) = a* b(p); } return x; } function[x,y] = rgbFilter(h,w,c,p,g) % h : height of the image % w : width of the image % c : colour of the filter % p : pixel matrix of the image % g : gradient factor filter=ones(h,w); filter=filter.* c; %applyFilter=filter; %x = i; for i=1:w x = p(:,i); x = x+gradient(w,g); end x = p; y = applyFilter(p,filter); end

Builtin methods (contd.) //3 public static def mtimes(a:Array[Double], b:Double){ val x = new Array[Double](a.region); for (p in a.region){ x(p) = a(p)* b; } return x; } //4 public static def mtimes(a:Double, b:Double){ val x: Double; x = a*b; return x; } //And 4 more for complex numbers function[x,y] = rgbFilter(h,w,c,p,g) % h : height of the image % w : width of the image % c : colour of the filter % p : pixel matrix of the image % g : gradient factor filter=ones(h,w); filter=filter.* c; %applyFilter=filter; %x = i; for i=1:w x = p(:,i); x = x+gradient(w,g); end x = p; y = applyFilter(p,filter); end

Should we have all the possible overloaded methods for every builtin used in the generated code ?

That’s what Builtin handler solves! Template based specialization Generates only required overloaded versions Creates a separate class Improves readability

X10 as a target language Nice X10 features

The type ‘Any’ function[x,y] = rgbFilter(h,w,c,p,g) % h : height of the image % w : width of the image % c : colour of the filter % p : pixel matrix of the image % g : gradient factor filter=ones(h,w); filter=filter.* c; %applyFilter=filter; %x = i; for i=1:w x = p(:,i); x = x+gradient(w,g); end x = p; y = applyFilter(p,filter); end return [x as Any, y as Any]; Same idea also used for Cell Arrays

Point and Region API function[x,y] = rgbFilter(h,w,c,p,g) % h : height of the image % w : width of the image % c : colour of the filter % p : pixel matrix of the image % g : gradient factor filter=ones(h,w); filter=filter.* c; %applyFilter=filter; %x = i; for i=1:w x = p(:,i); x = x+gradient(w,g); end x = p; y = applyFilter(p,filter); end mix10_pt_p = Point.make(0, 1-(i as Int)); mix10_ptOff_p = p; x = new Array[Double]( ((p.region.min(0))..(p.region.max(0)))*(1..1), (p:Point(2))=> mix10_ptOff_p(p.operator-(mix10_pt_p))); mix10_pt_p = Point.make(0, 1-(i as Int)); mix10_ptOff_p = p; x = new Array[Double]( ((p.region.min(0))..(p.region.max(0)))*(1..1), (pt:Point(2))=> mix10_ptOff_p(pt.operator-(mix10_pt_p))); Works even when shape is unknown at compile time

3 Wow! Some preliminary results Results for managed and native backends

Benchmarks bubble - bubble sort capr - computes the capacitance per unit length of a coaxial pair of rectangles dich - finds the Dirichlet solution to Laplace’s equation fiff - a finite difference solution to a wave equation mbrt - computes a mandelbrot set nb1d - simulates the gravitational movement of a set of objects in 1 dimension

Compilation flow Java, C++X10MATLAB MiX10 X10c javac x10c++gc++ Managed backend Native backend -O, -NO_CHECKS

Native backend

Managed backend

“The JIT is very unhappy” Optimizer triggered code inlining Resultant code too big for JIT compiler to compile Switched to interpreter Static rank declaration eliminated runtime rank checks Reduced code size for capr enough for JIT compiler to compile Dich was still too large (for HotSpot JIT compiler) Static rank declaration gave significant performance improvements for other benchmarks (upto 30% depending on number of array accesses) Thank you Dave for figuring this out

This was just the beginning Support for vector instructions and parfor loops Analyses and transformations for performance and readability Thank You

Acknowledgements NSERC for supporting this research, in part David Grove for helping us validate and understand some results Anton Dubrau for his help in using Tamer Xu Li for providing valuable suggestions