Project Fortress: A Multicore Language for Scientists and Engineers

Similar documents
Copyright c 2008 Sun Microsystems, Inc. ( Sun ). All rights are reserved by Sun except as expressly stated as follows. Permission to make digital or

ERC 4th Workshop KAIST. Sukyoung Ryu KAIST. August 26, 2010

Fortress: A New Programming Language for Scientific Computing

CS 2210 Sample Midterm. 1. Determine if each of the following claims is true (T) or false (F).

Growing a Syntax. Ryan Culpepper. Eric Allen. Janus Dam Nielsen. Jon Rafkind. Sukyoung Ryu. 1. Introduction. Abstract. Aarhus University

CPS 506 Comparative Programming Languages. Syntax Specification

Alternatives for semantic processing

Chapter 4: LR Parsing

Better Extensibility through Modular Syntax. Robert Grimm New York University

Using Scala for building DSL s

Grammars and Parsing. Paul Klint. Grammars and Parsing

Kristoffer H. Rose. Version /01/07

Quick Start with CASSY Lab. Bi-05-05

Scala, Your Next Programming Language

CS415 Compilers. Syntax Analysis. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

Introduction to Java

Compilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam

Last class. CS Principles of Programming Languages. Introduction. Outline

Semantic Analysis. Lecture 9. February 7, 2018

EDAN65: Compilers, Lecture 06 A LR parsing. Görel Hedin Revised:

Academic Formalities. CS Modern Compilers: Theory and Practise. Images of the day. What, When and Why of Compilers

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages. Lambda calculus

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking

CS 6110 S14 Lecture 1 Introduction 24 January 2014

The SPL Programming Language Reference Manual

Sukyoung Ryu. Member of Technical Staff Mailstop UBUR Sun Microsystems Laboratories 35 Network Dr. Burlington, Massachusetts

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

Programming Languages Lecture 15: Recursive Types & Subtyping

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

Concepts of programming languages

Lecture 2: SML Basics

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS522 Programming Language Semantics

Parsing. Roadmap. > Context-free grammars > Derivations and precedence > Top-down parsing > Left-recursion > Look-ahead > Table-driven parsing

Homework. Lecture 7: Parsers & Lambda Calculus. Rewrite Grammar. Problems

4. Lexical and Syntax Analysis

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Operational Semantics. One-Slide Summary. Lecture Outline

Programming Languages (PL)

JavaCC Parser. The Compilation Task. Automated? JavaCC Parser

Syntax Analysis. Chapter 4

4. Lexical and Syntax Analysis

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Programming Lecture 3

Building Compilers with Phoenix

Compiler Theory. (Semantic Analysis and Run-Time Environments)

Scheme: Expressions & Procedures

Parsing II Top-down parsing. Comp 412

Earlier edition Dragon book has been revised. Course Outline Contact Room 124, tel , rvvliet(at)liacs(dot)nl

The package paresse. Le TEXnicien de surface February 16, 2013

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242

Programming Languages

Contents. Chapter 1 SPECIFYING SYNTAX 1

First Programming Language in CS Education The Arguments for Scala

Abstract register machines Lecture 23 Tuesday, April 19, 2016

Special Topics: Programming Languages

Context-free Grammars

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS422 Programming Language Semantics

Math Typesetting and Authoring

Comp 411 Principles of Programming Languages Lecture 3 Parsing. Corky Cartwright January 11, 2019

ProjectFortress: Run your whiteboard, in parallel, on the JVM

The compilation process is driven by the syntactic structure of the program as discovered by the parser

Review. CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Let bindings (CBV) Adding Stuff. Booleans and Conditionals

CSE 130 Programming Language Principles & Paradigms Lecture # 5. Chapter 4 Lexical and Syntax Analysis

Programming Languages Lecture 14: Sum, Product, Recursive Types

3. Syntax Analysis. Andrea Polini. Formal Languages and Compilers Master in Computer Science University of Camerino

3. Parsing. Oscar Nierstrasz

