Optimization in Code Generationto Reduce Energy Consumption
Total Page:16
File Type:pdf, Size:1020Kb
Universidade do Minho Escola de Engenharia Departamento de Informatica´ David Luis Moniz Branco Optimization in code generation to reduce energy consumption November 2018 This work is funded by the ERDF through the Programme COMPETE and by the Por- tuguese Government through FCT - Foundation for Science and Technology, within projects: FCOMP-01-0124-FEDER-020484, FCOMP-01-0124-FEDER-022701, and grant ref. BI4-2014 GreenSSCM-38973 UMINHO. Universidade do Minho Escola de Engenharia Departamento de Informatica´ David Luis Moniz Branco Optimization in code generation to reduce energy consumption Master dissertation Master Degree in Computer Science Dissertation supervised by Pedro Rangel Henriques November 2018 ACKNOWLEDGEMENTS I want to thank to Prof. Pedro Rangel Henriques for his consideration, dedication, teachings and guidance that came since the first day of the Computer Science Degree. I am also grateful to Dr. Rui Pereira, Prof. Joao˜ Saraiva, Prof. Jacome´ Cunha and other members of the GreenSSCM project team for their support, passed knowledge and always pertinent suggestions. I also want to thank all my colleagues who have always provided assistance and great moments during the journey. Miro, Carc¸ao,˜ Daniel, Joao,˜ Hugo, Nuno, Marina and the remaining group that was part of the Infobiz family. Lastly, I would also like to thank my family for their support over time and for the opportunity they gave me to carry out this work. i ABSTRACT In recent years we have witnessed a great technological advance accompanied by an equally impressive increase in energy consumption, causing problems of both financial and envi- ronmental order. In order to counteract this tendency, Green Computing emerges with a number of measures for a more efficient use of computing resources without a great loss of performance. This essay is a study of several elements of Information Technology analyzed from the point of view of energy efficiency. With special emphasis on microprocessors, modern compiler design, development tools and optimization of code generation, a wide range of information is gathered on very relevant subjects through perspectives still not very considered by the community in general. Also presented are two experimental studies that analyze the optimization of generated code for a set of benchmark programs in several programming languages with the aim of apraise the otimization impact on improving their energy consumption efficiency. A soft- ware measurement framework was also developed that, together with the methodologies presented in both studies, allows obtaining very precise and pertinent results for analysis. Finally, a ranking was produced for 18 development tools, considering the execution time and energy consumption of the executables generated through their compilation profiles. This study also intends to contribute to an energy efficient technological advancement. All the work developed here may also serve as motivation so that these and other aspects of Information Technology may be seen through a greener perspective. ii RESUMO Nos ultimos´ anos temos assistido a um grande avanc¸o tecnologico´ acompanhado por um aumento igualmente impressionante do consumo energetico,´ provocando problemas quer de ordem financeira quer de ordem ambiental. Com o intuito de contrariar essa tendencia,ˆ surge o Green Computing com varias´ medidas para uma utilizac¸ao˜ mais eficiente dos re- cursos computacionais sem grande perda de performance. Esta dissertac¸ao˜ apresenta um estudo relativo a diversos elementos das Tecnologias de Informac¸ao˜ analisados do ponto de vista da eficienciaˆ energetica.´ Com especial destaque para microprocessadores, concec¸ao˜ moderna dos compiladores atuais, ferramentas de de- senvolvimento e gerac¸ao˜ de codigo´ otimizado, e´ aqui reunida uma vasta gama de informac¸ao˜ sobre assuntos bastante relevantes segundo perspetivas ainda pouco consideradas pela co- munidade em geral. Sao˜ tambem´ apresentados dois estudos experimentais que analisam a otimizac¸ao˜ do codigo´ gerado para um conjunto de programas benchmarks em varias´ linguagens de programac¸ao˜ com o objetivo de compreender o impacto das otimizac¸oes˜ no sentido de melhorar a eficienciaˆ energetica´ dos programas compilados. Foi tambem´ desenvolvida uma framework de medic¸ao˜ por software que em conjunto com as metodologias apresentadas em ambos os estudos permite a obtenc¸ao˜ de resultados bastante precisos e pertinentes de analise.´ Por ultimo´ e´ elaborado um ranking para 18 ferramentas de desenvolvimento considerando o tempo de execuc¸ao˜ e consumo energetico´ dos executaveis´ gerados atraves´ dos seus perfis de compilac¸ao.˜ Este estudo pretende assim contribuir para um avanc¸o tecnologico´ energeticamente mais eficiente. Que todo o trabalho aqui desenvolvido possa tambem´ ele servir de motivac¸ao˜ para que estes e outros aspetos das Tecnologias de Informac¸ao˜ possam ser vistos atraves´ de uma perspetiva mais ecologica.´ iii CONTENTS 1 introduction1 1.1 Context and Motivation 1 1.2 Objectives 2 1.3 Study Plan 3 1.4 Document Structure 4 2 processor vendors and green computing6 2.1 Green Computing 6 2.1.1 Advent of Green Computing 6 2.1.2 Meaning and Objectives of Green Computing 9 2.1.3 Roots of Green Computing 10 2.1.4 Importance and Solutions of Green Computing 10 2.2 Microprocessors 13 2.2.1 Different concerns in the development over time 14 2.2.2 Microprocessors as a means for reduction of energy consumption 15 2.3 Manufacturers of Microprocessors 16 2.3.1 Intel 17 2.3.2 AMD 18 2.3.3 IBM 19 3 compiler design and energy reduction 21 3.1 Code Generation 22 3.2 Power reduction and energy saving 25 3.2.1 Power vs. Energy 25 3.2.2 Energetic aspects of programs 26 3.3 Optimization Techniques 28 3.3.1 Just compiling for speed 29 3.3.2 Trading speed for power 29 3.3.3 Instruction scheduling and bit switching 30 3.3.4 Avoiding the dynamic scheduler 31 3.3.5 Domain-specific optimizations 32 3.4 Just-In-Time compilation 32 3.5 Summary 34 4 impact of gcc optimization levels in energy consumption during program execution 37 4.1 Related Work 38 iv 4.2 Experimental Setup 39 4.2.1 Testing Platform 39 4.2.2 Measurement Software 39 4.2.3 Measured Software 40 4.3 Methodology 42 4.3.1 Optimizations Flags 42 4.3.2 Measurement Process 43 4.4 Discussion of Results 44 4.5 Conclusion 49 5 impact of compilation by integrated development environments in energy consumption during program execution 51 5.1 Integrated Development Environments 53 5.1.1 Meaning and Main Features 54 5.1.2 Advantages and Disadvantages 56 5.1.3 Differentiation Factors 58 5.1.4 Summary 58 5.2 Compilation Profiles 59 5.3 The Computer Language Benchmarks Game 61 5.4 Experimental Setup 63 5.4.1 Testing Platform 63 5.4.2 Measurement Software 63 5.4.3 Measured Software 63 5.5 Methodology 67 5.5.1 Analyzed Tools 67 5.5.2 Compilation Options 76 5.5.3 Measurement Process 103 5.6 Discussion of Results 108 5.6.1 Programs 109 5.6.2 Programs - Tools 119 5.6.3 Tools - Profiles 126 5.6.4 Profiles - Parameters 131 5.6.5 Parameters 140 5.6.6 Discussion 144 5.7 Summary 146 6 conclusion 150 a support material 163 v LISTOFFIGURES Figure 2 Worldwide IT spending on servers, power and cooling and manage- ment/administration (He, 2008). 11 Figure 3 Industry Changes in Requirements (Davies, 2012). 15 Figure 4 Server power breakdown by components (Ellison, 2009). 16 Figure 5 Energy Consumption, Power, Step Power and Peak Power during a program execution (Grune et al., 2012). 28 Figure 6 Results of Bzip measurements (C program). 44 Figure 7 Results of Oggenc measurements (C program). 45 Figure 8 Results of Pbrt measurements (C++ program). 45 Figure 9 Results of PGo measurements (Go program). 46 Figure 10 Results of Matmulobjc measurements (Objective-C program). 46 Figure 11 Sphere Engine interface. 72 Figure 12 Geany interface. 73 Figure 13 Traditional C compilation stages. 77 Figure 14 Log message with the compilation parameters from ZinjaI. 80 Figure 15 Log message with the compilation parameters from CodeLite. 81 Figure 16 Project properties manager from NetBeans IDE. 81 Figure 17 Project properties manager from Eclipse CDT. 82 Figure 18 Example of CMakeLists.txt from CLion. 82 Figure 19 Default configuration file from AWS Cloud9. 83 Figure 20 Changing between profiles through Oracle Developer Studio. 83 Figure 21 Changing between profiles through Anjuta DevStudio. 84 Figure 22 Managing profiles through Oracle Developer Studio. 87 Figure 23 Managing profiles through GPS. 87 Figure 24 Results of mandelbrot measurements. 112 Figure 25 Results of fannkuch-redux measurements. 113 Figure 26 Results of reverse-complement measurements. 115 Figure 27 Results of regex-redux measurements. 116 Figure 28 Tools measurements for thread-ring. 120 Figure 29 Tools measurements for n-body. 121 Figure 30 Tools measurements for reverse-complement. 122 Figure 31 Default profiles measurements for binary-trees. 127 Figure 32 Release profiles measurements for mandelbrot. 129 vi Figure 33 Debug profiles measurements for spectral-norm. 130 Figure 34 Profiles without optimization and debug options for fannkuch-redux.132 Figure 35 Profiles with debug but without optimization options for fannkuch- redux. 133 Figure 36 Profiles with debug and optimization options for fannkuch-redux.134 Figure 37 Profiles without debug but with optimization options for fannkuch- redux. 134 Figure 38 Results of binary-trees measurements. 164 Figure 39 Results of chameneos-redux measurements. 164 Figure 40 Results of fannkuch-redux measurements. 165 Figure 41 Results of fasta measurements. 165 Figure 42 Results of k-nucleotide measurements. 166 Figure 43 Results of mandelbrot measurements. 166 Figure 44 Results of meteor measurements. 167 Figure 45 Results of n-body measurements. 167 Figure 46 Results of regex-redux measurements. 168 Figure 47 Results of reverse-complement measurements.