Now You C It Now You Dont Rob
Now You C It. Now You Don’t! Rob Ennals Intel Research Cambridge
The World has Changed 2 Then Now Parallelism an exotic curiosity Multicore chips the norm Slow inter-chip communication Fast on-die communication Parallel chunks must be large Parallel chunks can be tiny Uni-processor performance increasing rapidly Uni-processor performance stalling, multicore storming Not worthwhile for languages, tools, or programmers to pay attention to parallel hardware Essential that languages, tools and programmers pay attention to multicore 1/16/06 Now you C it. Now you Don't! (Dec Langs for Multicore)
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) 3 Imperative Declarative Very fast in a single core Often slower on a single core Hard to express parallelism Easier to express parallelism Widely known and used Little known or used 1/16/06 Now you C it. Now you Don't! (Dec Langs for Multicore)
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 Trust Programmers Libraries C Existing Code 4 1/16/06 Now you C it. Now you Don't! Tools (Dec Langs for Multicore)
A Solution: Lossless Round Tripping C Programmer Jekyll Programmer C 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 5 1/16/06 Now you C it. Now you Don't! (Dec Langs for Multicore)
Another View of C Repository Jekyll Programmer or Tool C File Jekyll File C Programmer or Tool 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. 6 1/16/06 Now you C it. Now you Don't! (Dec Langs for Multicore)
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 7 1/16/06 Now you C it. Now you Don't! C Tools (Dec Langs for Multicore)
Jekyll Features Jekyll Parallel Most of Haskell All of C Parallel Combinators Effect Typing Atomic Blocks Algebraic Types Type Classes Lambda Expressions Pattern Matching Generic Types Type Safety Optional GC Unsafe Features Imperative Features Low-Level Features C Types C Expressions Pre-processor Parallel features still in progress. Other features largely implemented. Use of unsafe features causes a warning unless marked as “unsafe” 8 1/16/06 Now you C it. Now you Don't! (Dec Langs for Multicore)
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 manipulate combinators Relies on Jekyll’s lambda expressions Effect Typing - ensure threads are cleanly separated – Use linear types + regions + effect types – Determine what a thread can touch – Relies on Jekyll’s 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 9 1/16/06 Now you C it. Now you Don't! (Dec Langs for Multicore)
Encoding Jekyll Features into C - Example List<int>* multlist(List<int>* 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; _tmp 0 = (int*)GC_malloc(sizeof(int)); (*_tmp 0) = (*n) * *_cenv->x; return _tmp; } List _p(int)* multlist(List _p(int)* l, int x){ _temp struct multlist_lam_env _f 0_env = {&x}; return List_par_map(_env NULL, l, _localfun (*(*)(void*, a*))multlist_lam); } 10 1/16/06 Now you C it. Now you Don't! (Dec Langs for Multicore)
Jekyll Features Encoded using C Macros Jekyll_1. h #define #define … unsafe _fwd _temp _localfunenv _env /* /* /* nothing 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) 11 1/16/06 Now you C it. Now you Don't! (Dec Langs for Multicore)
A Language with Two Syntaxes Annotated C Syntax Jekyll Syntax Compatible with C Tools Elegant Understood by C Programmers Concise Compatible with existing code Better fit with new features Translation allow Jekyll to sit on both sides of the fence Jekyll with transparent to C compilers, but also has an elegant syntax 12 1/16/06 Now you C it. Now you Don't! (Dec Langs for Multicore)
Common Syntax Tree Representation Parse C File 1/16/06 Parse Jekyll File AST Print 13 Check Transform Now you C it. Now you Don't! Print (Dec Langs for Multicore)
Lossless Translation by Twinned Printing C Tokens Twins AST 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 14 1/16/06 Now you C it. Now you Don't! (Dec Langs for Multicore)
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 -> C -> Jekyll is always lossless Only edited lines of source code will change. The programmer is warned in such circumstances. 15 1/16/06 Now you C it. Now you Don't! (Dec Langs for Multicore)
Demo 16 1/16/06 Now you C it. Now you Don't! (Dec Langs for Multicore)
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 17 1/16/06 Now you C it. Now you Don't! (Dec Langs for Multicore)
18 1/16/06 Now you C it. Now you Don't! (Dec Langs for Multicore)
- Slides: 18