Compilers. Yannis Smaragdakis, U. Athens (original slides by Sam

10/5/17. Lexical and Syntactic Analysis. Lexical and Syntax Analysis. Tokenizing Source. Scanner. Reasons to Separate Lexical and Syntax Analysis

Acknowledgement. CS Compiler Design. Semantic Processing. Alternatives for semantic processing. Intro to Semantic Analysis. V.

COP4020 Programming Languages. Syntax Prof. Robert van Engelen

Context-Free Grammar (CFG)

CPS Conversion. Di Zhao.

CSCE 314 Programming Languages. Type System

The Untyped Lambda Calculus

Parsing. source code. while (k<=n) {sum = sum+k; k=k+1;}

Parsing Expression Grammar and Packrat Parsing

Tabella dei caratteri ASCII e UNICODE

Syntax Analysis. COMP 524: Programming Language Concepts Björn B. Brandenburg. The University of North Carolina at Chapel Hill

CSCI312 Principles of Programming Languages!

Sémantique des Langages de Programmation (SemLP) DM : Region Types

Semantics of programming languages

Pure (Untyped) λ-calculus. Andrey Kruglyak, 2010

Lambda Calculus. Type Systems, Lectures 3. Jevgeni Kabanov Tartu,

About the Authors... iii Introduction... xvii. Chapter 1: System Software... 1

CS152 Programming Language Paradigms Prof. Tom Austin, Fall Syntax & Semantics, and Language Design Criteria

Types of parsing. CMSC 430 Lecture 4, Page 1

CS 242. Fundamentals. Reading: See last slide

Parsers. Xiaokang Qiu Purdue University. August 31, 2018 ECE 468

Object-oriented Compiler Construction

LL(k) Compiler Construction. Choice points in EBNF grammar. Left recursive grammar

Syntax. 2.1 Terminology

6.001 Notes: Section 15.1

Monday, September 13, Parsers

2. Unlock the Customization Features: The Edit Button Click the "Edit" button on the Dashboard Home Page to unlock the customization features.

How do LL(1) Parsers Build Syntax Trees?

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

mdput for mathematical typesetting with Adobe Utopia Paul Pichaureau January 29, 2006

News from the Wrapper

Wednesday, September 9, 15. Parsers

Parsers. What is a parser. Languages. Agenda. Terminology. Languages. A parser has two jobs:

Transcription:

Project Fortress: A Multicore Language for Scientists and Engineers Sukyoung Ryu Department of Computer Science Korea Advanced Institute of Science and Technology December 13, 2009

Copyright c 2009 Sun Microsystems, Inc. ( Sun ). All rights are reserved by Sun except as expressly stated as follows. Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted, provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, or republish, to post on servers, or to redistribute to lists, requires prior specific written permission of Sun. 1

Project Fortress A multicore language for scientists and engineers 2

Project Fortress A multicore language for scientists and engineers Run your whiteboard in parallel! 3

Project Fortress A multicore language for scientists and engineers Run your whiteboard in parallel! v norm = v/ v a k x k k 1:n C = A B y = 3x sin x cos 2x log log x 4

Project Fortress A multicore language for scientists and engineers Run your whiteboard in parallel! v norm = v/ v a k x k k 1:n C = A B y = 3x sin x cos 2x log log x 5

Project Fortress A multicore language for scientists and engineers Run your whiteboard in parallel! v norm = v/ v a k x k k 1:n C = A B y = 3x sin x cos 2x log log x Growing a Language Guy L. Steele Jr., keynote talk, OOPSLA 1998 6

Project Fortress A multicore language for scientists and engineers Run your whiteboard in parallel! v norm = v/ v a k x k k 1:n C = A B y = 3x sin x cos 2x log log x Growing a Language Guy L. Steele Jr., keynote talk, OOPSLA 1998 Parsing syntax, formal semantics, and safety 7

Project Fortress Fortress is a growable, mathematically oriented, parallel programming language for scientific applications. Started under Sun/DARPA HPCS program, 2003 2006. Fortress is now an open-source project with international participation. The Fortress 1.0 release (March 2008) synchronized the specification and implementation. Moving forward, we are growing the language and libraries and developing a compiler. 8

Mathematical Syntax 9

Mathematical Syntax Integrated mathematical and object-oriented notation Supports a stylistic spectrum that runs from Fortran to Java TM and sticks out at both ends! > More conventionally mathematical than Fortran Compare a*x**2+b*x+c and a x 2 + b x + c > More object-oriented than Java Multiple inheritance Numbers, booleans, and characters are objects > To find the size of a set S : either S or S.size If you prefer #S, defining it is a one-liner. 10

Mathematical Syntax Using Unicode Full Unicode character set available for use, including mathematical operators and Greek letters: α β γ δ ɛ ζ η θ ι κ λ µ ξ π ρ σ / φ χ ψ ω Γ Θ and so on Use of funny characters is under the control of libraries (and therefore users) 11

Mathematical Syntax Example NAS NPB 1 Specification 12

Mathematical Syntax Example NAS NPB 2.3 Serial Code in Fortran 13

Mathematical Syntax Example NAS NPB 1 Specification in Fortress 14

Mathematical Syntax by Fortify Emacs-based code formatter Fortress programs can be typed on ASCII keyboards. Code automatically formatted for processing by L A TEX sum: R64 := 0 for k 1 : n do a k := (1 α)b k sum += c k x k end All code on these slides was formatted by this tool. 15

Mathematical Syntax by Fortify Emacs-based code formatter Fortress programs can be typed on ASCII keyboards. Code automatically formatted for processing by L A TEX sum: R64 := 0 for k 1 : n do a k := (1 α)b k sum += c k x k end sum: RR64 := 0 for k<-1:n do a[k] := (1-alpha)b[k] sum += c[k] x^k end All code on these slides was formatted by this tool. 16

Mathematical Syntax Using Editors Fortress mode for Emacs > Provides syntax coloring > Some automatic formatting > Unicode font conversion Fortress NetBeans TM plug-in > Syntax highlighting > Mark occurrences > Instant rename These tools were contributed by people outside Sun. 17

Parallelism by Default 18

A Parallel Language High productivity for multicore, SMP, and cluster computing Hard to write a program that isn t potentially parallel Support for parallelism at several levels > Expressions > Loops, reductions, and comprehensions > Parallel code regions > Explicit multithreading Shared global address space model with shared data Thread synchronization through atomic blocks and transactional memory 19

Implicit Parallelism Tuples (a, b, c) = (f(x), g(y), h(z)) Functions, operators, method call recipients, and their arguments e 1 e 2 e 1 + e 2 e 1 (e 2 ) e 1.method(e 2 ) Expressions with generators s = k 1:n c k x k { x 2 x xs, x > 43 } for k 1 : n do sum += c k x k end sum += c k x k, k 1 : n 20

Recursive Subdivision and Work Stealing k 1#1024 c k x k 21

Growable Language 22

Growing a Language Languages have gotten much bigger. You can t build one all at once. Therefore it must grow over time. What happens if you design it to grow? How does the need to grow affect the design? Need to grow a user community, too. 23

Design Strategy Consider how a proposed language feature might be provided by a library rather than building features directly into the compiler. This requires control over both syntax and semantics, not just the ability to add new functions and methods. 24

for Loops in Fortress for generators do body end Generator list produces data items (usually in parallel). Body computation is executed for each data item. Whether/how they run in parallel is defined in the libraries. 25

for Loops in Fortress for generators do body end for i {1, 2}, j {3, 4} do println ( i, j ) end Generator list produces data items (usually in parallel). Body computation is executed for each data item. Whether/how they run in parallel is defined in the libraries. In Fortress, for loops are parallel by default. (2, 3) (1, 3) (2, 4) (1, 4) 26

Desugaring for Loops g 1 = {1, 2} g 2 = {3, 4} for i g 1, j g 2 do println ( i, j ) end 27

Desugaring for Loops g 1 = {1, 2} g 2 = {3, 4} for i g 1, j g 2 do println ( i, j ) end desugars to g 1.loop(fn i g 2.loop(fn j println ( i, j ) )) 28

Desugaring for Loops Design strategy Consider how a proposed language feature might be provided by a library rather than building features directly into the compiler. 29

Desugaring for Loops Design strategy Consider how a proposed language feature might be provided by a library rather than building features directly into the compiler. for loops desugaring in the current implementation is built directly into the interpreter. 30

Desugaring for Loops Design strategy Consider how a proposed language feature might be provided by a library rather than building features directly into the compiler. for loops desugaring in the current implementation is built directly into the interpreter. for loops desugaring by syntactic abstraction is provided by a library. 31

Syntactic Abstraction a New syntax indistinguishable from the core syntax Similar syntax for definition/use of a language extension Composition of independent language extensions Expansion into other language extensions Mutually recursive definition of a language extension a Growing a Syntax, Eric Allen, Ryan Culpepper, Janus Dam Nielsen, Jon Rafkind, and Sukyoung Ryu. The Foundations of Object-Oriented Languages 2009 32

Syntactic Abstraction Example Use of a new syntax xml 2 = <note><to>tove</to></eton> println Xml: xml 2 33

Syntactic Abstraction Example Use of a new syntax xml 2 = <note><to>tove</to></eton> println Xml: xml 2 Definition of a new syntax grammar xml extends {Expression, Symbols} Expr := x: XExpr <[ x ]> XExpr: Element : Expr := b: XmlStart c: XmlContent e: XmlEnd <[ Element(b, c, e) asif Content ]> b: XmlStart e: XmlEnd <[ Element(b, e) asif Content ]> x: XmlComplete <[ Element(x) asif Content ]>... end 34

Parsing Fortress Syntax 35

Challenges in Parsing Parsing juxtaposition requires types of juxtaposed items. Operator fixity is dependent on whitespace context. Program itself defines how it is parsed. Language syntax changes constantly. 36

Challenges in Parsing Parsing juxtaposition requires types of juxtaposed items. 3 x sin x cos 2 x log log x Operator fixity is dependent on whitespace context. Program itself defines how it is parsed. Language syntax changes constantly. 37

Challenges in Parsing Parsing juxtaposition requires types of juxtaposed items. ((((3 x) (sin x)) (cos (2 x))) (log (log x))) Operator fixity is dependent on whitespace context. Program itself defines how it is parsed. Language syntax changes constantly. 38

Challenges in Parsing Parsing juxtaposition requires types of juxtaposed items. ((((3 x) (sin x)) (cos (2 x))) (log (log x))) Operator fixity is dependent on whitespace context. { x x myset, 3 x } Program itself defines how it is parsed. Language syntax changes constantly. 39

Challenges in Parsing Parsing juxtaposition requires types of juxtaposed items. ((((3 x) (sin x)) (cos (2 x))) (log (log x))) Operator fixity is dependent on whitespace context. { x x myset, 3 x } Program itself defines how it is parsed. Language syntax changes constantly. 40

Challenges in Parsing Parsing juxtaposition requires types of juxtaposed items. ((((3 x) (sin x)) (cos (2 x))) (log (log x))) Operator fixity is dependent on whitespace context. { x x myset, 3 x } Program itself defines how it is parsed. xml = <to>tove</to> Language syntax changes constantly. 41

Challenges in Parsing Parsing juxtaposition requires types of juxtaposed items. ((((3 x) (sin x)) (cos (2 x))) (log (log x))) Operator fixity is dependent on whitespace context. { x x myset, 3 x } Program itself defines how it is parsed. xml = <to>tove</to> grammar xml extends {Expression, Symbols}... Language syntax changes constantly. 42

Challenges in Parsing Parsing juxtaposition requires types of juxtaposed items. ((((3 x) (sin x)) (cos (2 x))) (log (log x))) Operator fixity is dependent on whitespace context. { x x myset, 3 x } Program itself defines how it is parsed. xml = <to>tove</to> grammar xml extends {Expression, Symbols}... Language syntax changes constantly. language being developed by a research lab. 43

Parsing Fortress Syntax Parsing juxtaposition requires types of juxtaposed items. two-phase parsing: Juxt(3,x,sin,x,cos,2,x,log,log,x) Operator fixity is dependent on whitespace context. Program itself defines how it is parsed. Language syntax changes constantly. 44

Parsing Fortress Syntax Parsing juxtaposition requires types of juxtaposed items. two-phase parsing: Juxt(3,x,sin,x,cos,2,x,log,log,x) Operator fixity is dependent on whitespace context. space-sensitive parsing: Expression,NoNewlineExpr,NoSpaceExpr Program itself defines how it is parsed. Language syntax changes constantly. 45

Parsing Fortress Syntax Parsing juxtaposition requires types of juxtaposed items. two-phase parsing: Juxt(3,x,sin,x,cos,2,x,log,log,x) Operator fixity is dependent on whitespace context. space-sensitive parsing: Expression,NoNewlineExpr,NoSpaceExpr Program itself defines how it is parsed. syntax normalization: parsing transformation Language syntax changes constantly. 46

Parsing Fortress Syntax Parsing juxtaposition requires types of juxtaposed items. two-phase parsing: Juxt(3,x,sin,x,cos,2,x,log,log,x) Operator fixity is dependent on whitespace context. space-sensitive parsing: Expression,NoNewlineExpr,NoSpaceExpr Program itself defines how it is parsed. syntax normalization: parsing transformation Language syntax changes constantly. automatic generation: ASTGen and Rats! 47

Parsing Techniques Tried JavaCC: LL(k) CUP: LALR(1) Hand-Written Recursive Descent Elkhound: GLR(1) Rats!: Packrat 48

Parsing Techniques Tried JavaCC: LL(k) requires big lookahead CUP: LALR(1) requires big lookahead Hand-Written Recursive Descent hard to understand, implement, adapt to syntax changes Elkhound: GLR(1) no abstraction mechanism, not scalable Rats!: Packrat 49

Rats! Parser Generator: Pros Unlimited lookahead Close to EBNF notation Module system Linear time performance Global parsing state 50

Rats! Parser Generator: Cons Syntax error reporting > Unlimited lookahead > Module system Memory consumption > Linear time performance Left-recursive productions Subtle grammatical errors 51

Rats! Parser Generator: Cons Syntax error reporting > Delimiter checker: pre-parsing > Syntax checker: post-parsing Memory consumption > transient productions Left-recursive productions: OMeta parsing algorithm,... Subtle grammatical errors > Extensive regression testing 52

Parsing Fortress Syntax Parsing juxtaposition requires types of juxtaposed items. Operator fixity is dependent on whitespace context. Program itself defines how it is parsed. Language syntax changes constantly. 53

Parsing Fortress Syntax Parsing juxtaposition requires types of juxtaposed items. Operator fixity is dependent on whitespace context. Program itself defines how it is parsed. Language syntax changes constantly. Fortress parser family > Abstract Syntax Tree: ASTGen > Syntactic abstraction: syntax normalization > Delimiter checker: pre-parsing > Parser: Rats! > Syntax checker: post-parsing > Type checker: juxtaposition 54

Formal Semantics and Safety 55

56

Formal Semantics Formalized Semantics > Provides unambiguous specification for compiler writers Fewer insidious bugs More portable code > Allows proofs of soundness and formal analysis Mechanized Semantics > Tests soundness of language semantics by PLT Redex 57

Type System Traits are like Java TM interfaces, but may contain code Objects are like Java TM classes, but may not be extended Multiple inheritance of code (but not fields) > Objects with fields are the leaves of the hierarchy Traits and objects may be parameterized > Parameters may be types or compile-time constants Primitive types are first-class > Booleans, integers, floats, characters are all objects 58

Safety in Fortress Strong static type checking > Including dimensions and units Bounds checking > Enclose bounds in the type, check at compile time Atomic transactional synchronization Garbage collection Design-by-contract > requires, ensures, invariant clauses Test-driven development > properties and tests 59

Current Task: Compiler Development Better syntax error messages Full static type checker and various static guarantees Static type inference to reduce visual clutter Code generation > Initially targeted to JVM for full multithreaded platform independence > After that, VM customization for Fortress-specific optimizations Collaboration with universities and individuals 60

Conclusion Help scientists and engineers build the programs with higher: Productivity Performance Correctness 61

Conclusion Help scientists and engineers build the programs with higher: Productivity > Mathematical syntax > Growable language Performance > Parallelism by default Correctness > Formal semantics and safety 62

Conclusion Help scientists and engineers build the programs with higher: Productivity > Mathematical syntax > Growable language Performance > Parallelism by default Correctness > Formal semantics and safety... Thanks again for all the work you guys have put into this, There is fortress code being used in the wild (it is REALLY handy if the code needs to be audited and we have a math based spec.) blair (ProjectFortress community) 63