compiler techniques for memory consistency models
play

Compiler Techniques For Memory Consistency Models Students: Xing - PowerPoint PPT Presentation

Compiler Techniques For Memory Consistency Models Students: Xing Fang (Purdue), Jaejin Lee (Seoul National University), Kyungwoo Lee (Purdue), Zehra Sura (IBM T.J. Watson Research Center), David Wong (Intel KAI Research Lab) Faculty: Sam Midkiff


  1. Compiler Techniques For Memory Consistency Models Students: Xing Fang (Purdue), Jaejin Lee (Seoul National University), Kyungwoo Lee (Purdue), Zehra Sura (IBM T.J. Watson Research Center), David Wong (Intel KAI Research Lab) Faculty: Sam Midkiff (Purdue) David Padua (UIUC) Faculty: Sam Midkiff (Purdue), David Padua (UIUC) smidkiff@purdue.edu

  2. G Goal of this talk l f thi t lk • A brief overview of techniques to enable • A brief overview of techniques to enable stricter consistency models to be incorporated into Cell programming incorporated into Cell programming models – Techniques are broadly applicable Techniques are broadly applicable – Techniques are necessitated by the programming model, not hardware – Techniques are often not necessary when input program is sequential Compilation techniques for Memory Consistency Models 2

  3. H Hardware and Language Models d d L M d l Programmers Language memory model Language memory model Orders enforced by compiler and hardware fences or syncs Compiler Hardware memory model O d Orders enforced by hardware f d b h d H/ W Compilation techniques for Memory Consistency Models 3

  4. O tli Outline • Part I: Introduction – Memory Consistency Models – Compiling for Memory Consistency • Part II: Compiler Analysis – Delay set analysis – Synchronization analysis • Part III: Results and Conclusion Compilation techniques for Memory Consistency Models 4

  5. Wh When do consistency issues arise? d i t i i ? • Issues arise whenever state is shared across different • Issues arise whenever state is shared across different threads of execution • Typically reads/writes to shared memory • Synchronization, I/O, … also require attention be paid to consistency issues – The typical programmer assumes a program will act as if yp p g p g f operations occur in the order written – Not true for most consistency models • We will use shared memory reads/writes in W ill h d d / it i our examples for simplicity. Reads/writes can be DMA operations or synchronization p y Compilation techniques for Memory Consistency Models 5

  6. S Sequential Consistency (SC) ti l C i t (SC) Processor 2 Processor 3 Processor 4 Processor 1 S S tream of tream of Instructions Ordering Requirement g q Compilation techniques for Memory Consistency Models 6

  7. SC i t iti SC intuitive, but no free lunch b t f l h fl flag = 0; a = null ; 0 ll Th Thread 0 d 0 Thread 1 Th d 1 a = f( ); while (flag ==0); flag = 1; flag = 1; b = a; b = a; x[2] = 4; x[2] 4; for (i=0; i<n; i++) { for (i 0; i n; i ) { x[i] = … Compilation techniques for Memory Consistency Models 7

  8. SC is harder to compile than sequential SC i h d t il th ti l •Whether a variable reference can be Wh th i bl f b – strength reduced to a register reference, – hoisted from a loop, – or otherwise moved In part depends on how used in other threads -- requires inter-thread analysis q y Compilation techniques for Memory Consistency Models 8

  9. R l Relaxed Consistency (RC) d C i t (RC) • Like sequential programs only requires • Like sequential programs, only requires relations among variable accesses within a thread to be analyzed when performing y p g optimizations (e.g. dependence/alias analysis) • Examples: p – Weak consistency, Release consistency, Java memory model • Semantics for well synchronized programs • Semantics for well synchronized programs same as SC Compilation techniques for Memory Consistency Models 9

  10. RC RC versus SC SC • SC better for programmability SC b tt f bilit – Fewer re-orderings for programmer to reason about – Compiler cannot naively reorder any memory accesses Compiler cannot naively reorder any memory accesses • RC better for performance – Allow accesses to overlap or be re-ordered • Can we recover performance for SC? – Compiler analysis to determine orders that really need to be enforced Mark Hill, Multiprocessors should support simple memory-consistency models, Mark Hill, Multiprocessors should support simple memory consistency models, IEEE Computer, August 1998 Compilation techniques for Memory Consistency Models 10

  11. When can memory ops be moved? Wh b d? fl flag = 0; a = null; 0 ll Thread 0 Th d 0 Thread 1 Th d 1 a = f( ); While (flag ==0); Conflict edges Program edge flag = 1; b = a; x[2] = 4; x[2] = … Compilation techniques for Memory Consistency Models 11

  12. When can memory ops be moved? Wh b d? fl flag = 0; a = null; 0 ll Thread 0 Th d 0 Thread 1 Th d 1 a = f( ); While (flag ==0); flag = 1; b = a; Oriented conflict edges x[2] = 4; x[2] = … Compilation techniques for Memory Consistency Models 12

  13. H How bad orientations can exist b d i t ti i t fl flag = 0; a = null; 0 ll Thread 0 Th d 0 Th Thread 1 d 1 flag = 1; While (flag ==0); a = f( ); b = a; x[2] = 4; x[2] = … Compilation techniques for Memory Consistency Models 13

  14. Graph for RC -- program edges only exist between dependent references i t b t d d t f fl flag = 0; a = null; 0 ll Thread 0 Th d 0 Thread 1 Th d 1 a = f( ); While (flag ==0); Conflict edges flag = 1; b = a; x[2] = 4; for (i=0; i<n; i++) { x[i] = … Compilation techniques for Memory Consistency Models 14

  15. What a consistency aware compiler must do • Program edges involved in cycles must be • Program edges involved in cycles must be treated like a dependence and enforced • Therefore, a consistency aware compiler must Therefore, a consistency aware compiler must determine intra-thread memory operation orderings that must be enforced because of – Inter-thread relationships I h d l i hi – Traditional dependence relationships • Ordering of operations that cannot be violated • Ordering of operations that cannot be violated because of inter-thread relationships are delays Compilation techniques for Memory Consistency Models 15

  16. Pensieve Compiler for SC P i C il f SC Source Java Source Java Hardware Hardware Bytecode Memory Model Thread Escape Analysis E p n y Program Program Analysis Alias Analysis Synchronization Analysis Synchronization Analysis D l Delay Set Analysis Delay Set Analysis D l S S A A l l i i Ordering Code Re-ordering and Code Constraints Elimination Transformations Elimination Transformations J ikes RVM Barrier Insertion and Optimization Target Machine Code (SC) Target Machine Code (SC) Compilation techniques for Memory Consistency Models 16

  17. How is this handled in current languages? • MPI avoids these issues by not having shared • MPI avoids these issues by not having shared state • OpenMP avoids these issues by requiring OpenMP avoids these issues by requiring – shared state in parallel regions to be in an atomic block – Shared state accessed via reduction, etc – Otherwise results are undefined • Standard Java avoids this by using a relaxed model model • C/C++/Pthreads basically undefined Compilation techniques for Memory Consistency Models 17

  18. Th These work, but … k b t • All of these solutions have problems All f th l ti h bl – Shared memory programming model sometimes useful f l – Undefined results make debugging hard – Most programmers think SC M hi k SC Compilation techniques for Memory Consistency Models 18

  19. O tli Outline • Part I: Introduction – Memory Consistency Models – Compiling for Memory Consistency • Part II: Compiler Analysis – Escape analysis E l i – Alias analysis (simple type based) [Sura, PPoPP05] – Synchronization analysis Synchronization analysis – Delay set analysis • Part III: Results and Conclusion Compilation techniques for Memory Consistency Models 19

  20. Th Thread Escape Analysis d E A l i • Find references to objects that may be accessed • Find references to objects that may be accessed in two or more threads – In Java, these are objects accessed directly, or indirectly, J j y y from static fields or thread object fields • Java does not allow arguments to be passed to thread run methods • Rather, the “arguments” are passed to the thread constructor, and stored in a field in the constructed thread object – Can be modeled as a reachability problem - an object that b d l d h b l bl b h can be reached (directly or indirectly) by something reachable from 2 or more threads thread-escapes. Compilation techniques for Memory Consistency Models 20

  21. Two phase escape analysis p p y [Lee, PACT06] • Uses a slow, off-line analysis to build a very • U l ff li l i t b ild precise connection graph for available classes • Results of this analysis are converted to level • Results of this analysis are converted to level summary form for the on-line phase – The level summary form is used to reconcile reachability The level summary form is used to reconcile reachability information from • Classes not seen during the offline analysis, • Classes that have changed since being seen in the offline Cl h h h d i b i i h ffli analysis Compilation techniques for Memory Consistency Models 21

Recommend


More recommend