Now You C It. Now You Don - PowerPoint PPT Presentation

About This Presentation
Title:

Now You C It. Now You Don

Description:

Now You C It. Now You Don t! Rob Ennals Intel Research Cambridge The World has Changed An Opportunity for Declarative Languages Parallelisability is more important ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 19
Provided by: rennals
Learn more at: http://glew.org
Category:
Tags: don | now | problem | threads | with

less

Transcript and Presenter's Notes

Title: Now You C It. Now You Don


1
Now You C It. Now You Dont!
  • Rob EnnalsIntel Research Cambridge

2
The World has Changed
Then
Now
Multicore chips the norm Fast on-die
communication Parallel chunks can be
tiny Uni-processor performance stalling,
multicore storming Essential that
languages,tools and programmers pay attention
to multicore
Parallelism an exotic curiosity Slow inter-chip
communication Parallel chunks must be
large Uni-processor performanceincreasing
rapidly Not worthwhile for languages, tools, or
programmers to pay attention to parallel hardware
3
An Opportunity for Declarative Languages
  • Parallelisability is more important than straight
    line performance
  • Number of cores set to double every 18 months
  • Declarative languages make parallelism easier
  • Easier to isolate parallel threads (pure
    functions, effect systems, etc)
  • Easier to express parallel algorithms (closures,
    combinators, etc)

Imperative
Declarative
  • Very fast in a single core
  • Hard to express parallelism
  • Widely known and used
  • Often slower on a single core
  • Easier to express parallelism
  • Little known or used

4
A Problem Language Switching Costs
  • Much important software is currently written in C
  • Even if not the most lines of code, probably most
    of the cycles
  • Moving to a new language incurs high switching
    costs
  • Programmers, tools, libraries, and existing code,
    all tied to C

5
A Solution Lossless Round Tripping
C Programmer
Jekyll Programmer
C File
Jekyll File
C File
Jekyll File
  • Jekyll is a high level functional programming
    language
  • Featuring most of the features of Haskell more
  • Jekyll can be translated losslessly to and from C
  • Preserving layout, formatting, comments,
    everything
  • C code is readable and editable

6
Another View of C
Repository
Jekyll Programmer or Tool
C File
Jekyll File
C Programmer or Tool
C File
C File
  • Authoritative source code can stay as C
  • But programmers and tools can also view it as
    Jekyll
  • C Programmers need not know Jekyll is even being
    used.

7
Switching Costs are Reduced
  • Programmers and Tools can still use the C
    version.
  • Existing C code can stay in C
  • Although there may be benefit to be had from
    modifying it
  • If Jekyll ceases to be maintained, just use the C

C Trust
C Programmers
C Libraries
Jekyll
Existing C Code
C Tools
8
Jekyll Features
Jekyll
All of C
Most of Haskell
Parallel
Unsafe Features Imperative Features Low-Level
Features C Types C Expressions Pre-processor
Algebraic Types Type Classes Lambda
Expressions Pattern Matching Generic Types Type
Safety Optional GC
Parallel Combinators Effect Typing Atomic Blocks
  • Parallel features still in progress. Other
    features largely implemented.
  • Use of unsafe features causes a warning unless
    marked as unsafe

9
Jekyll Parallel Features (in progress)
  • Parallel Combinators - express parallelism at a
    higher level
  • Use high level concepts such as parallel map,
    reduce, pipeline, etc
  • Easily write new combinators
  • Write tools that understand and manipulate
    combinators
  • Relies on Jekylls lambda expressions
  • Effect Typing - ensure threads are cleanly
    separated
  • Use linear types regions effect types
  • Determine what a thread can touch
  • Relies on Jekylls type-safe foundation
  • Atomic Blocks - avoid the mess of locks
  • Simple, blocking semantics (no STM required, can
    be just a global lock)
  • Translate to locking, or use hardware

10
Encoding Jekyll Features into C - Example
Listltintgt multlist(Listltintgt l, int x) return
par_map (l) int n ret new (n) x
_localfunenv struct multlist_lam_env int
x _localfun int multlist_lam(struct
multlist_lam_env _cenv, int n) _temp int
_tmp _tmp0 (int)GC_malloc(sizeof(int)) (_
tmp0) (n) _cenv-gtx return _tmp List
_p(int) multlist(List _p(int) l, int x) _temp
struct multlist_lam_env _f0_env x return
List_par_map(_env NULL,l,_localfun
(()(void,a))multlist_lam)
11
Jekyll Features Encoded using C Macros
Jekyll_1.h
define unsafe / nothing / define _fwd /
nothing / define _temp / nothing / define
_localfun / nothing / define _localfunenv /
nothing / define _env / nothing /
  • Ignored by C compilers
  • Tell the Jekyll translator when Jekyll features
    are being used
  • All macros are very simple (most are defined to
    nothing)

12
A Language with Two Syntaxes
Annotated C Syntax
Jekyll Syntax
Compatible with C Tools Understood by C
Programmers Compatible with existing code
Elegant Concise Better fit with new features
Translation
  • Translation allow Jekyll to sit on both sides of
    the fence
  • Jekyll with transparent to C compilers, but also
    has an elegant syntax

13
Common Syntax Tree Representation
Parse
Parse
Check
AST
C File
Jekyll File
Print
Print
Transform
14
Lossless Translation by Twinned Printing
AST
C Tokens
Twins
Jekyll Tokens
  • Every Jekyll token is twinned with a C token
  • Twinned tokens always have the same whitespace
  • Thus allowing whitespace to be preserved during
    translation
  • Some C tokens may be un-twinned (see next slide)
  • Some Jekyll-only features need more C tokens than
    Jekyll tokens

15
An Issue Untwinned C tokens
  • Problem
  • Whitespace is NOT preserved for untwinned C
    tokens
  • But
  • Untwinned tokens only appear when Jekyll-only
    features are used.
  • Whitespace is only lost when a C programmer edits
    such code.
  • Thus this is ok, since
  • All existing C code is unaffected.
  • Jekyll -gt C -gt Jekyll is always lossless
  • Only edited lines of source code will change.
  • The programmer is warned in such circumstances.

16
Demo
17
Conclusions
  • Multicore is a great opportunity for declarative
    languages
  • But many developers are tied into C
  • Jekyll overcomes switching costs through
    lossless translation
  • Download Jekyll now
  • http//jekyllc.sf.net

18
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com