Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MAchine Guided Energy Efficient Compilation

Simon Cook
February 02, 2014

MAchine Guided Energy Efficient Compilation

MAGEEC, a collaboration between the open source software house, Embecosm, and Bristol University's microcomputer group, aims to use machine learning to improve the energy efficiency of compiled code. This entirely open source project is funded by the UK government through the Technology Strategy Board, and aims to provide working systems based on LLVM and GCC by the end of 2014.

Simon Cook

February 02, 2014
Tweet

More Decks by Simon Cook

Other Decks in Technology

Transcript

  1. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license The Starting Point Identifying Compiler Options to Minimize Energy Consumption for Embedded Platforms James Pallister; Simon J. Hollis; Jeremy Bennett The Computer Journal 2013; doi: 10.1093/comjnl/bxt129 http://comjnl.oxfordjournals.org/cgi/reprint/bxt129?ijkey=aA4RYlYQLNVgkE3 ◾ Joint research project by Embecosm and Bristol University ◾ Now published in a peer- reviewed journal ◾ Open access
  2. 3 Copyright © 2014 Embecosm and University of Bristol Freely

    available under a Creative Commons license Results ◾ Time ≈ Energy – true for simple pipelines – mostly true for complex pipelines – good first approximation ◾ Optimization is very unpredictable – difficult to model the interactions between optimizations ◾ There is only modest commonality – some common options for a single architecture – some common options within the ARM family – sometimes common options across a benchmark ◾ Summary: You can't predict which optimizations are best
  3. 4 Copyright © 2014 Embecosm and University of Bristol Freely

    available under a Creative Commons license Results ◾ Time ≈ Energy – true for simple pipelines – mostly true for complex pipelines – good first approximation ◾ Optimization is very unpredictable – difficult to model the interactions between optimizations ◾ There is only modest commonality – some common options for a single architecture – some common options within the ARM family – sometimes common options across a benchmark ◾ Summary: You can't predict which optimizations are best
  4. 5 Copyright © 2014 Embecosm and University of Bristol Freely

    available under a Creative Commons license BEEBS ◾ The Bristol/Embecosm Embedded Energy Benchmark Suite ◾ A set of benchmarks for deeply embedded systems – no assumed O/S – no printf (!) – minimal use of library routines ◾ Fully free and open source (GPL) ◾ Currently just 10 programs – please help with more ◾ http://www.cs.bris.ac.uk/Research/Micro/beebs.jsp
  5. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license What is MAGEEC? Today we optimize for speed or space
  6. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license What is MAGEEC? Today we optimize for speed or space What if we could optimize for energy usage?
  7. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license How We Got Here Research into feedback directed optimization Research into modeling energy usage Energy measurement
  8. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license How We Got Here Research into feedback directed optimization
  9. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license How We Got Here Research into feedback directed optimization Research into modeling energy usage Energy measurement
  10. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license How We Got Here Research into feedback directed optimization Research into modeling energy usage Energy measurement
  11. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license What's New? Objective is energy optimization
  12. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license What's New? Objective is energy optimization Energy measured not modeled
  13. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license What's New? Objective is energy optimization Generic framework: GCC and LLVM initially Energy measured not modeled
  14. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license What's New? Objective is energy optimization Generic framework: GCC and LLVM initially Energy measured not modeled Working system, not research prototype
  15. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license Our Plan ◾ Implement MILEPOST concepts in a generic way. ◾ Train and evaluate based on real hardware energy measurements and existing passes. ◾ Write and evaluate optimization passes specifically for energy efficiency (Jörn Rennecke). ◾ Using MAGEEC should be as easy as adding -Oe to compiler.
  16. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license Overall Design Compiler Coordinator Machine Learner Plugin I/F ML I/F MAGEEC MAGEEC
  17. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license Overall Design Compiler Coordinator Machine Learner init() init() init() gen_features() decision() run_pass() stats_gen()* next_pass() mod_stats()* decision() end() end() end() * may be gen_features(), comes later version / target version / target program features new features pass list init running loop finish
  18. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license Feature Extraction ◾ Properties of a program, based on MILEPOST feature set ft1 Number of basic blocks in the method ft2 Number of basic blocks with a single successor ft3 Number of basic blocks with two successors ft4 Number of basic blocks with more then two successors ft5 Number of basic blocks with a single predecessor ft6 Number of basic blocks with two predecessors ft7 Number of basic blocks with more then two predecessors ft8 Number of basic blocks with a single predecessor and a single successor ft9 Number of basic blocks with a single predecessor and two successors ft10 Number of basic blocks with a two predecessors and one successor ft11 Number of basic blocks with two successors and two predecessors ft12 Number of basic blocks with more then two successors and more then two predecessors ft13 Number of basic blocks with number of instructions less then 15 ft14 Number of basic blocks with number of instructions in the interval [15, 500]
  19. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license Feature Extraction static unsigned mageec_featextract_exec(void) { basic_block bb; gimple_stmt_iterator gsi; std::vector<int> count; unsigned bb_count = 0; unsigned stmt_count = 0; FOR_EACH_BB(bb) { if (bb_count != 0) count.push_back(stmt_count); stmt_count = 0; bb_count++; for (gsi=gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) { stmt_count++; } } count.push_back(stmt_count); return 0; }
  20. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license Feature Extraction static unsigned mageec_featextract_exec(void) { basic_block bb; gimple_stmt_iterator gsi; std::vector<int> count; unsigned bb_count = 0; unsigned stmt_count = 0; FOR_EACH_BB(bb) { if (bb_count != 0) count.push_back(stmt_count); stmt_count = 0; bb_count++; for (gsi=gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) { stmt_count++; } } count.push_back(stmt_count); return 0; } Pass: 'mageec-extractor', Type: GIMPLE, Function: 'main', Gate: 1 Current Function: main Basic Block Count: 2 Min Statement in BB: 2 Max Statement in BB: 2 Avg Statement in BB: 2 Total Statement in BB: 4
  21. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license 3 Modes of Operation ◾ Good – Gates – allowing passes to be turned on and of ◾ Better – Rearranging – allowing passes to be moved around ◾ Best – Selection – allowing MAGEEC to select passes
  22. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license Machine Learning - Good ◾ Uses decision trees to decide on which passes to execute. ◾ One tree per optimisation pass. ◾ At run time, the learner will use these trees and decide whether a pass will execute. ft2 > 2 ft3 > 4 ft1 > 5 ft1 < 3 Run Don't Run Run Don't Run
  23. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license Machine Learning - Good ◾ Uses decision trees to decide on which passes to execute. ◾ One tree per optimisation pass. ◾ At run time, the learner will use these trees and decide whether a pass will execute. ft2 > 2 ft3 > 4 ft1 > 5 ft1 < 3 Run Don't Run Run Don't Run
  24. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license Custom Optimization Pass ◾ Keeping loops in a single line of flash saves energy – avoid lighting up more than one line – many loops fit into 128 bytes ◾ Aligning to 4-byte boundaries is also more efficient – minimize bit line energy ◾ Optimization will move loops into single line – then pack the line with adjacent basic blocks ◾ Future optimization will move loops into RAM – e.g. for memcpy
  25. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license Status Today ◾ Machine learning method chosen (C5.0) – using existing MILEPOST features – feature identification planned for future ◾ Framework implementation for GCC – can identify passes – can extract features ◾ Framework implementation for LLVM – can report passes ◾ Current issues – BEEBS needs expanding to include more tests ◾ Design of one optimisation pass is underway
  26. Copyright © 2014 Embecosm and University of Bristol Freely available

    under a Creative Commons license Further Reading ◾ Energy measuring and modeling – The software drained my battery. Kerstin Eder & Jeremy Bennett, NMI Yearbook 2012, www.embecosm.com/resources/articles/#EAR12. ◾ MILEPOST GCC - Feedback directed optimization – ctuning.org/milepost-gcc ◾ Measurement of compiler energy usage – Identifying Compiler Options to Minimize Energy Consumption for Embedded Platforms. James Pallister, Simon Hollis, Jeremy Bennett comjnl.oxfordjournals.org/cgi/reprint/bxt129?ijkey=aA4RYlYQLNVg kE3 ◾ BEEBS – www.cs.bris.ac.uk/Research/Micro/beebs.jsp ◾ MAGEEC – mageec.org