petabricks
play

PetaBricks A Language and Compiler for Algorithmic Choice Jason - PowerPoint PPT Presentation

PetaBricks A Language and Compiler for Algorithmic Choice Jason Ansel Cy Chan Yee Lok Wong Marek Olszewski Qin Zhao Alan Edelman Saman Amarasinghe MIT - CSAIL June 16, 2009 Jason Ansel (MIT) PetaBricks June 16, 2009 1 / 47


  1. Introduction Language & Compiler Overview Sort algorithm timings 1 0.0025 InsertionSort QuickSort 0.002 0.0015 Time (s) 0.001 0.0005 0 0 250 500 750 1000 1250 1500 1750 Input Size 1 On an 8-way Xeon E7340 system Jason Ansel (MIT) PetaBricks June 16, 2009 8 / 47

  2. Introduction Language & Compiler Overview Sort algorithm timings 1 0.0025 InsertionSort QuickSort MergeSort 0.002 0.0015 Time (s) 0.001 0.0005 0 0 250 500 750 1000 1250 1500 1750 Input Size 1 On an 8-way Xeon E7340 system Jason Ansel (MIT) PetaBricks June 16, 2009 8 / 47

  3. Introduction Language & Compiler Overview Sort algorithm timings 1 0.0025 InsertionSort QuickSort MergeSort RadixSort 0.002 0.0015 Time (s) 0.001 0.0005 0 0 250 500 750 1000 1250 1500 1750 Input Size 1 On an 8-way Xeon E7340 system Jason Ansel (MIT) PetaBricks June 16, 2009 8 / 47

  4. Introduction Language & Compiler Overview Sort algorithm timings 1 0.0025 InsertionSort QuickSort MergeSort RadixSort 0.002 Autotuned 0.0015 Time (s) 0.001 0.0005 0 0 250 500 750 1000 1250 1500 1750 Input Size 1 On an 8-way Xeon E7340 system Jason Ansel (MIT) PetaBricks June 16, 2009 8 / 47

  5. Introduction Language & Compiler Overview Timings on different architectures Trained on Mobile Xeon 1-way Xeon 8-way Niagara Mobile - 1.09x 1.67x 1.47x Run on Xeon 1-way 1.61x - 2.08x 2.50x Xeon 8-way 1.59x 2.14x - 2.35x Niagara 1.12x 1.51x 1.08x - Jason Ansel (MIT) PetaBricks June 16, 2009 9 / 47

  6. Introduction Language & Compiler Overview Timings on different architectures Trained on Mobile Xeon 1-way Xeon 8-way Niagara Mobile - 1.09x 1.67x 1.47x Run on Xeon 1-way 1.61x - 2.08x 2.50x Xeon 8-way 1.59x 2.14x - 2.35x Niagara 1.12x 1.51x 1.08x - Jason Ansel (MIT) PetaBricks June 16, 2009 9 / 47

  7. Introduction Language & Compiler Overview Timings on different architectures Trained on Mobile Xeon 1-way Xeon 8-way Niagara Mobile - 1.09x 1.67x 1.47x Run on Xeon 1-way 1.61x - 2.08x 2.50x Xeon 8-way 1.59x - 2.35x 2.14x Niagara 1.12x 1.51x 1.08x - Jason Ansel (MIT) PetaBricks June 16, 2009 9 / 47

  8. Introduction Why choices Outline Introduction 1 Motivating Example Language & Compiler Overview Why choices PetaBricks Language 2 Key Ideas Compilation Example Other Language Features Results 3 Benchmarks Scalability Variable Accuracy Conclusion 4 Final thoughts Jason Ansel (MIT) PetaBricks June 16, 2009 10 / 47

  9. Introduction Why choices Early compilers Constrained Input Language (No choices) Parsing Early computers (and compilers) were weak Code Gen Jason Ansel (MIT) PetaBricks June 16, 2009 11 / 47

  10. Introduction Why choices Early compilers Constrained Input Language (No choices) Parsing Early computers (and compilers) were weak Code Gen Parsing and code generation dominated compilation Jason Ansel (MIT) PetaBricks June 16, 2009 11 / 47

  11. Introduction Why choices Early compilers Constrained Input Language (No choices) Parsing Early computers (and compilers) were weak Code Gen Parsing and code generation dominated compilation Needed a constrained input language to simplify compilation Jason Ansel (MIT) PetaBricks June 16, 2009 11 / 47

  12. Introduction Why choices Current compilers Constrained Input Language Current computers are much more powerful (No choices) Compilers can do a lot more Parsing Exposing Choices Decisions Code Gen Jason Ansel (MIT) PetaBricks June 16, 2009 12 / 47

  13. Introduction Why choices Current compilers Constrained Input Language Current computers are much more powerful (No choices) Compilers can do a lot more Parsing Input language is still constraining Exposing Choices Decisions Code Gen Jason Ansel (MIT) PetaBricks June 16, 2009 12 / 47

  14. Introduction Why choices Current compilers Constrained Input Language Current computers are much more powerful (No choices) Compilers can do a lot more Parsing Input language is still constraining Compilation dominated by exposing choices Exposing Choices Decisions Code Gen Jason Ansel (MIT) PetaBricks June 16, 2009 12 / 47

  15. Introduction Why choices Current compilers Constrained Input Language Current computers are much more powerful (No choices) Compilers can do a lot more Parsing Input language is still constraining Compilation dominated by exposing choices Input language specifies only one Exposing Choices Algorithmic choice Iteration order choice Parallelism strategy choice Data layout choice Decisions Code Gen Jason Ansel (MIT) PetaBricks June 16, 2009 12 / 47

  16. Introduction Why choices Current compilers Constrained Input Language Current computers are much more powerful (No choices) Compilers can do a lot more Parsing Input language is still constraining Compilation dominated by exposing choices Input language specifies only one Exposing Choices Algorithmic choice Iteration order choice Parallelism strategy choice Data layout choice Decisions Compiler must perform heroic analysis to reconstruct Code other choices Gen Jason Ansel (MIT) PetaBricks June 16, 2009 12 / 47

  17. Introduction Why choices PetaBricks compiler Rich Input Language (w/ choices) Parsing We propose explicit choices in the language Exploring Choices & Making Decisions Code Gen Jason Ansel (MIT) PetaBricks June 16, 2009 13 / 47

  18. Introduction Why choices PetaBricks compiler Rich Input Language (w/ choices) Parsing We propose explicit choices in the language The programmer defines the space of legal Algorithmic choices Exploring Choices Iteration orders (include parallel) & Making Decisions Data layouts Code Gen Jason Ansel (MIT) PetaBricks June 16, 2009 13 / 47

  19. Introduction Why choices PetaBricks compiler Rich Input Language (w/ choices) Parsing We propose explicit choices in the language The programmer defines the space of legal Algorithmic choices Exploring Choices Iteration orders (include parallel) & Making Decisions Data layouts Allow compilers to focus on exploring choices Compiler no longer needs to reconstruct choices Code Gen Jason Ansel (MIT) PetaBricks June 16, 2009 13 / 47

  20. Introduction Why choices Future-proof programs The result: programs can adapt to their environment Jason Ansel (MIT) PetaBricks June 16, 2009 14 / 47

  21. Introduction Why choices Future-proof programs The result: programs can adapt to their environment Choices make programs less brittle Jason Ansel (MIT) PetaBricks June 16, 2009 14 / 47

  22. Introduction Why choices Future-proof programs The result: programs can adapt to their environment Choices make programs less brittle Programs change with architecture, available cores, inputs, etc Jason Ansel (MIT) PetaBricks June 16, 2009 14 / 47

  23. PetaBricks Language Key Ideas Outline Introduction 1 Motivating Example Language & Compiler Overview Why choices PetaBricks Language 2 Key Ideas Compilation Example Other Language Features Results 3 Benchmarks Scalability Variable Accuracy Conclusion 4 Final thoughts Jason Ansel (MIT) PetaBricks June 16, 2009 15 / 47

  24. PetaBricks Language Key Ideas Algorithmic choice in the language Algorithmic choice is the key aspect of PetaBricks Jason Ansel (MIT) PetaBricks June 16, 2009 16 / 47

  25. PetaBricks Language Key Ideas Algorithmic choice in the language Algorithmic choice is the key aspect of PetaBricks Programmer can define multiple rules to compute the same data Jason Ansel (MIT) PetaBricks June 16, 2009 16 / 47

  26. PetaBricks Language Key Ideas Algorithmic choice in the language Algorithmic choice is the key aspect of PetaBricks Programmer can define multiple rules to compute the same data Compiler re-use rules to create hybrid algorithms Jason Ansel (MIT) PetaBricks June 16, 2009 16 / 47

  27. PetaBricks Language Key Ideas Algorithmic choice in the language Algorithmic choice is the key aspect of PetaBricks Programmer can define multiple rules to compute the same data Compiler re-use rules to create hybrid algorithms Can express choices at many different granularities Jason Ansel (MIT) PetaBricks June 16, 2009 16 / 47

  28. PetaBricks Language Key Ideas Synthesized outer control flow Outer control flow synthesized by compiler Jason Ansel (MIT) PetaBricks June 16, 2009 17 / 47

  29. PetaBricks Language Key Ideas Synthesized outer control flow Outer control flow synthesized by compiler Another choice that the programmer should not make Jason Ansel (MIT) PetaBricks June 16, 2009 17 / 47

  30. PetaBricks Language Key Ideas Synthesized outer control flow Outer control flow synthesized by compiler Another choice that the programmer should not make By rows? Jason Ansel (MIT) PetaBricks June 16, 2009 17 / 47

  31. PetaBricks Language Key Ideas Synthesized outer control flow Outer control flow synthesized by compiler Another choice that the programmer should not make By rows? By columns? Jason Ansel (MIT) PetaBricks June 16, 2009 17 / 47

  32. PetaBricks Language Key Ideas Synthesized outer control flow Outer control flow synthesized by compiler Another choice that the programmer should not make By rows? By columns? Diagonal? Reverse order? Blocked? Parallel? Jason Ansel (MIT) PetaBricks June 16, 2009 17 / 47

  33. PetaBricks Language Key Ideas Synthesized outer control flow Outer control flow synthesized by compiler Another choice that the programmer should not make By rows? By columns? Diagonal? Reverse order? Blocked? Parallel? Instead programmer provides explicit producer-consumer relations Jason Ansel (MIT) PetaBricks June 16, 2009 17 / 47

  34. PetaBricks Language Key Ideas Synthesized outer control flow Outer control flow synthesized by compiler Another choice that the programmer should not make By rows? By columns? Diagonal? Reverse order? Blocked? Parallel? Instead programmer provides explicit producer-consumer relations Allows compiler to explore choice space Jason Ansel (MIT) PetaBricks June 16, 2009 17 / 47

  35. PetaBricks Language Compilation Example Outline Introduction 1 Motivating Example Language & Compiler Overview Why choices PetaBricks Language 2 Key Ideas Compilation Example Other Language Features Results 3 Benchmarks Scalability Variable Accuracy Conclusion 4 Final thoughts Jason Ansel (MIT) PetaBricks June 16, 2009 18 / 47

  36. PetaBricks Language Compilation Example Simple example program 1 transform RollingSum 2 from A[ n ] 3 to B[ n ] 4 { 5 // r u l e 0: use the p r e v i o u s l y computed value 6 B. c e l l ( i ) from (A. c e l l ( i ) a , 7 B. c e l l ( i − 1) leftSum ) { 8 return a+leftSum ; 9 } 10 11 // r u l e 1: sum a l l elements to the l e f t 12 B. c e l l ( i ) from (A. region (0 , i ) in ) { 13 return sum( in ) ; 14 } 15 } Jason Ansel (MIT) PetaBricks June 16, 2009 19 / 47

  37. PetaBricks Language Compilation Example Simple example program 1 transform RollingSum 2 from A[ n ] 3 to B[ n ] 4 { 5 // r u l e 0: use the p r e v i o u s l y computed value 6 B. c e l l ( i ) from (A. c e l l ( i ) a , 7 B. c e l l ( i − 1) leftSum ) { 8 return a+leftSum ; 9 } 10 11 // r u l e 1: sum a l l elements to the l e f t 12 B. c e l l ( i ) from (A. region (0 , i ) in ) { 13 return sum( in ) ; 14 } 15 } Jason Ansel (MIT) PetaBricks June 16, 2009 19 / 47

  38. PetaBricks Language Compilation Example Simple example program ... 5 // r u l e 0: use the p r e v i o u s l y computed value 6 B. c e l l ( i ) from (A. c e l l ( i ) a , 7 B. c e l l ( i − 1) leftSum ) { 8 return a+leftSum ; 9 } ... A: B: Jason Ansel (MIT) PetaBricks June 16, 2009 20 / 47

  39. PetaBricks Language Compilation Example Simple example program A: B: ... 11 // r u l e 1: sum a l l elements to the l e f t 12 B. c e l l ( i ) from (A. region (0 , i ) in ) { 13 return sum( in ) ; 14 } ... Jason Ansel (MIT) PetaBricks June 16, 2009 21 / 47

  40. PetaBricks Language Compilation Example Applicable regions Compilation Process Applicable regions Choice grids Choice dependency graph Jason Ansel (MIT) PetaBricks June 16, 2009 22 / 47

  41. PetaBricks Language Compilation Example Applicable regions Compilation Process Applicable regions Choice grids Choice dependency graph // r u l e 0 : use the p r e v i o u s l y computed v a l u e B. c e l l ( i ) from (A. c e l l ( i ) a , B. c e l l ( i − 1) leftSum ) { a+leftSum ; return } Applicable where 1 ≤ i < n Jason Ansel (MIT) PetaBricks June 16, 2009 22 / 47

  42. PetaBricks Language Compilation Example Applicable regions Compilation Process Applicable regions Choice grids Choice dependency graph // r u l e 0 : use the p r e v i o u s l y computed v a l u e B. c e l l ( i ) from (A. c e l l ( i ) a , B. c e l l ( i − 1) leftSum ) { a+leftSum ; return } Applicable where 1 ≤ i < n // r u l e 1 : sum a l l elements to the l e f t B. c e l l ( i ) from (A. region (0 , i ) i n ) { return sum( i n ) ; } Applicable where 0 ≤ i < n Jason Ansel (MIT) PetaBricks June 16, 2009 22 / 47

  43. R1 R0 or R1 0 1 n PetaBricks Language Compilation Example Choice grids Compilation Process Applicable regions Choice grids Choice dependency graph Jason Ansel (MIT) PetaBricks June 16, 2009 23 / 47

  44. R1 R0 or R1 0 1 n PetaBricks Language Compilation Example Choice grids Compilation Process Applicable regions Choice grids Choice dependency graph Divide data space into symbolic regions with common sets of choices Jason Ansel (MIT) PetaBricks June 16, 2009 23 / 47

  45. PetaBricks Language Compilation Example Choice grids Compilation Process Applicable regions Choice grids Choice dependency graph Divide data space into symbolic regions with common sets of choices In this simple example: A: Input (no choices) B: [0 , 1) = rule 1 B: [1 , n ) = rule 0 or rule 1 R1 R0 or R1 0 1 n Jason Ansel (MIT) PetaBricks June 16, 2009 23 / 47

  46. PetaBricks Language Compilation Example Choice grids Compilation Process Applicable regions Choice grids Choice dependency graph Divide data space into symbolic regions with common sets of choices In this simple example: A: Input (no choices) B: [0 , 1) = rule 1 B: [1 , n ) = rule 0 or rule 1 R1 R0 or R1 0 1 n Applicable regions map rules → symbolic data Choice grids map symbolic data → rules Jason Ansel (MIT) PetaBricks June 16, 2009 23 / 47

  47. PetaBricks Language Compilation Example Choice dependency graph Compilation Process Applicable regions Choice grids Choice dependency graph (r0,=,-1) (r1,<=),(r0,=) B.region(1, n) A.region(0, n) Choices: r0, r1 (r1,<=),(r0,=) (r0,=,-1) B.region(0, 1) Choices: r1 Jason Ansel (MIT) PetaBricks June 16, 2009 24 / 47

  48. PetaBricks Language Compilation Example Choice dependency graph Compilation Process Applicable regions Choice grids Choice dependency graph (r0,=,-1) (r1,<=),(r0,=) B.region(1, n) A.region(0, n) Choices: r0, r1 (r1,<=),(r0,=) (r0,=,-1) B.region(0, 1) Choices: r1 Adds dependency edges between symbolic regions Jason Ansel (MIT) PetaBricks June 16, 2009 24 / 47

  49. PetaBricks Language Compilation Example Choice dependency graph Compilation Process Applicable regions Choice grids Choice dependency graph (r0,=,-1) (r1,<=),(r0,=) B.region(1, n) A.region(0, n) Choices: r0, r1 (r1,<=),(r0,=) (r0,=,-1) B.region(0, 1) Choices: r1 Adds dependency edges between symbolic regions Edges annotated with directions and rules Jason Ansel (MIT) PetaBricks June 16, 2009 24 / 47

  50. PetaBricks Language Compilation Example Choice dependency graph Compilation Process Applicable regions Choice grids Choice dependency graph (r0,=,-1) (r1,<=),(r0,=) B.region(1, n) A.region(0, n) Choices: r0, r1 (r1,<=),(r0,=) (r0,=,-1) B.region(0, 1) Choices: r1 Adds dependency edges between symbolic regions Edges annotated with directions and rules Many compiler passes on this IR to: Jason Ansel (MIT) PetaBricks June 16, 2009 24 / 47

  51. PetaBricks Language Compilation Example Choice dependency graph Compilation Process Applicable regions Choice grids Choice dependency graph (r0,=,-1) (r1,<=),(r0,=) B.region(1, n) A.region(0, n) Choices: r0, r1 (r1,<=),(r0,=) (r0,=,-1) B.region(0, 1) Choices: r1 Adds dependency edges between symbolic regions Edges annotated with directions and rules Many compiler passes on this IR to: Simplify complex dependency patterns Jason Ansel (MIT) PetaBricks June 16, 2009 24 / 47

  52. PetaBricks Language Compilation Example Choice dependency graph Compilation Process Applicable regions Choice grids Choice dependency graph (r0,=,-1) (r1,<=),(r0,=) B.region(1, n) A.region(0, n) Choices: r0, r1 (r1,<=),(r0,=) (r0,=,-1) B.region(0, 1) Choices: r1 Adds dependency edges between symbolic regions Edges annotated with directions and rules Many compiler passes on this IR to: Simplify complex dependency patterns Add choices Jason Ansel (MIT) PetaBricks June 16, 2009 24 / 47

  53. PetaBricks Language Compilation Example Code generation PetaBricks Source Code 1 PetaBricks source code is compiled PetaBricks Compiler Autotuning Final Binary Binary Choice Configuration File Jason Ansel (MIT) PetaBricks June 16, 2009 25 / 47

  54. PetaBricks Language Compilation Example Code generation PetaBricks Source Code 1 PetaBricks source code is compiled PetaBricks Compiler 2 An autotuning binary is created Autotuning Final Binary Binary Choice Configuration File Jason Ansel (MIT) PetaBricks June 16, 2009 25 / 47

  55. PetaBricks Language Compilation Example Code generation PetaBricks Source Code 1 PetaBricks source code is compiled PetaBricks Compiler 2 An autotuning binary is created 3 Autotuning occurs creating a Autotuning Final Binary Binary choice configuration file Choice Configuration File Jason Ansel (MIT) PetaBricks June 16, 2009 25 / 47

  56. PetaBricks Language Compilation Example Code generation PetaBricks Source Code 1 PetaBricks source code is compiled PetaBricks Compiler 2 An autotuning binary is created 3 Autotuning occurs creating a Autotuning Final Binary Binary choice configuration file 4 Choices are fed back into the compiler to create a final binary Choice Configuration File Jason Ansel (MIT) PetaBricks June 16, 2009 25 / 47

  57. PetaBricks Language Compilation Example Autotuning Based on two building blocks: A genetic tuner An n -ary search algorithm Jason Ansel (MIT) PetaBricks June 16, 2009 26 / 47

  58. PetaBricks Language Compilation Example Autotuning Based on two building blocks: A genetic tuner An n -ary search algorithm Flat parameter space Compiler generates a dependency graph describing this parameter space Jason Ansel (MIT) PetaBricks June 16, 2009 26 / 47

  59. PetaBricks Language Compilation Example Autotuning Based on two building blocks: A genetic tuner An n -ary search algorithm Flat parameter space Compiler generates a dependency graph describing this parameter space Entire program tuned from bottom up Jason Ansel (MIT) PetaBricks June 16, 2009 26 / 47

  60. PetaBricks Language Compilation Example Parallel Runtime Library Task-based parallel runtime Thread-local decks of runnable tasks Jason Ansel (MIT) PetaBricks June 16, 2009 27 / 47

  61. PetaBricks Language Compilation Example Parallel Runtime Library Task-based parallel runtime Thread-local decks of runnable tasks Use a work-stealing algorithm similar to that of Cilk Jason Ansel (MIT) PetaBricks June 16, 2009 27 / 47

  62. PetaBricks Language Other Language Features Outline Introduction 1 Motivating Example Language & Compiler Overview Why choices PetaBricks Language 2 Key Ideas Compilation Example Other Language Features Results 3 Benchmarks Scalability Variable Accuracy Conclusion 4 Final thoughts Jason Ansel (MIT) PetaBricks June 16, 2009 28 / 47

  63. PetaBricks Language Other Language Features More PetaBricks features Automatic consistency checking The tunable keyword Call external code Custom training data generators Matrix versions for iterative algorithms Rule priorities where (clause for limiting applicable regions) Template transforms Jason Ansel (MIT) PetaBricks June 16, 2009 29 / 47

  64. PetaBricks Language Other Language Features More PetaBricks features Automatic consistency checking The tunable keyword Call external code Custom training data generators Matrix versions for iterative algorithms Rule priorities where (clause for limiting applicable regions) Template transforms Jason Ansel (MIT) PetaBricks June 16, 2009 29 / 47

  65. PetaBricks Language Other Language Features More PetaBricks features Automatic consistency checking The tunable keyword Call external code Custom training data generators Matrix versions for iterative algorithms Rule priorities where (clause for limiting applicable regions) Template transforms Jason Ansel (MIT) PetaBricks June 16, 2009 29 / 47

  66. PetaBricks Language Other Language Features More PetaBricks features Automatic consistency checking The tunable keyword Call external code Custom training data generators Matrix versions for iterative algorithms Rule priorities where (clause for limiting applicable regions) Template transforms Jason Ansel (MIT) PetaBricks June 16, 2009 29 / 47

More recommend