1 / 18

Now You C It. Now You Don’t!

Now You C It. Now You Don’t!. Rob Ennals Intel Research Cambridge. 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

chidi
Download Presentation

Now You C It. Now You Don’t!

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Now You C It. Now You Don’t! 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 Now you C it. Now you Don't! (Dec Langs for Multicore)

  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 Now you C it. Now you Don't! (Dec Langs for Multicore)

  4. Trust Programmers Libraries C Existing Code Tools 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 Now you C it. Now you Don't! (Dec Langs for Multicore)

  5. A Solution: Lossless Round Tripping C Programmer Jekyll Programmer • 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 C File Jekyll File C File Jekyll File Now you C it. Now you Don't! (Dec Langs for Multicore)

  6. Another View of C Repository Jekyll Programmer or Tool • 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. C File Jekyll File C Programmer or Tool C File C File Now you C it. Now you Don't! (Dec Langs for Multicore)

  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 Now you C it. Now you Don't! (Dec Langs for Multicore)

  8. Jekyll Features Jekyll All of C Parallel Most of Haskell • Parallel features still in progress. Other features largely implemented. • Use of unsafe features causes a warning unless marked as “unsafe” Unsafe Features Imperative Features Low-Level Features C Types C Expressions Pre-processor Parallel Combinators Effect Typing Atomic Blocks Algebraic Types Type Classes Lambda Expressions Pattern Matching Generic Types Type Safety Optional GC Now you C it. Now you Don't! (Dec Langs for Multicore)

  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 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 Now you C it. Now you Don't! (Dec Langs for Multicore)

  10. 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; _tmp0 = (int*)GC_malloc(sizeof(int)); (*_tmp0) = (*n) * *_cenv->x; 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); } Now you C it. Now you Don't! (Dec Langs for Multicore)

  11. Jekyll Features Encoded using C Macros Jekyll_1.h • Ignored by C compilers • Tell the Jekyll translator when Jekyll features are being used • All macros are very simple (most are defined to nothing) #define unsafe /* nothing */ #define _fwd /* nothing */ #define _temp /* nothing */ #define _localfun /* nothing */ #define _localfunenv /* nothing */ #define _env /* nothing */ … Now you C it. Now you Don't! (Dec Langs for Multicore)

  12. A Language with Two Syntaxes Annotated C Syntax Jekyll Syntax • Translation allow Jekyll to sit on both sides of the fence • Jekyll with transparent to C compilers, but also has an elegant syntax Compatible with C Tools Understood by C Programmers Compatible with existing code Elegant Concise Better fit with new features Translation Now you C it. Now you Don't! (Dec Langs for Multicore)

  13. Common Syntax Tree Representation Parse Check Parse C File AST Jekyll File Print Transform Print Now you C it. Now you Don't! (Dec Langs for Multicore)

  14. Lossless Translation by Twinned Printing AST C 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 Twins Jekyll Tokens Now you C it. Now you Don't! (Dec Langs for Multicore)

  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 -> C -> Jekyll is always lossless • Only edited lines of source code will change. • The programmer is warned in such circumstances. Now you C it. Now you Don't! (Dec Langs for Multicore)

  16. Demo Now you C it. Now you Don't! (Dec Langs for Multicore)

  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 Now you C it. Now you Don't! (Dec Langs for Multicore)

  18. Now you C it. Now you Don't! (Dec Langs for Multicore)

More Related