An Active-Library Based Investigation Into the Performance Optimisation of Linear Algebra and the Finite Element Method

Total Page:16

File Type:pdf, Size:1020Kb

An Active-Library Based Investigation Into the Performance Optimisation of Linear Algebra and the Finite Element Method Imperial College of Science, Technology and Medicine Department of Computing An Active-Library Based Investigation into the Performance Optimisation of Linear Algebra and the Finite Element Method Francis Prem Russell Submitted in part fulfilment of the requirements for the degree of Doctor of Philosophy in Computing and the Diploma of Imperial College, London, July 2011 Abstract In this thesis, I explore an approach called \active libraries". These are libraries that take part in their own optimisation, enabling both high-performance code and the presentation of intuitive abstractions. I investigate the use of active libraries in two domains. Firstly, dense and sparse linear algebra, particularly, the solution of linear systems of equations. Secondly, the specification and solution of finite element problems. Extending my earlier (MEng) thesis work, I describe the modifications to my linear algebra library \Desola" required to perform sparse-matrix code generation. I show that optimisations easily applied in the dense case using code-transformation must be applied at a higher level of abstraction in the sparse case. I present performance results for sparse linear system solvers generated using Desola and compare against an implementation using the Intel Math Kernel Library. I also present improved dense linear-algebra performance results. Next, I explore the active-library approach by developing a finite element library that captures runtime representations of basis functions, variational forms and sequences of operations be- tween discretised operators and fields. Using captured representations of variational forms and basis functions, I demonstrate optimisations to cell-local integral assembly that this approach enables, and compare against the state of the art. As part of my work on optimising local assembly, I extend the work of Hosangadi et al. on common sub-expression elimination and factorisation of polynomials. I improve the weight function presented by Hosangadi et al., increasing the number of factorisations found. I present an implementation of an optimised branch-and-bound algorithm inspired by reformulating the original matrix-covering problem as a maximal graph biclique search problem. I evaluate the algorithm's effectiveness on the expressions generated by our finite element solver. i ii Acknowledgements I would like to express my greatest thanks and appreciation to: • Paul Kelly, my supervisor, for his time, knowledge, patience, enthusiasm and endless discussions without which this work would never have been possible. • Tony Field, my second supervisor, for the interesting conversations we've had. • Graham Markall, for our many discussions about finite element assembly and other related issues. • David Ham, for his help in understanding the numerical issues surrounding the finite element discretisation of the Navier-Stokes equations. • William Knottenbelt and Peter Jimack, my examiners, for taking the time and effort to read my thesis and for their constructive comments and suggestions. • Tristan Allwood, Marc Hull and Matthew Sackman for their support with special thanks to Tristan and Marc for enduring countless conversations about the many research obsta- cles I encountered. • My family, for always having faith in my abilities. iii iv Contents Abstract i Acknowledgements iii 1 Introduction1 1.1 Thesis Statement...................................1 1.2 Motivation and Objectives..............................1 1.3 Contributions.....................................2 1.4 Statement of Originality...............................3 1.5 Publications......................................4 2 Background5 2.1 Optimising Domain-Specific Abstractions......................5 2.1.1 Expression Templates and Template Metaprogramming..........6 2.1.2 ROSE.....................................8 2.1.3 Broadway Compiler..............................9 2.2 Programming for Adaptation............................ 10 v vi Contents 2.2.1 Sequoia.................................... 11 2.2.2 Themis .................................... 12 2.3 Library Adaptation through Empirical Techniques................. 14 2.3.1 X Language.................................. 15 2.3.2 ATLAS.................................... 16 2.3.3 SPIRAL.................................... 19 2.4 Code Optimisation Techniques and Models..................... 22 2.4.1 Loop Fusion.................................. 22 2.4.2 Array Contraction.............................. 23 2.4.3 Polytope Model................................ 23 2.4.4 Runtime Data and Computation Reordering................ 25 2.5 Code Generation and Optimisation Frameworks.................. 30 2.5.1 LLVM..................................... 30 2.5.2 SUIF...................................... 35 2.5.3 TaskGraph.................................. 36 2.6 Tensors........................................ 36 2.7 Vector Calculus Notation............................... 38 2.8 The Finite Element Method............................. 39 2.8.1 Introduction.................................. 39 2.8.2 The Method of Weighted Residuals..................... 40 2.8.3 Boundary Conditions............................. 41 Contents vii 2.8.4 Problem Discretisation............................ 42 2.8.5 Assembly and Solution............................ 43 2.9 Finite Element Libraries............................... 44 2.9.1 Analysa.................................... 44 2.9.2 GetDP..................................... 45 2.9.3 deal.II..................................... 46 2.9.4 FreeFEM++................................. 47 2.9.5 Sundance................................... 47 2.9.6 FEniCS.................................... 48 2.10 Conclusion....................................... 49 3 Code Generation for Iterative Solvers of Sparse Linear Systems 51 3.1 Introduction...................................... 51 3.2 Delaying Evaluation................................. 53 3.3 Runtime Code Generation.............................. 55 3.4 Code Caching..................................... 57 3.5 Loop Fusion and Array Contraction......................... 59 3.6 Liveness Analysis................................... 61 3.7 Performance Evaluation for Dense Linear Algebra................. 63 3.8 Extension to Sparse Matrices............................ 72 3.8.1 Sparse Matrix Storage............................ 72 3.8.2 Code Generation............................... 72 viii Contents 3.8.3 Matrices.................................... 78 3.8.4 Results..................................... 78 3.9 Conclusions and Further Work............................ 81 4 Excafe´: An Expression Capturing Finite Element Library 85 4.1 The Finite Element Method............................. 85 4.2 Our Investigation................................... 86 4.3 Data Flow in Excafe´ ................................ 88 4.4 Representation Capabilities of Excafe´ ....................... 89 4.5 Overview of the Excafe´ Chapters......................... 92 5 Heat Solver Example in Excafe´ 95 5.1 A Simple Heat Conduction Problem......................... 95 5.2 Discretisation of the Heat Equation......................... 97 5.3 Specifying the Problem Context to Excafe´ .................... 99 5.4 Specifying the Solution Steps to Excafe´ ...................... 100 5.5 Executing the solver................................. 102 5.6 Generated Output.................................. 102 5.7 Conclusion....................................... 104 6 Expression Capture in Excafe´ 105 6.1 Overview........................................ 105 6.2 Problem Context Construction............................ 107 Contents ix 6.2.1 Specifying Tensor Field Discretisation.................... 107 6.2.2 Boundary Conditions............................. 109 6.3 Discrete Expression Capture............................. 111 6.3.1 Handle Types................................. 111 6.3.2 Linear System Solution............................ 114 6.3.3 Registering Solution Steps.......................... 114 6.4 Declarative Iteration Capture............................ 116 6.4.1 Linearising the Convective Acceleration Term of Navier-Stokes...... 117 6.4.2 C++ Syntax................................. 118 6.4.3 Comparison to Imperative Form....................... 122 6.4.4 Future Development............................. 122 6.5 Variational Form Capture.............................. 123 6.6 Basis Function Capture................................ 125 6.7 Conclusion....................................... 130 7 Imperative Loop Inference 133 7.1 The Problem..................................... 133 7.2 Algorithm....................................... 134 7.2.1 Expression DAG Annotation......................... 136 7.2.2 Determining Loop Nesting.......................... 139 7.2.3 Topological Sort................................ 141 7.3 Declarative Specification Validation......................... 142 x Contents 7.3.1 Updating persistent values with incorrectly scoped expressions...... 142 7.3.2 Under-specification of loop nesting..................... 142 7.3.3 Over-specification of loop nesting...................... 144 7.3.4 Invalid dependencies............................. 144 7.4 Conclusion....................................... 145 8 Incompressible Navier-Stokes Solver 147 8.1 The Test Problem................................... 147 8.2 Our model....................................... 149 8.3 Variational Formulation............................... 150 8.4 Outflow Boundary Condition............................ 151 8.5 Temporal Discretisation..............................
Recommended publications
  • Linear Algebra Libraries
    Linear Algebra Libraries Claire Mouton [email protected] March 2009 Contents I Requirements 3 II CPPLapack 4 III Eigen 5 IV Flens 7 V Gmm++ 9 VI GNU Scientific Library (GSL) 11 VII IT++ 12 VIII Lapack++ 13 arXiv:1103.3020v1 [cs.MS] 15 Mar 2011 IX Matrix Template Library (MTL) 14 X PETSc 16 XI Seldon 17 XII SparseLib++ 18 XIII Template Numerical Toolkit (TNT) 19 XIV Trilinos 20 1 XV uBlas 22 XVI Other Libraries 23 XVII Links and Benchmarks 25 1 Links 25 2 Benchmarks 25 2.1 Benchmarks for Linear Algebra Libraries . ....... 25 2.2 BenchmarksincludingSeldon . 26 2.2.1 BenchmarksforDenseMatrix. 26 2.2.2 BenchmarksforSparseMatrix . 29 XVIII Appendix 30 3 Flens Overloaded Operator Performance Compared to Seldon 30 4 Flens, Seldon and Trilinos Content Comparisons 32 4.1 Available Matrix Types from Blas (Flens and Seldon) . ........ 32 4.2 Available Interfaces to Blas and Lapack Routines (Flens and Seldon) . 33 4.3 Available Interfaces to Blas and Lapack Routines (Trilinos) ......... 40 5 Flens and Seldon Synoptic Comparison 41 2 Part I Requirements This document has been written to help in the choice of a linear algebra library to be included in Verdandi, a scientific library for data assimilation. The main requirements are 1. Portability: Verdandi should compile on BSD systems, Linux, MacOS, Unix and Windows. Beyond the portability itself, this often ensures that most compilers will accept Verdandi. An obvious consequence is that all dependencies of Verdandi must be portable, especially the linear algebra library. 2. High-level interface: the dependencies should be compatible with the building of the high-level interface (e.
    [Show full text]
  • C++ API for BLAS and LAPACK
    2 C++ API for BLAS and LAPACK Mark Gates ICL1 Piotr Luszczek ICL Ahmad Abdelfattah ICL Jakub Kurzak ICL Jack Dongarra ICL Konstantin Arturov Intel2 Cris Cecka NVIDIA3 Chip Freitag AMD4 1Innovative Computing Laboratory 2Intel Corporation 3NVIDIA Corporation 4Advanced Micro Devices, Inc. February 21, 2018 This research was supported by the Exascale Computing Project (17-SC-20-SC), a collaborative effort of two U.S. Department of Energy organizations (Office of Science and the National Nuclear Security Administration) responsible for the planning and preparation of a capable exascale ecosystem, including software, applications, hardware, advanced system engineering and early testbed platforms, in support of the nation's exascale computing imperative. Revision Notes 06-2017 first publication 02-2018 • copy editing, • new cover. 03-2018 • adding a section about GPU support, • adding Ahmad Abdelfattah as an author. @techreport{gates2017cpp, author={Gates, Mark and Luszczek, Piotr and Abdelfattah, Ahmad and Kurzak, Jakub and Dongarra, Jack and Arturov, Konstantin and Cecka, Cris and Freitag, Chip}, title={{SLATE} Working Note 2: C++ {API} for {BLAS} and {LAPACK}}, institution={Innovative Computing Laboratory, University of Tennessee}, year={2017}, month={June}, number={ICL-UT-17-03}, note={revision 03-2018} } i Contents 1 Introduction and Motivation1 2 Standards and Trends2 2.1 Programming Language Fortran............................ 2 2.1.1 FORTRAN 77.................................. 2 2.1.2 BLAST XBLAS................................. 4 2.1.3 Fortran 90.................................... 4 2.2 Programming Language C................................ 5 2.2.1 Netlib CBLAS.................................. 5 2.2.2 Intel MKL CBLAS................................ 6 2.2.3 Netlib lapack cwrapper............................. 6 2.2.4 LAPACKE.................................... 7 2.2.5 Next-Generation BLAS: \BLAS G2".....................
    [Show full text]
  • Chapter 1. Preliminaries
    Chapter 1. Preliminaries 1.0 Introduction This book, like its sibling versions in other computer languages, is supposed to teach you methods of numerical computing that are practical, efficient, and (insofar as possible) elegant. We presume throughout this book that you, the reader, have particular tasks that you want to get done. We view our job as educating you on how to proceed. Occasionally we may try to reroute you briefly onto a particularly beautiful side road; but by and large, we will guide you along main highways that lead to practical destinations. Throughout this book, you will find us fearlessly editorializing, telling you what you should and shouldn’t do. This prescriptive tone results from a conscious decision on our part, and we hope that you will not find it irritating. We do not claim that our advice is infallible! Rather, we are reacting against a tendency, in the textbook literature of computation, to discuss every possible method that has ever been invented, without ever offering a practical judgment on relative merit. We do, therefore, offer you our practical judgments whenever we can. As you gain experience, you will form your own opinion of how reliable our advice is. We presume that you are able to read computer programs in C++, that being the language of this version of Numerical Recipes. The books Numerical Recipes in Fortran 77, Numerical Recipes in Fortran 90, and Numerical Recipes in C are separately available, if you prefer to program in one of those languages. Earlier editions of Numerical Recipes in Pascal and Numerical Recipes Routines and Ex- amples in BASIC are also available; while not containing the additional material of the Second Edition versions, these versions are perfectly serviceable if Pascal or BASIC is your language of choice.
    [Show full text]
  • A Framework for Developing Finite Element Codes for Multi- Disciplinary Applications
    A Framework for Developing Finite Element Codes for Multi- Disciplinary Applications Pooyan Dadvand Eugenio Oñate Monograph CIMNE Nº-109, January 2008 A Framework for Developing Finite Element Codes for Multi-Disciplinary Applications Pooyan Dadvand Eugenio Oñate Monograph CIMNE Nº-109, January 2008 Centro Internacional de Métodos Numéricos en Ingeniería Gran Capitán s/n, 08034 Barcelona, España CENTRO INTERNACIONAL DE MÉTODOS NUMÉRICOS EN INGENIERÍA Edificio C1, Campus Norte UPC Gran Capitán s/n 08034 Barcelona, Spain Primera edición: Januray 2008 A FRAMEWORK FOR DEVELOPING FINITE ELEMENT CODES FOR MULTI-DISCIPLINARY APPLICATIONS Monografía CIMNE M109 Los autores To Hengameh Abstract The world of computing simulation has experienced great progresses in recent years and requires more exigent multidisciplinary challenges to satisfy the new upcoming demands. Increasing the importance of solving multi-disciplinary problems makes developers put more attention to these problems and deal with difficulties involved in developing software in this area. Conventional finite element codes have several difficulties in dealing with multi-disciplinary problems. Many of these codes are designed and implemented for solving a certain type of problems, generally involving a single field. Extending these codes to deal with another field of analysis usually consists of several problems and large amounts of modifications and implementations. Some typical difficulties are: predefined set of degrees of freedom per node, data structure with fixed set of defined variables, global list of variables for all entities, domain based interfaces, IO restriction in reading new data and writing new results and algorithm definition inside the code. A common approach is to connect different solvers via a master program which implements the interaction algorithms and also transfers data from one solver to another.
    [Show full text]
  • Domain Engineering and Generic Programming for Parallel Scientific
    Domain Engineering and Generic Programming for Parallel Scientific Computing vorgelegt von Diplom-Mathematiker Jens Gerlach Von der Fakult¨at IV – Elektrotechnik und Informatik der Technischen Universit¨at Berlin zur Erlangung des akademischen Grades Doktor der Ingenieurwissenschaften – Dr.-Ing – genehmigte Dissertation Promotionsausschuss: Vorsitzender: Prof. Dr. rer. nat. Hans-Ulrich Heiß Gutachter: Prof. Dr.-Ing. Stefan J¨ahnichen Gutachter: Prof. Dr. Sergei Gorlatch Tag der wissenschaftlichen Aussprache: 4. Juli 2002 Berlin 2002 D 83 For my parents Brigitte and Peter Gerlach Acknowledgement I want to express my gratitude to many people who supported me while I was working on this dissertation and developing the Janus framework. First of all I want to thank my advisors Professor Stefan J¨ahnichen and Professor Sergei Gorlatch, both from Technische Universit¨at Berlin, for their scientific assistance. As the director of Fraunhofer FIRST, Professor J¨ahnichen provided important feedback, constant support and a great rese- arch infrastructure. Professor Gorlatch discussed many parts of this disser- tation with me and helped me to keep the focus of this work. I also want to thank Professor Wolfgang Schr¨oder-Preikschat of University of Magdeburg for his invaluable assistance and very helpful critics when I was mapping out the scope of this work. I started working on the subject of this dissertation during my stay at the Tsukuba Research Center of the Real World Computing Partnership, Japan. My department heads Mitsuhisa Sato and Yukata Ishikawa were very supportive and provided an outstanding research environment. I owe both of them and my other Japanese colleagues deep gratitude. After returning from Japan, my project leader Dr.
    [Show full text]
  • A Framework for Developing Finite Element Codes for Multi- Disciplinary Applications
    A Framework for Developing Finite Element Codes for Multi- Disciplinary Applications Pooyan Dadvand Eugenio Oñate Monograph CIMNE Nº-109, January 2008 A Framework for Developing Finite Element Codes for Multi-Disciplinary Applications Pooyan Dadvand Eugenio Oñate Monograph CIMNE Nº-109, January 2008 Centro Internacional de Métodos Numéricos en Ingeniería Gran Capitán s/n, 08034 Barcelona, España CENTRO INTERNACIONAL DE MÉTODOS NUMÉRICOS EN INGENIERÍA Edificio C1, Campus Norte UPC Gran Capitán s/n 08034 Barcelona, Spain Primera edición: Januray 2008 A FRAMEWORK FOR DEVELOPING FINITE ELEMENT CODES FOR MULTI-DISCIPLINARY APPLICATIONS Monografía CIMNE M109 Los autores To Hengameh Abstract The world of computing simulation has experienced great progresses in recent years and requires more exigent multidisciplinary challenges to satisfy the new upcoming demands. Increasing the importance of solving multi-disciplinary problems makes developers put more attention to these problems and deal with difficulties involved in developing software in this area. Conventional finite element codes have several difficulties in dealing with multi-disciplinary problems. Many of these codes are designed and implemented for solving a certain type of problems, generally involving a single field. Extending these codes to deal with another field of analysis usually consists of several problems and large amounts of modifications and implementations. Some typical difficulties are: predefined set of degrees of freedom per node, data structure with fixed set of defined variables, global list of variables for all entities, domain based interfaces, IO restriction in reading new data and writing new results and algorithm definition inside the code. A common approach is to connect different solvers via a master program which implements the interaction algorithms and also transfers data from one solver to another.
    [Show full text]
  • Linear Algebra Libraries Claire Mouton
    Linear Algebra Libraries Claire Mouton To cite this version: Claire Mouton. Linear Algebra Libraries. [Technical Report] 2009, pp.35. inria-00576469 HAL Id: inria-00576469 https://hal.inria.fr/inria-00576469 Submitted on 15 Mar 2011 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. Linear Algebra Libraries Claire Mouton [email protected] March 2009 Contents I Requirements 3 II CPPLapack 4 III Eigen 5 IV Flens 6 V Gmm++ 7 VI GNU Scientific Library (GSL) 8 VII IT++ 9 VIII Lapack++ 10 IX Matrix Template Library (MTL) 11 X PETSc 13 XI Seldon 14 XII SparseLib++ 15 XIII Template Numerical Toolkit (TNT) 16 XIV Trilinos 17 XV uBlas 19 1 XVI Other Libraries 20 XVII Links and Benchmarks 22 1 Links 22 2 Benchmarks 22 2.1 Benchmarks for Linear Algebra Libraries . ...... 22 2.2 BenchmarksincludingSeldon . 23 2.2.1 BenchmarksforDenseMatrix. 23 2.2.2 BenchmarksforSparseMatrix . 26 XVIII Appendix 27 3 Flens Overloaded Operator Performance Compared to Seldon 27 4 Flens, Seldon and Trilinos Content Comparisons 29 4.1 Available Matrix Types from Blas (Flens and Seldon) . ....... 29 4.2 Available Interfaces to Blas and Lapack Routines (Flens and Seldon) .
    [Show full text]
  • The Libflame Library for Dense Matrix Computations
    S O F T W A R E E NGINEERING The libflame Library for Dense Matrix Computations Researchers from the Formal Linear Algebra Method Environment (Flame) project have developed new methodologies for analyzing, designing, and implementing linear algebra libraries. These solutions, which have culminated in the libflame library, seem to solve many of the programmability problems that have arisen with the advent of multicore and many- core architectures. How do we convince people that in program­ books, numerous papers, and even more working ming simplicity and clarity—in short: what math­ notes over the last decade documenting the chal­ ematicians call “elegance”—are not a dispensable lenges and motivations that led to the libflame luxury, but a crucial matter that decides between library’s APIs and implementations (see www. success and failure? cs.utexas.edu/users/flame/publications). Seasoned —Edsger W. Dijkstra users in scientific and numerical computing circles will quickly recognize libflame’s target functional­ ity set. In short, in libflame, our goal is to provide ver the past decade, the University not only a framework for developing dense linear of Texas at Austin and Universidad algebra solutions, but also a ready­made library Jaime I de Castellón have collabo­ that is, by almost any metric, easier to use and of­ rated on the Formal Linear Algebra fers competitive (and in many cases superior) real­ OMethod Environment (Flame) project, developing world performance when compared to the more a unique methodology, notation, tools, and APIs set traditional Basic Linear Algebra Subprograms for deriving and representing linear algebra librar­ (BLAS)1 and Linear Algebra Package (Lapack) ies.
    [Show full text]