선정목록으로
Fast Evaluation of Finite Element Weak Forms Using Python Tensor Contraction Packages
엔지니어링 플라스틱 · (23) 컴파운드
기본 정보
- 저자
- DOI
- 10.48550/arxiv.2107.04121
- 저널
- arXiv (Cornell University)
- 발행년도
- 2022
- 발행기관
- Cornell University
- 피인용수
- 0
- 라이선스
- cc-by
- 논문 유형
- –
- 언어
- –
- 원문 페이지
- https://doi.org/10.48550/arxiv.2107.04121
- 토픽
- Composite Material Mechanics
- OpenAlex ID
- W6910587456
평가 내용
- 관련도
- 사업분야
- 엔지니어링 플라스틱 · (23) 컴파운드
- 부 분야
- –
- R&D 측면
- –
- 확신도
- –
- 근거 용어
- –
- 판단 근거
- 임베딩 유사도 기반 평가로 '엔지니어링 플라스틱 > 컴파운드' 분야에 선정된 논문입니다.
- R&D 활용 포인트
- –
- 평가 입력
- –
초록
In finite element calculations, the integral forms are usually evaluated using nested loops over elements, and over quadrature points. Many such forms (e.g. linear or multi-linear) can be expressed in a compact way, without the explicit loops, using a single tensor contraction expression by employing the Einstein summation convention. To automate this process and leverage existing high performance codes, we first introduce a notation allowing trivial differentiation of multi-linear finite element forms. Based on that we propose and describe a new transpiler from Einstein summation based expressions, augmented to allow defining multi-linear finite element weak forms, to regular tensor contraction expressions. The resulting expressions are compatible with a number of Python scientific computing packages, that implement, optimize and in some cases parallelize the general tensor contractions. We assess the performance of those packages, as well as the influence of operand memory layouts and tensor contraction paths optimizations on the elapsed time and memory requirements of the finite element form evaluations. We also compare the efficiency of the transpiled weak form implementations to the C-based functions available in the finite element package SfePy.
본문 144,071자
본문 펼치기
## Fast Evaluation of Finite Element Weak Forms Using Python Tensor Contraction Packages
Robert Cimrman <sup>1</sup>
1New Technologies Research Centre, University of West Bohemia, Univerzitn´ı 8,
306 14 Plzeˇn, Czech Republic
July 12, 2021
Abstract
In finite element calculations, the integral forms are usually evaluated using nested loops
over elements, and over quadrature points. Many such forms (e.g. linear or multi-linear)
can be expressed in a compact way, without the explicit loops, using a single tensor contraction expression by employing the Einstein summation convention. To automate this process
and leverage existing high performance codes, we first introduce a notation allowing trivial
differentiation of multi-linear finite element forms. Based on that we propose and describe
a new transpiler from Einstein summation based expressions, augmented to allow defining
multi-linear finite element weak forms, to regular tensor contraction expressions. The resulting expressions are compatible with a number of Python scientific computing packages, that
implement, optimize and in some cases parallelize the general tensor contractions. We assess
the performance of those packages, as well as the influence of operand memory layouts and
tensor contraction paths optimizations on the elapsed time and memory requirements of the
finite element form evaluations. We also compare the efficiency of the transpiled weak form
implementations to the C-based functions available in the finite element package SfePy.
### 1 Introduction
The Einstein summation convention, abbreviated as _einsum_ in the following text according to the
eponymous function of NumPy [15], is a powerful and concise way of writing linear algebra or
tensor contraction expressions and as such it has received attention from computer science related
communities. Large einsum-related research is going on in tensor networks applicable in machine
learning or quantum physics calculations, see e.g. [19, 27, 25, 12, 17].
In the finite element method (FEM), a mathematical model defined using partial differential
equations (PDEs) is transformed to a weak (integral) formulation and then discretized, see e.g. [31].
In the discretization, the unknown continuous functions from infinite-dimensional function spaces
are approximated by finite-dimensional vectors of coefficients - the degrees of freedom (DOFs)
- that are used as linear combination coefficients of basis functions with small support over the
individual finite elements that cover the solution domain. This leads to the necessity of evaluating
the weak form integrals over each element using a numerical quadrature, usually using nested loops
over elements, and over quadrature points. Fast evaluation of the weak form integrals is crucial
for efficient calculations, especially when using higher order polynomials/curves for the basis and
hence the approximated variables. Many such integral forms (e.g. all linear or multi-linear) can
be written using a single tensor contraction, or einsum, expression.
In recent years machine learning techniques and related contractions of large tensor networks
started to be involved in the solution of PDEs using various approaches such as collocation or
energy minimization approaches, see e.g. [26]. In contrast with that we wish to use the tensor
contraction expressions directly in the classical FEM to evaluate the weak forms of PDEs. However,
unlike the huge tensor networks in machine learning or quantum calculations [12], the einsum
expressions in the FE context consist usually of only a few (e.g. three or four) tensors and the
contractions have low numerical intensity. This complicates use of modern parallel architectures
such as GPUs and is subject to an ongoing research [29]. Nevertheless, einsums are successfully
used, for example, in the pure Python finite element package scikit-fem [13], where vectorized FE
assembling (cf. [24]) is employed for fast integral form evaluations.
In this paper we assess several Python scientific computing packages, that implement, optimize
and in some cases parallelize the general tensor contractions using the einsum semantics. The
tested packages are:
- NumPy [15], with the basic implementation and some contraction optimizations using a
version of opt ~~e~~ insum;
- opt ~~e~~ insum [28], with state-of-the-art contraction optimization strategies;
- Dask [11], which can use opt ~~e~~ insum as a backend, can parallelize the calculation and allows
out-of-core calculations with very large data.
- JAX [7], with JIT compilation <sup>1</sup> and possible parallel execution or automatic GPU transfer
and einsum optimization for GPUS in spirit of [29].
The used tensor contraction packages require rectangular (non-ragged) arrays, which limits a single
einsum call to a set of finite elements of the same shape and approximation order. Applying the
einsum semantics in the context of p- or hp-adaptivity [2] or XFEM [21, 6] would require an
additional sorting/grouping of the same element kinds together. Such situation is not considered
in this paper.
The calculation speed and memory requirements of the various strategies are evaluated using
several integral forms common in solving multi-physical problems and compared with the C-based
implementation available in the finite element package SfePy [10]. SfePy is used by our team for
solving relatively small ( _∼_ 10 <sup>6</sup> DOFs), but still physically relevant, multiphysical and multiscale
problems on a single computer and so far targets only CPU computations.
We present mostly the single-thread performance of the above packages because that is directly
influenced by the contraction path optimality in terms of the number of floating point operations
(flops) and use of BLAS [5], nevertheless results with enables multi-threading are presented in
Appendix A.
While we compare the performance with a particular FE solver (SfePy), the obtained results
do not depend on that and are relevant to general audience for the following reasons. The local
element tensors and resulting vectors/matrices are tied to the mathematical problem and thus are
essentially the same in every FE code. We analyze effects of the memory layout of the tensors on
the time and memory requirements of the tensor contractions. The tensor contractions in einsum
function syntax are generated by a simple “weak form to einsum” transpiler that we introduce in
Section 5. This description/implementation of multi-linear forms does not abstract out the details
(basis functions evaluated in quadrature points etc. are numpy arrays) and can be reused. The
calculations are pure-Python from user’s perspective, and while our approach is smaller in scope
than e.g. libCEED, it might offer a simple yet efficient way of implementing the local matrix
action operator [3].
The paper is structured as follows: first, in Section 2 several notions that are used throughout
the text are explained. In Section 3 we discuss factors that influence the speed of tensor contractions from the perspective of local FE evaluations. Then in Section 4 we recall some basic FE
concepts necessary for the subsequent text and establish the relation to einsum expressions, and
in Section 5 we introduce the transpiler from generalized einsum-like expressions, suitable for describing multi-linear finite element weak forms, to regular einsum/tensor contraction expressions.
Finally, we present the results of many numerical simulations in Section 6 allowing us to assess
the performance of the several einsum implementations mentioned above and conclude the paper
in Section 7.
1JIT compilation = Just in time compilation.
### 2 Explanation of Basic Concepts
The presented topic combines aspects of computer science, numerical approximation of PDEs and
software engineering. This section purports to define the common ground necessary for readers of
different backgrounds to understand the following parts.
A _transpiler_ (or source-to-source compiler) translates input in a programming/domain specific
language to another language that works at approximately the same level of abstraction, unlike
a traditional compiler that translates from a higher level programming language to a lower level
programming language. In Section 5 we use this term to denote our translator from generalized
einsum-like notation to regular einsum function notation.
By _einsum_ _expressions_ we mean both the mathematical way of expressing implicit summation
by repeated indices (the Einstein summation convention), such as
_Aij_ = _BikCkj_ _≡_
_n_
_k_ =1
_BikCkj_ _,_
where _A_, _B_ and _C_ are second order tensors (matrices), _B_ has _n_ columns and _C_ has _n_ rows, and,
more specifically, the syntax and arguments used to call einsum functions of Python packages such
as NumPy [15]. The above matrix multiplication in this syntax is
`A` `=` `einsum(’ik,kj->ij’,` `B,` `C)` .
This operation is called _tensor_ _contraction_ and the index _k_ is the contraction index or axis. Many
common linear algebra operations can be expressed using the einsum syntax, for example ( _A_ is a
matrix, _u_, _v_ vectors with compatible dimensions):
trace of _A_ _. . ._ `einsum(’ii’,` `A)`
diagonal of _A_ _. . ._ `einsum(’ii->i’,` `A)`
transposition of _A_ _. . ._ `einsum(’ij->ji’,` `A)`
outer product of _u_, _v_ _. . ._ `einsum(’i,j->ij’,` `u,` `v)`
bilinear form _A_ applied to _u_, _v_ _. . ._ `einsum(’i,ij,j->’,` `u,` `A,` `v)`
All multi-linear (linear, bilinear, etc.) forms that are defined using such multiplicative expressions
can be expressed in this syntax. More examples specific to FE evaluations are given in Section 5.3.
### 3 What Influences Tensor Contraction Speed
Evaluating tensor expressions brings various trade-offs between the numerical intensity/number of
flops, the memory consumption and access patterns, intermediate/temporary array sizes etc. In
this Section we consider several factors that influence the evaluation speed of the weak form einsum
expressions and address some of the trade-offs. The effects of memory layouts are presented in
Section 3.1. Tensor contraction paths and related optimizations are introduced in Section 3.2.
3.1 Memory Layout of Operands
The einsum operands are initially, irrespective of the package used for performing the calculations,
always stored in NumPy’s _n_ -dimensional array objects ( `ndarray` class). A NumPy array is a
continuous one-dimensional segment of memory that can be accessed using an indexing scheme
that maps _n_ integer indices into the location of a fixed-size item (e.g. a 64 bit floating point
number) in the block. The ranges in which the indices can vary is specified by the shape of the
array ( _d_ 0 _, . . ., dn−_ 1) [15].
Among many schemes of arranging items of an _n_ -dimensional array in a one-dimensional block,
NumPy uses a flexible _strided_ _indexing_ _scheme_ where an offset of an item ( _i_ 0 _, . . ., in−_ 1) from the
beginning of the memory block is given by
_i_ offset =
_n_
- _skik,_
_k_ 1
where the integers _sk_ specify the array strides. The most common strides are given by the _row-_
_major_ _order_ (as in C), where the leftmost index varies the fastest, i.e. _sk_ = <sup>�</sup> _j_ <sup>_n_</sup> = <sup>_−_</sup> _k_ <sup>1</sup> +1 <sup>_dj_</sup> <sup>,</sup> <sup>or</sup> <sup>the</sup>
_major_ _order_ (as in C), where the leftmost index varies the fastest, i.e. _sk_ = <sup>�</sup> _j_ <sup>_n_</sup> = <sup>_−_</sup> _k_ <sup>1</sup> +1 <sup>_dj_</sup> <sup>,</sup> <sup>or</sup> <sup>the</sup>
_column_ _major_ _order_ (as in Fortran or Matlab), where the rightmost index varies the fastest, i.e.
_sk_ = <sup>�</sup> _j_ <sup>_k_</sup> =0 <sup>_−_</sup> <sup>1</sup> <sup>_dj_</sup> <sup>.</sup>
_sk_ = <sup>�</sup> _j_ <sup>_k_</sup> =0 <sup>_−_</sup> <sup>1</sup> <sup>_dj_</sup> <sup>.</sup>
The term memory layout can refer both to the layout in terms of the strides (row-major order,
column major order, . . . ) and to the order of the array dimensions. In this work we assume all
operands to be in a contiguous block of memory in the row-major order, and by layout we denote
the various permutations of array dimensions. <sup>2</sup>
The operand layout significantly influences the speed of the tensor contractions, as will be
shown in Section 6.4. For illustration, let us consider the multiplication of two matrices: for all _i_,
_k_, _Cik_ = <sup>�</sup> _j_ <sup>_AijBjk_</sup> <sup>.</sup> <sup>Having the innermost loop index</sup> <sup>_j_</sup> <sup>vary along a contiguous block of memory</sup>
is usually much faster than when, for fixed _i, k_, the _j_ -th and ( _j_ + 1)-th items of _A_ and _B_ are not
next to each other in memory for all _j_, as data access patterns with high locality help avoiding
memory cache misses.
The operand layout significantly influences the speed of the tensor contractions, as will be
shown in Section 6.4. For illustration, let us consider the multiplication of two matrices: for all _i_,
_k_, _Cik_ = <sup>�</sup> _j_ <sup>_AijBjk_</sup> <sup>.</sup> <sup>Having the innermost loop index</sup> <sup>_j_</sup> <sup>vary along a contiguous block of memory</sup>
3.2 Tensor Contraction Path Optimization
For einsum expressions with more than two operands, a number of possibilities exist of how, or in
what order, to perform the tensor contractions. The naive flops cost, corresponding to a for loop
for each index in the expression, is proportional to the product of all operand shapes, and quickly
grows prohibitive. Even though in the context of this work the multi-linear weak form expressions
have less than 10 operands (unlike the machine learning networks), the naive calculation time and
memory requirements are not feasible for all but the simplest forms, see Fig. 1. It is much faster
to contract a subset of operands at a time, which massively reduces the flops and intermediate
array sizes and also allows BLAS use, see [28]. An ordered list of operands to contract at a time
is called a contraction path.
<u>matrix</u> <u>mode</u>
~~Laplacian~~
vector dot
weighted vector dot
~~NS~~ ~~convective~~
elasticity
1 2 3 4 5
order
10 <sup>10</sup>
10 <sup>8</sup>
10 <sup>6</sup>
10 <sup>4</sup>
<u>residual</u> <u>mode</u>
Laplacian
<u>vector</u> <u>dot</u>
weighted vector dot
NS convective
<u>elasticity</u>
1 2 3 4 5
order
10 <sup>11</sup>
10 <sup>10</sup>
10 <sup>9</sup>
10 <sup>8</sup>
10 <sup>7</sup>
10 <sup>6</sup>
10 <sup>5</sup>
10 <sup>4</sup>
Figure 1: Dependence of the naive flops counts per FE cell on the FE approximation order for
several weak forms considered in Section 6. Left: residual mode, i.e. evaluation of the weak form
action on a vector. Right: matrix mode, i.e. evaluation of the local element matrices.
The considered packages support various methods of contraction path optimizations. The resulting path is a sequence of index tuples (usually pairs), denoting the positions of operands to
contract in a list of operands, see below. While the contraction path optimization algorithms
themselves introduce an intrinsic overhead, the resulting contraction paths strongly influence the
elapsed time and memory consumption, especially as the problem size increases and the optimization overhead becomes amortized.
2Both terms are related: an array of shape ( _m, n_ ) in the row-major order has exactly the same arrangement of
items in memory as an array of shape ( _n, m_ ) in the column-major order.
For illustration let us compare the naive and optimized contraction paths of a chained dot
product _AijBjkCkl_, i.e. the einsum expression `einsum(’ij,jk,kl->il’,` `A,` `B,` `C)`, where _A_ is
2 _×_ 2, _B_ is 2 _×_ 5, _C_ is 5 _×_ 2. In this case, opt ~~e~~ insum [28] contraction path optimization results in
the following:
```
Complete contraction: ij,jk,kl->il
Naive scaling: 4
Optimized scaling: 3
Naive FLOP count: 1.200e+2
Optimized FLOP count: 5.600e+1
Theoretical speedup: 2.143e+0
Largest intermediate: 4.000e+0 elements
-------------------------------------------------------------------------------scaling BLAS current remaining
------------------------------------------------------------------------------- 3 GEMM kl,jk->lj ij,lj->il
3 GEMM lj,ij->il il->il
```
That is, instead of the naive four nested loops, it is faster to first contract the _B_ and _C_ :
`D` `=` `einsum(’kl,jk->jl’,` `B,` `C)`, three nested loops, and then to contract the result with _A_ :
`einsum(’jl,ij->il’,` `D,` `A)`, again three nested loops. The flops count of the naive algorithm
is 120, while the optimized flops count is reported to be 56, providing a theoretical speed-up of
about two. Furthermore, the two-step contraction allows using the fast function GEMM of a
BLAS implementation. More examples of tensor contraction paths from the FE form evaluation
context are shown in Section 5.3.
### 4 FE Evaluation and Einsum
In this Section we recall some very basic FEM concepts that will be needed in subsequent text,
details can be found e.g. in [31]. In particular, the concepts are reviewed using vector functions
(scalar functions correspond to a single component) and two example weak forms: the vector dot
product/mass matrix weak form and the convective term weak form from Navier-Stokes equations.
We propose a unified notation that allows straightforward translation to einsum expressions as
well as a trivial differentiation of those expressions.
4.1 Notation
Let us denote _<u>u, v</u>_ two vector functions from suitable function spaces (e.g. _H_ <sup>1</sup> (Ω) in the case of
elasticity, _H_ <sup>div</sup> (Ω) in the case of fluid flow problems). For simplicity, we assume both functions
to be from the same space of functions _V_ 0(Ω): a space of functions that are zero on the boundary
_∂_ Ω. In the FEM and related methods, the continuous functions are approximated by functions
defined using a finite set of degrees of freedom (DOFs) and a finite element basis. A component
_ui_, _i_ = 1 _, . . ., D_ can be expressed as the linear combination
_ui_ <u>(</u> _<u>x</u>_ <u>)</u> _≈_ _ui_ <sup>_h_</sup>
_i_ <sup>_h_</sup> <sup><u>(</u></sup> <sup>_<u>x</u>_</sup> <sup><u>) = u</u></sup> <sup>_k_</sup> _i_
<sup>_k_</sup> _i_ <sup>_φk_</sup> <sup><u>(</u></sup> <sup>_<u>x</u>_</sup> <sup><u>)</u></sup> <sup>_,_</sup> (1)
where u <sup>_k_</sup> _i_ <sup>,</sup> <sup>_k_</sup> <sup>=</sup> <sup>1</sup> <sup>_, . . ., N_</sup> <sup>are</sup> <sup>the</sup> <sup>discrete</sup> <sup>DOFs</sup> <sup>and</sup> <sup>_φk_</sup> <sup><u>(</u></sup> <sup>_<u>x</u>_</sup> <sup><u>)</u></sup> <sup>are</sup> <sup>the</sup> <sup>basis</sup> <sup>functions</sup> <sup>—</sup> <sup>for</sup> <sup>example</sup>
piece-wise polynomials with a small support in the case of FEM. The discrete functions _<u>u</u>_ <sup>_h_</sup> _<u>v</u>_ <sup>_h_</sup> are
substituted in the weak form of a PDE in question and a discrete problem is obtained, in terms
of weak form integrals. The integrals need to be evaluated over the solution domain Ω, resp. its
approximation Ω <sup>_h_</sup>, that is covered by non-overlapping cells - the elements. The total integral is
then the sum of the element contributions.
The actual elements _Tc_, that can have various shapes, sizes and orientations in space, are often
mapped to a reference (unit) element _T_, where the integration using a numerical quadrature takes
place. Let us denote _<u>x</u>_ the coordinates in space and _<u>ξ</u>_ the coordinates in the reference element,
then the mapping is defined as _F_ <sup>_c_</sup> : _<u>ξ</u>_ _→_ _<u>x</u>_ <u>;</u> _<u>x</u>_ _∈_ _Tc_ ; _xi_ <u>(</u> _<u>ξ</u>_ ) = x _i_ <sup>_kφk_</sup> <sup><u>(</u></sup> <sup>_<u>ξ</u>_</sup> <sup>),</sup> <sup>where</sup> <sup><u>x</u></sup> <sup>_k_</sup> <sup>,</sup> <sup>_k_</sup> <sup>=</sup> <sup>1</sup> <sup>_, . . ., N_</sup> <sup>are</sup>
the coordinates of _Tc_ vertices, _φk_ <u>(</u> _<u>ξ</u>_ <u>)</u> are the basis functions restricted to the reference element <sup>3</sup>
and the Jacobian matrix of _F_ <sup>_c_</sup> is _J_ <sup>_c_</sup>
<sup>_<u>∂x</u>_</sup> _∂ξj_ <sup>_<u>i</u>_</sup> <sup>_}_</sup> <sup>.</sup> <sup>Applying</sup> <sup>_F c_</sup> <sup>to</sup> <sup>_<u>ξ</u>_</sup> <sup>_∈_</sup> <sup>_Tc_</sup> <sup>,</sup> <sup>we</sup> <sup>have</sup> <sup>also</sup>
_ij_ <sup>_c_</sup> <sup><u>(</u></sup> <sup>_<u>ξ</u>_</sup> <sup><u>) =</u></sup> <sup>_{_</sup> <sup>_<u>∂x</u>_</sup> _∂ξj_ <sup>_<u>i</u>_</sup>
_ui_ <u>(</u> _<u>ξ</u>_ <u>)</u> _≈_ _ui_ <sup>_h_</sup>
_i_ <sup>_h_</sup> <sup><u>(</u></sup> <sup>_<u>ξ</u>_</sup> <sup>) = u</sup> <sup>_k_</sup> _i_
<sup>_k_</sup> _i_ <sup>_φk_</sup> <sup><u>(</u></sup> <sup>_<u>ξ</u>_</sup> <sup>)</sup> <sup>_._</sup> (2)
This allows evaluating weak form integrals on the reference element.
Thus the basis functions have well defined restrictions _φk_ <u>(</u> _<u>ξ</u>_ ) to the elements - the forms can
be evaluated independently in the individual elements, in a (parallel) loop. An example of such
a loop is in Algorithm 1. This particular loop evaluates a weak form integral in each cell using a
numerical quadrature for a given DOF vector u. For linear forms, it is equivalent to the matrixvector action of the form, i.e. Mu. The same loop structure can be seen also in Algorithm 2, which
evaluates the weak form derivative w.r.t. u, i.e. the matrix M for linear forms. Both functions
return arrays of values for the given set of cells, the actual assembling to a global vector/sparse
matrix is not shown.
Algorithm 1 Basic finite element loop algorithm for evaluating local element contributions to a
global residual vector, i.e. the action of the form on a DOF vector u. The quadrature weights are
incorporated in the element reference mapping Jacobian _J_ <u>(</u> _<u>ξ</u>_ <u>).</u>
Require: _F_ _▷_ A weak form evaluation function.
Require: _cells, qps_ _▷_ Lists of FE mesh cells and reference cell quadrature points.
Require: _v, u_ _▷_ FE variables
Require: _d_ _▷_ material parameters, reference mappings (Jacobian _J_ ) and other data
1: function eval ~~r~~ esidual( _cells_, _qps_, _F_, _v_, _u_, _d_ )
3:2: _rnc←, nzerosdr_ _←_ (( _getnc_ _~~s~~_ _, nhapedr_ ))( _cells, v, u, d_ ) _▷_ _▷_ getallocateresult arrayresult shapearray
4: for _ic_ in _cells_ do _▷_ loop over cells
5: for _<u>ξ</u>_ in _qps_ do _▷_ loop over cell quadrature points
6: _r_ [ _ic,_ :] _←_ _r_ [ _ic,_ :] + _d.J_ ( _ξ_ ) _· F_ ( _ic, ξ, v, u, d_ ) _▷_ evaluate and integrate _F_
7: end for
8: end for
9: return _r_
10: <u>end</u> <u>function</u>
Algorithm 2 Basic finite element loop algorithm for evaluating local element contributions to a
global matrix, i.e. the derivative of the form w.r.t. a DOF vector u. The quadrature weights are
incorporated in the element reference mapping Jacobian _J_ <u>(</u> _<u>ξ</u>_ <u>).</u>
1: function eval ~~m~~ atrix( _cells_, _qps_, _F_, _v_, _u_, _d_ )
3:2: _Mnc, n←drzeros, ndc_ (( _←ngetc, ndr_ _~~s~~_ _hape, ndc_ ()) _cells, v, u, d_ ) _▷_ _▷_ getallocateresult arrayresult shapearray
4: for _ic_ in _cells_ do _▷_ loop over cells
5: for _<u>ξ</u>_ in _qps_ do _▷_ loop over cell quadrature points
6: _▷_ evaluate and integrate <sup>_<u>∂F</u>_</sup> _∂u_
_M_ [ _ic,_ : _,_ :] _←_ _M_ [ _ic,_ : _,_ :] + _d.J_ ( _ξ_ ) _· ∂F_ ( _ic, ξ, v, u, d_ ) _/∂u_
7: end for
8: end for
9: return _M_
10: <u>end</u> <u>function</u>
In the following we will be interested in both modes of evaluation. The global matrices are
required e.g. when using a direct linear system solver, while the matrix action/residual form can
3For the sake of notation simplicity, we assume isoparametric elements here, i.e. the same basis functions for
the variables and the reference element mapping. We also use the same basis for each vector component.
be used in connection with iterative solvers that do not need the global sparse matrix explicitly,
only its application to a vector.
In compiled languages, such as Fortran or C++, the integrals over a group of elements can
be calculated in a loop. In Python (and other interpreted languages), the loops are very slow
- that is why NumPy and other packages allowing fast vectorized calculations were introduced.
Considering this, our aim is to evaluate a FE expression by a single call vectorized over many
elements, unlike the aforementioned listings. Below we expand on the already introduced notation
to allow formulating the evaluation loops using einsum functions in a straightforward and efficient
way. The notation facilitates using scalar _H_ <sup>1</sup> (Ω) basis functions with vector variables, which saves
both time and memory during calculations.
Traditionally the DOFs of all components will be stored in a vector - a 1D array: (2) in
matrix notation, for _D_ = 3, has the following form:
u <sup>1</sup> 1
...
u <sup>_N_</sup> 1
u <sup>1</sup> 2
...
u <sup>_N_</sup> 2
u <sup>1</sup> 3
...
u <sup>_N_</sup> 3
_φ_ 0 0
0 _φ_ 0
0 0 _φ_
(3)
_<u>u</u>_ <sup>_h_</sup> <u>(</u> _<u>ξ</u>_ <u>) =</u>
_≡_
_φ_ 1 _. . ._ _φN_ 0 _. . ._ 0 0 _. . ._ 0
0 _. . ._ 0 _φ_ 1 _. . ._ _φN_ 0 _. . ._ 0
0 _. . ._ 0 0 _. . ._ 0 _φ_ 1 _. . ._ _φN_
_DN_
�( Φ ) _i_ ( u ) _i_ _,_
_i_ =1
u 1
u 2
u 3
_≡_ Φ <u>(</u> _<u>ξ</u>_ ) u _≡_
where _φ_ (argument _<u>ξ</u>_ omitted) is the vector of scalar basis functions evaluated in _<u>ξ</u>_ and Φ <u>(</u> _<u>ξ</u>_ ) is the
_D × DN_ matrix, whose columns can be interpreted as vector basis functions ( Φ ) _i_ corresponding
to items of the DOF vector u of size _DN_ . Because all components of _<u>u</u>_ in (3) are approximated
using the same scalar basis functions, it can be rearranged as follows:
u <sup>_T_</sup> 1
u <sup>_T_</sup> 2
u <sup>_T_</sup> 3
(4)
_φ_ <sup>_T_</sup> <u>(</u> _<u>ξ</u>_ <u>)</u> _≡_ U <sup>_T_</sup> _φ_ <sup>_T_</sup> <u>(</u> _<u>ξ</u>_ ) _,_
_<u>u</u>_ <sup>_h_</sup> <u>(</u> _<u>ξ</u>_ <u>) =</u>
where U is the _N_ _× D_ matrix with columns formed by component DOF vectors u _i_ . In our weak
form to einsum transpiler in Section 5, we use the compact expression (4) as well as a tensor
(three-dimensional array of shape _D × D × N_ ) form of the basis functions matrix Φ <u>(</u> _<u>ξ</u>_ ) of (3)
_φ_ 1 _. . ._ _φN_
0 _. . ._ 0
0 _. . ._ 0
0 _. . ._ 0
_φ_ 1 _. . ._ _φN_
0 _. . ._ 0
0 _. . ._ 0
0 _. . ._ 0
_φ_ 1 _. . ._ _φN_
(5)
Φ <sup>(3)</sup> <u>(</u> _<u>ξ</u>_ <u>) =</u>
_≡{δijφk_ <u>(</u> _<u>ξ</u>_ <u>)</u> _},_
where _i, j_ = 1 _, . . ., D_ and _k_ = 1 _, . . ., N_ . This allows distinguishing the indices of _u_ <sup>_h_</sup> _i_
where _i, j_ = 1 _, . . ., D_ and _k_ = 1 _, . . ., N_ . This allows distinguishing the indices of _u_ <sup>_h_</sup> _i_ <sup>components</sup>
from the DOF components u <sup>_k_</sup> _j_ <sup>,</sup> <sup>by</sup> <sup>rewriting</sup> <sup>(2)</sup> <sup>as</sup>
<sup>_k_</sup> _j_ <sup>,</sup> <sup>by</sup> <sup>rewriting</sup> <sup>(2)</sup> <sup>as</sup>
_u_ <sup>_h_</sup> _i_
<sup>_k_</sup> _j_ <sup>_δijφk_</sup> <sup><u>(</u></sup> <sup>_<u>ξ</u>_</sup> <sup>)</sup> <sup>_._</sup> (6)
<sup>_h_</sup> _i_ <sup><u>(</u></sup> <sup>_<u>ξ</u>_</sup> <sup>) = u</sup> <sup>_k_</sup> _j_
The expression (6) will be used when differentiating a form w.r.t. the DOFs and enables using
scalar _H_ <sup>1</sup> (Ω) basis functions with vector variables as mentioned earlier in this Section. In the
relation (3) the result of differentiation w.r.t. the DOFs is obvious: it is the matrix Φ . But to
avoid forming this rather sparse matrix explicitly, (6) can be used, accompanied with a subsequent
reshape operation ( _j, k_ ) _→_ _J_, _j_ = 1 _, . . ., D_, _k_ = 1 _, . . ., N_, _J_ = 1 _, . . ., DN_ .
4.2 Example Weak Forms
One of the most common forms is the one corresponding to the vector dot product/mass matrix,
used e.g. for _l_ 2 projections, in elastodynamics and elsewhere. Evaluating this form in an element
_TC_, in the context of vector variables, means calculating
_Tc_
_mc_ <u>(</u> _<u>v, u</u>_ <u>) =</u>
_vi_ <u>(</u> _<u>x</u>_ <u>)</u> _ui_ <u>(</u> _<u>x</u>_ <u>) =</u>
_T_
_vi_ <u>(</u> _<u>ξ</u>_ ) _ui_ <u>(</u> _<u>ξ</u>_ ) _|J_ <sup>_c_</sup> <u>(</u> _<u>ξ</u>_ <u>)</u> _| ._ (7)
Substituting the FE approximation (2), applied to both _vi_ and _ui_, into (7) yields
_m_ <sup>_h_</sup> _c_ <sup><u>(</u></sup> <sup>_<u>vh, uh</u>_</sup> <sup>) =</sup>
_T_
v _i_ <sup>_k_</sup>
_i_ <sup>_kφk_</sup> <sup><u>(</u></sup> <sup>_<u>ξ</u>_</sup> <sup><u>)u</u></sup> <sup>_m_</sup> _i_
<sup>_m_</sup> _i_ <sup>_φm_</sup> <sup><u>(</u></sup> <sup>_<u>ξ</u>_</sup> <sup>)</sup> <sup>_|J_</sup> <sup>_c_</sup> <sup><u>(</u></sup> <sup>_<u>ξ</u>_</sup> <sup>)</sup> <sup>_|_</sup> <sup>= v</sup> _i_ <sup>_k_</sup>
_i_ <sup>_k_</sup> <sup>(</sup>
_T_
_φk_ <u>(</u> _<u>ξ</u>_ <u>)</u> _φm_ <u>(</u> _<u>ξ</u>_ ) _|J_ <sup>_c_</sup> <u>(</u> _<u>ξ</u>_ <u>)</u> _|_ )u _i_ <sup>_m_</sup> <sup>_._</sup> (8)
The expression (8) is suitable for calculating the dot product of two known vector functions _<u>v</u>_ <sup>_h_</sup>,
_<u>u</u>_ <sup>_h_</sup>, i.e. a scalar value, but to evaluate either a weak form residual or matrix, either the traditional
matrix relation (3) can be used
<sup>_h_</sup> _c_ <sup><u>(</u></sup> <sup>_<u>vh, uh</u>_</sup> <sup>) =</sup> <sup>v</sup> <sup>_T_</sup> <sup>(</sup>
_T_
_m_ <sup>_h_</sup> _c_
(9)
Φ <sup>_T_</sup> <u>(</u> _<u>ξ</u>_ ) Φ <u>(</u> _<u>ξ</u>_ <u>)</u> _|J_ <sup>_c_</sup> <u>(</u> _<u>ξ</u>_ <u>)</u> _|_ ) u = ( v ) _I_ M _IJ_ ( u ) _J_ _,_
which requires working with Φ <sup>_T_</sup> <u>(</u> _<u>ξ</u>_ <u>),</u> or the form (6) can be employed:
_m_ <sup>_h_</sup> _c_
<sup>_h_</sup> _c_ <sup><u>(</u></sup> <sup>_<u>vh, uh</u>_</sup> <sup>) = v</sup> _a_ <sup>_k_</sup>
_a_ <sup>_k_</sup> <sup>(</sup>
_T_
_a_ <sup>_k_</sup> <sup>M</sup> <sup>_akbm_</sup> <sup>u</sup> <sup>_m_</sup> _b_
_δiaφk_ <u>(</u> _<u>ξ</u>_ ) _δibφm_ <u>(</u> _<u>ξ</u>_ <u>)</u> _|J_ <sup>_c_</sup> <u>(</u> _<u>ξ</u>_ <u>)</u> _|_ )u _b_ <sup>_m_</sup>
_b_ <sup>_m_</sup> <sup>= v</sup> _a_ <sup>_k_</sup>
<sup>_m_</sup> _b_ <sup>_._</sup> (10)
followed by a simple reshape operation _ak_ _→_ _I_, _bm →_ _J_, which does not need to copy/move data,
if the reshaping of M _akbm_ corresponds to its memory storage scheme (e.g. row-major contiguous).
The form (8) has a very simple structure, so it can be readily seen that the mass matrix corresponding to vector variables is formed by _D_ blocks of the scalar mass matrix (� _T_ <sup>_φk_</sup> <sup><u>(</u></sup> <sup>_<u>ξ</u>_</sup> <sup><u>)</u></sup> <sup>_φm_</sup> <sup><u>(</u></sup> <sup>_<u>ξ</u>_</sup> <sup><u>)</u></sup> <sup>_|J_</sup> <sup>_c_</sup> <sup><u>(</u></sup> <sup>_<u>ξ</u>_</sup> <sup><u>)</u></sup> <sup>_|_</sup> <sup>),</sup>
sponding to vector variables is formed by _D_ blocks of the scalar mass matrix (� _T_ <sup>_φk_</sup> <sup><u>(</u></sup> <sup>_<u>ξ</u>_</sup> <sup><u>)</u></sup> <sup>_φm_</sup> <sup><u>(</u></sup> <sup>_<u>ξ</u>_</sup> <sup><u>)</u></sup> <sup>_|J_</sup> <sup>_c_</sup> <sup><u>(</u></sup> <sup>_<u>ξ</u>_</sup> <sup><u>)</u></sup> <sup>_|_</sup> <sup>),</sup>
but the tensor form (10) enables a straightforward (tangent) matrix evaluation of more complex
forms too, for example the convective term below.
The convective term weak form of the Navier-Stokes equations is non-linear, if the advection
velocity coincides with the flow velocity, but its structure is that of a multi-linear term. In an
element _TC_ it is defined as
_cc_ <u>(</u> _<u>v, u, u</u>_ <u>) =</u>
_Tc_
_vi_ <u>(</u> _<u>x</u>_ <u>)</u> <sup>_<u>∂ui</u>_</sup>
_∂xj_
_vi_ <u>(</u> _<u>x</u>_ <u>)</u> <sup>_<u>∂ui</u>_</sup>
<u>(</u> _<u>x</u>_ <u>)</u> _uj_ <u>(</u> _<u>x</u>_ <u>) =</u>
_T_
_vi_ <u>(</u> _<u>ξ</u>_ ) <sup>_<u>∂ui</u>_</sup>
_∂xj_
_vi_ <u>(</u> _<u>ξ</u>_ ) <sup>_<u>∂ui</u>_</sup>
<u>(</u> _<u>ξ</u>_ <u>)</u> _uj_ <u>(</u> _<u>ξ</u>_ ) _|J_ <sup>_c_</sup> <u>(</u> _<u>ξ</u>_ <u>)</u> _|,_ (11)
where _∂x_ <sup>_<u>∂u</u>_</sup> _j_ <sup>_<u>i</u>_</sup>
_∂x_ <sup>_<u>∂u</u>_</sup> _j_ <sup>_<u>i</u>_</sup> <sup><u>(</u></sup> <sup>_<u>ξ</u>_</sup> <sup><u>) can by expressed in terms of</u></sup> <sup>_<u>ξ</u>_</sup> <sup>using</sup> _∂x_ <sup>_<u>∂u</u>_</sup> _j_ <sup>_<u>i</u>_</sup>
_∂x_ <sup>_<u>∂u</u>_</sup> _j_ <sup>_<u>i</u>_</sup> <sup><u>(</u></sup> <sup>_<u>ξ</u>_</sup> <sup>) =</sup> _∂ξ_ <sup>_<u>∂u</u>_</sup> _k_ <sup>_<u>i</u>_</sup>
_∂ξ_ <sup>_<u>∂u</u>_</sup> _k_ <sup>_<u>i</u>_</sup> <sup><u>(</u></sup> <sup>_<u>ξ</u>_</sup> <sup><u>)</u></sup> <sup>_J_</sup> _kj_ <sup>_−_</sup> <sup>1</sup>
where _∂x_ <sup>_<u>∂u</u>_</sup> _j_ <sup>_<u>i</u>_</sup> <sup><u>(</u></sup> <sup>_<u>ξ</u>_</sup> <sup><u>) can by expressed in terms of</u></sup> <sup>_<u>ξ</u>_</sup> <sup>using</sup> _∂x_ <sup>_<u>∂u</u>_</sup> _j_ <sup>_<u>i</u>_</sup> <sup><u>(</u></sup> <sup>_<u>ξ</u>_</sup> <sup>) =</sup> _∂ξ_ <sup>_<u>∂u</u>_</sup> _k_ <sup>_<u>i</u>_</sup> <sup><u>(</u></sup> <sup>_<u>ξ</u>_</sup> <sup><u>)</u></sup> <sup>_J_</sup> _kj_ <sup>_−_</sup> <sup>1(</sup> <sup>_<u>ξ</u>_</sup> <sup><u>).</u></sup> <sup>Substituting the tensor</sup>
FE approximation (6) into (11) yields (the argument _<u>ξ</u>_ is omitted for brevity)
_c_ <sup>_h_</sup> _c_
<sup>_h_</sup> _c_ <sup><u>(</u></sup> <sup>_<u>vh, uh, uh</u>_</sup> <sup>) = v</sup> _a_ <sup>_k_</sup>
_a_
_<u>∂φl</u>_
_∂xj_
u <sup>_m_</sup> _c_ <sup>_δjcφm|J_</sup> <sup>_c|,_</sup> (12)
u <sup>_m_</sup> _c_
_T_
_δiaφk_ u <sup>_l_</sup> _b_ <sup>_δib_</sup>
_δiaφk_ u <sup>_l_</sup> _b_
which allows trivial differentiation w.r.t. u, we just omit u <sup>_l_</sup> _b_
<sup>_l_</sup> _b_ <sup>and</sup> <sup>then</sup> <sup>u</sup> _c_ <sup>_m_</sup>
which allows trivial differentiation w.r.t. u, we just omit u <sup>_l_</sup> _b_ <sup>and</sup> <sup>then</sup> <sup>u</sup> _c_ <sup>_m_</sup> <sup>from</sup> <sup>the</sup> <sup>expression</sup> <sup>and</sup>
sum the two terms together:
_<u>∂c</u>_ <sup>_h_</sup> _<u>c</u>_
_∂_ u
reshape
= v _a_ <sup>_k_</sup>
_b_ <sup>_l_</sup> <sup>_δib_</sup>
(13)
u <sup>_m_</sup> _c_
<sup>_m_</sup> _c_ <sup>_δjcφm_</sup> <sup>+</sup> <sup>_δiaφk_</sup> <sup>u</sup> _b_ <sup>_l_</sup>
<sup>_m_</sup> _j_ <sup>_φm_</sup> <sup>+</sup> <sup>_δiaφk_</sup> <sup>u</sup> _i_ <sup>_l_</sup>
_<u>∂φl</u>_
_∂xj_
_δjcφm_ ) _|J_ <sup>_c_</sup> _|_
= v _a_ <sup>_k_</sup>
(
_T_
_T_
( _δiaφkδib_
( _δiaφkδib_
_<u>∂φl</u>_
_∂xj_
_<u>∂φl</u>_
_∂xj_
u <sup>_m_</sup> _j_
_i_
_<u>∂φl</u>_
_∂xj_ _δjcφm_ ) _|J_ <sup>_c_</sup> _|,_
where in the second identity we replaced back u <sup>_m_</sup> _c_
<sup>_m_</sup> _c_ <sup>_δjc_</sup> <sup>by</sup> <sup>u</sup> <sup>_m_</sup> _j_
<sup>_m_</sup> _j_ <sup>and</sup> <sup>u</sup> _b_ <sup>_l_</sup>
_b_ <sup>_l_</sup> <sup>_δib_</sup> <sup>by</sup> <sup>u</sup> _i_ <sup>_l_</sup>
where in the second identity we replaced back u <sup>_m_</sup> _c_ <sup>_δjc_</sup> <sup>by</sup> <sup>u</sup> <sup>_m_</sup> _j_ <sup>and</sup> <sup>u</sup> _b_ <sup>_l_</sup> <sup>_δib_</sup> <sup>by</sup> <sup>u</sup> _i_ <sup>_l_</sup> <sup>,</sup> <sup>i.e.</sup> <sup>used</sup> <sup>the</sup> <sup>compact</sup>
expression (4).
The weak form to einsum transpiler described in Section 5 allows automatic transformation of
the description corresponding to the left-hand side of (11) to an einsum-ready descriptions of the
discretized form (12) and (13).
### 5 Weak Form to Einsum Transpiler
In this Section we propose a generalized einsum-like notation suitable for describing weak form
integrals and introduce a transpiler that can translate expressions in this notation to regular
einsum expressions and operands.
The generalized einsum-like syntax that we propose is both close to the mathematical notation
and explicit in what tensor axes are contracted, i.e. the weak form definitions are self-documenting,
compare e.g. with the very versatile [14] Unified Form Language [1] from the FEniCS project,
where named symbolic operators such as `inner` or `grad` are used.
5.1 Overview
Let us denote by _p_ a scalar unknown variable and by _q_ the corresponding test function. Similarly,
_<u>u ≡{ui}</u>_, _<u>v</u>_ _≡{vi}_ term a vector unknown and test variable pair.
In the proposed implementation, we generalize the einsum notation with symbols for derivatives
and other quantities summarized in Tab. 1. Using those symbols it is possible to define all the
(multi-)linear terms available in SfePy in a unified and easy manner. Several example definitions
are shown in Tab. 2 - five of those weak form expressions are the subject of the performance
analysis in the next Section.
symbol meaning example
`0` scalar _p_
`i` _i_ -th vector component _ui_
`i.j` gradient: derivative of _i_ -th vector component w.r.t. _<u>∂ui</u>_
_∂xj_
_j_ -th coordinate component
`i:j` symmetric gradient <u>12</u> <sup>(</sup> _∂x_ <sup>_<u>∂u</u>_</sup> _j_ <sup>_<u>i</u>_</sup> <sup>+</sup> <sup>_<u>∂u</u>_</sup> _∂x_ <sup>_<u>j</u>_</sup> _i_
`i:j` symmetric gradient <u>12</u> <sup>(</sup> _∂x_ <sup>_<u>∂u</u>_</sup> _j_ <sup>_<u>i</u>_</sup> <sup>+</sup> <sup>_<u>∂u</u>_</sup> _∂x_ <sup>_<u>j</u>_</sup> _i_ <sup>)</sup>
`s(i:j)->I` vector storage of symmetric second order tensor, _I_ is Cauchy strain
the vector component
Cauchy strain tensor _eij_ <u>(</u> _<u>u</u>_ <u>)</u>
Table 1: The generalized einsum-like notation.
description definition weak form expression
vector dot product `(’i,i’,` `v,` `u)` <u>�</u> _T_ <sup>_viui_</sup>
weighted vector dot product `(’ij,i,j’,` `M,` `v,` `u)` - _T_ <sup>_viM_</sup>
vector dot product `(’i,i’,` `v,` `u)`
<u>�</u>
dot product `(’ij,i,j’,` `M,` `v,` `u)` - _T_ <sup>_viMijuj_</sup>
weak Laplacian `(’0.i,0.i’,` `v,` `u)` - _T_ _<u>∂v</u>_ _∂xi_
convection `(’i,i.j,j’,` `v,` `u,` `u)` - _T_ <sup>_v_</sup> _∂x_ <sup>_i ∂u_</sup> _∂xi_ <sup>_<u>·</u>_</sup> _j_ <sup>_<u>i</u>_</sup> <sup>_u∂uj_</sup>
Stokes coupling `(’i.i,0’,` `v,` `p)` - _T_ _∂x∂vii_ <sup>_p_</sup>
_T_ _∂xi_
Navier-Stokes convection `(’i,i.j,j’,` `v,` `u,` `u)` - _T_ <sup>_v_</sup> _∂x_ <sup>_i ∂u_</sup> _∂xi_ <sup>_<u>·</u>_</sup> _j_ <sup>_<u>i</u>_</sup> <sup>_u∂uj_</sup>
_T_
_<u>∂v</u>_
_∂xi_
_∂xi_ <sup>_<u>·</u>_</sup> <sup>_<u>∂u</u>_</sup>
<sup>_i ∂ui_</sup>
_T_ <sup>_vi ∂u_</sup> _∂xj_ <sup>_<u>i</u>_</sup>
Stokes coupling `(’i.i,0’,` `v,` `p)` - _T_ _∂x∂vii_ <sup>_p_</sup>
divergence operator `(’i.i’,` `v)` - _T_ _∂x∂vii_
_T_
_T_
divergence operator `(’i.i’,` `v)` - _T_ _∂x∂vii_
transposed Stokes coupling `(’i.i,0’,` `u,` `q)` - _T_ <sup>_q_</sup> <sup>_<u>∂u</u>_</sup>
_T_ <sup>_q_</sup> <sup>_<u>∂u</u>_</sup> _∂xi_ <sup>_<u>i</u>_</sup>
_∂xi_
linear elasticity `(’IK,s(i:j)->I,s(k:l)->K’,` `D,` `v,` `u)` - _T_ <sup>_Dijkl_</sup>
linear elasticity `(’IK,s(i:j)->I,s(k:l)->K’,` `D,` `v,` `u)` - _T_ <sup>_Dijkl_</sup> <sup>_eij_</sup> <sup><u>(</u></sup> <sup>_<u>v</u>_</sup> <sup><u>)</u></sup> <sup>_ekl_</sup> <sup><u>(</u></sup> <sup>_<u>u</u>_</sup> <sup><u>)</u></sup>
Cauchy stress `(’IK,s(k:l)->K’,` `D,` `u)` _Dijkl_ _ekl_ <u>(</u> _<u>u</u>_ <u>)</u>
Table 2: Examples of multi-linear weak form definitions.
The generalized einsum-like expressions are transformed to regular einsum expressions using a
simple transpiler with the following features:
- several einsum evaluation backends, see Section 5.2;
- arbitrary memory layout of the operands;
- easy automatic differentiation, thanks to (multi-)linearity of the considered weak forms;
- various evaluation modes (see below).
The following evaluation modes, a feature available in SfePy, are supported:
- ’weak’ modes for expressions involving a test variable:
– ’residual’ mode corresponding to the operator/matrix application to a DOF vector
without the global sparse matrix assembly;
– ’matrix’ mode returning the local element matrices - derivatives of the expression
w.r.t. a given variable;
- ’eval’ mode returning the integral value in case all variables passed to the evaluation function
have associated DOFs, i.e. no test variables are in the argument list.
All weak forms shown in Tab. 2 support all the above evaluation modes automatically, with the
exception of the Cauchy stress expression: this form has no test variables and cannot be called in
a ‘weak‘ mode, only evaluated.
The transpiler allows performing simple transformations of the expressions and operands,
namely:
- Memory layout application: the required memory layout of einsum operands can be specified
using a letter symbol for each operand axis, listed in Tab. 3.
- Expression slicing: to reduce memory usage, an expression can be evaluated in a loop one
cell at a time.
- Operand conversion: operands can be retyped to dask arrays with chunks defined in terms
of cell slices.
- Transformations of expression indices and special operand storage: see the linear elasticity
weak form example in Section 5.3.
The weak form evaluation function implementing the above features is outlined in Algorithm 3.
In the actual implementation, results of various algorithm steps (e.g. the expression transpilation)
are cached to speed up subsequent evaluations.
letter axis
c cells
q quadrature points
v variable component
g gradient component
d local DOF (basis, node)
0 all material axes
Table 3: Memory layout specification letters.
5.2 Backends
A backend terms an expression evaluation function tailored for the specific library. The following
backends are currently supported, the abbreviations in parentheses are used in Section 6:
- `’numpy’` (np): the expression evaluation function uses `numpy.einsum()` .
- `’numpy_loop’` (npl): `numpy.einsum()` is applied to a sliced expression sequentially one cell
at a time.
Algorithm 3 Outline of the weak form evaluation function based on the weak form to einsum
<u>transpiler.</u>
Require: _ge_ _▷_ the generalized einsum-like expression of a weak form
Require: _data_ _▷_ FE variables, material parameters, reference mappings etc.
Require: _layout_ _▷_ operands memory layout
Require: _backend_ _▷_ einsum expression evaluation backend
1: function evaluate(ge, data, backend)
2: _ee_ _<u>←</u>_ _transpile_ ( _ge_ ) _▷_ transpile _ge_ to einsum expression (backend independent)
3: _eval_ _~~e~~_ _insum ←_ _get_ _~~f~~_ _unction_ ( _backend_ ) _▷_ backend-dependent evaluation function
4: _ops ←_ _get_ _operands_ ( _data_ ) _▷_ operands from FE data
5: _shape ←_ _get_ _~~o~~_ _utput_ _~~s~~_ _hape_ ( _ee, ops_ )
6: _ee, ops ←_ _apply_ _~~l~~_ _ayout_ ( _ee, ops_ ) _▷_ apply layout, does not change output shape
7: _ee, ops ←_ _transform_ ( _ee, ops, backend_ ) _▷_ do backend-dependent transformations
8: _paths ←_ _get_ _~~p~~_ _aths_ ( _ee, ops, backend_ ) _▷_ get optimized contraction paths
9: return _eval_ _~~e~~_ _insum_ ( _shape, ee, ops, paths_ )
10: <u>end</u> <u>function</u>
- `’opt_einsum’` (oe): the expression evaluation function uses `opt_einsum.contract()`, more
path optimization options are available than with `‘numpy‘` ;
- `’opt_einsum_loop’` (oel): like `’numpy_loop’` but with `opt_einsum.contract()` .
- `’jax’` (jx): the expression evaluation function uses `jax.numpy.einsum()` and is JIT-compiled
using `jax.jit()` .
- `’jax_vmap’` (jxv): the expression evaluation function uses `jax.numpy.einsum()`, is JITcompiled using `jax.jit()` and vectorized using `jax.vmap()`, which leads to a similar behavior to the `’*_loop’` backends.
- `’dask_single’` (das), `’dask_threads’` (dat): the expression evaluation function uses `dask.array.einsum()`,
explicitly without or with multiple threads.
- `’opt_einsum_dask_single’` (oedas), `’opt_einsum_dask_threads’` (oedat): like `’opt_einsum’`,
but the operands are converted to dask arrays with chunks defined in terms of cell slices and
dask is used by opt ~~e~~ insum to do the contraction, either without or with multiple threads.
The `’auto’` chunk size is used by default, i.e. suitable sizes are determined by dask.
5.3 Expression Examples
Several examples below illustrate the functioning of the transpiler. The default layout, compatible
with SfePy, is used, i.e. the row-major storage of arrays with the `cqgvd0` array axes order. The
following symbols defined in Tab. 4 will be used in the explanation.
5.3.1 Weak Laplacian Expression
The weak Laplacian integral defined by the expression `(’0.i,0.i’,` `v,` `u)` gets translated in
the matrix mode to `einsum(’cq,cqjd,cqje->cde’,` `v.det,` `v.bfg,` `u.bfg)`, where `det` is the
reference element mapping Jacobian and `bfg` is the matrix of basis functions gradients, as defined
in Tab. 4. For a particular case of 1024 tri-quadratic hexahedral elements, the data sizes are:
```
{’c’: 1024, ’q’: 27, ’j’: 3, ’d’: 27, ’e’: 27}
cde (1024, 27, 27) =
v.det cq (1024, 27)
v.bfg cqjd (1024, 27, 3, 27)
u.bfg cqje (1024, 27, 3, 27)
path: [(0, 1), (0, 1)]
```
variable.array meaning
v.det a reference mapping Jacobian _J_ multiplied by quadrature weights
u.bf basis functions _ψk_ corresponding to the approximation of _u_
u.bfg _<u>∂ψ∂ξlk</u>_ <sup>corresponding</sup> <sup>to</sup> <sup>the</sup> <sup>approximation</sup> <sup>of</sup> <sup>_u_</sup>
u.I the identity matrix
u.dofs the DOFs of _u_ in the matrix form U
u.Psg a tensor of shape ( _D, D, D_ ( _D_ + 1) _/_ 2) expressing the vector storage of the symmetric gradient
m1 ~~m~~ 2.arg an array m2 of a material m1
Table 4: Symbols used in the expression examples.
That is, the integral is over 1024 cells with 27 quadrature points each, `j` denotes the three components of the gradients and there are 27 DOFs per cell. The last line shows the contraction path
resulting from the greedy optimization algorithm implemented in NumPy’s `einsum()` function:
a pair ( _i, j_ ) denotes a contraction of operands _i_, _j_, then the operand _i_ is removed from the list of
operands and the operand _j_ is replaced by the contraction result. This process is repeated until
all the contractions are evaluated and a single operand, the result, remains.
Using either the `’numpy_loop’` or the `’opt_einsum_loop’` backend causes the expression to
be compiled to `einsum(’q,qjd,qje->de’,` `v.det[c],` `v.bfg[c],` `u.bfg[c])` that is evaluated
for each cell _c_ . In Section 6 we demonstrate that this slicing approach is an efficient method when
applied to FE approximation orders greater or equal to three, regardless the weak form.
5.3.2 Vector Dot Product Expression
The dot product of vector variables, discussed in Section 4.2 is defined by the expression `(’i,i’,` `v,` `u)`,
which is transpiled to
`einsum(’cq,qd,ir,qe,is->crdse’,` `v.det,` `v.bf,` `v.I,` `u.bf,` `u.I)` in the matrix mode, with
data sizes for 1024 tri-linear hexahedral elements
```
{’c’: 1024, ’q’: 8, ’d’: 8, ’i’: 3, ’r’: 3, ’e’: 8, ’s’: 3}
crdse (1024, 3, 8, 3, 8) =
v.det cq (1024, 8)
v.bf qd (8, 8)
v.I ir (3, 3)
u.bf qe (8, 8)
u.I is (3, 3)
path: [(2, 4), (0, 1), (0, 2), (0, 1)]
```
and to `einsum(’cq,qd,ir,qe,cie->crd’,` `v.det,` `v.bf,` `v.I,` `u.bf,` `u.dofs)` in the vector
mode, with data sizes
```
{’c’: 1024, ’q’: 8, ’d’: 8, ’i’: 3, ’r’: 3, ’e’: 8}
crd (1024, 3, 8) =
v.det cq (1024, 8)
v.bf qd (8, 8)
v.I ir (3, 3)
u.bf qe (8, 8)
u.dofs cie (1024, 3, 8)
path: [(3, 4), (0, 3), (0, 2), (0, 1)]
```
Note that the same expressions work also with scalar variables, but the transpilation result is
different.
5.3.3 Linear Elasticity Expression
The last example covers the linear elasticity weak form and illustrates the transformations of
expression indices and a special operand storage. The form is defined using the second order
Cauchy strain tensor (a.k.a. symmetric gradient)
_eij_ <u>(</u> _<u>u</u>_ <u>) =</u> <sup><u>1</u></sup> 2 <sup>(</sup> _∂x_ <sup>_<u>∂u</u>_</sup> _j_ <sup>_<u>i</u>_</sup>
+ <sup>_<u>∂uj</u>_</sup>
_∂xi_
)
and the fourth order tensor _Dijkl_ with elastic coefficients. Exploiting symmetry of those tensors
allows a substantial memory saving: in 3D, _eij_ is commonly stored as a vector of 6 components
instead of a 3 _×_ 3 matrix, and _Dijkl_ is stored as a 6 _×_ 6 matrix, instead of the full tensor with 81
items. This storage and shape transformation is supported by our transpiler via the `s(i:j)->I`
syntax, meaning a symmetric storage subset is taken from the tensor indices _i_, _j_ and the result
is put into a 1D array with the index _I_ . Hence the linear elasticity weak form is defined simply
using the expression `(’IK,s(i:j)->I,s(k:l)->K’,` `D,` `v,` `u)`, that is compiled to
```
einsum(’cq,cqje,rjI,cqIK,cqlf,slK->cresf’, v.det, v.bfg, v.Psg, m_D.arg, u.bfg, u.Psg)
```
in the matrix mode, with data sizes for 1024 tri-linear hexahedral elements
```
{’c’: 1024, ’q’: 8, ’j’: 3, ’e’: 8, ’r’: 3, ’I’: 6, ’K’: 6, ’l’: 3, ’f’: 8, ’s’: 3}
cresf (1024, 3, 8, 3, 8) =
v.det cq (1024, 8)
v.bfg cqje (1024, 8, 3, 8)
v.Psg rjI (3, 3, 6)
m_D.arg cqIK (1024, 8, 6, 6)
u.bfg cqlf (1024, 8, 3, 8)
u.Psg slK (3, 3, 6)
path: [(0, 1), (0, 1), (0, 1, 2, 3)]
```
The above contraction path corresponds again to the greedy optimization algorithm implemented
in NumPy’s `einsum()` function. Better performance can be obtained in this case e.g. by using
the dynamic programming optimization algorithm of opt ~~e~~ insum’s `contract()` function, which
returns the following path:
```
path: [(0, 4), (2, 3), (1, 3), (1, 2), (0, 1)]
```
Note also the special tensor `Psg` of shape ( _D, D, D_ ( _D_ + 1) _/_ 2) which extracts the basis function
gradient components and stores them in a vector. This tensor has only _D_ nonzeros (ones), however
this sparsity is not exploited. Consequently, the current performance of the linear elastic form
einsum expression is not optimal. Nevertheless, the ability to express this term using a single
simple expression is very convenient.
### 6 Performance Evaluation Results
Five representative weak forms from Tab. 2 were chosen for studying elapsed time and memory
consumption of the einsum evaluation backends from Section 5.2, namely the vector dot product,
weighted vector dot product, weak Laplacian, Navier Stokes convection and linear elasticity terms.
For comparison, their counterparts from SfePy were used, all implemented using a hand-crafted
C code, called from Python via SfePy’s lightweight Cython [4] wrapper. The reference implementation evaluates the forms cell-by-cell, and thus requires a very small memory additional to that
occupied by the operands and the resulting array.
The einsum backend performance measurements were executed on a Linux workstation with
the AMD Ryzen Threadripper 1920X 12-Core Processor, 32 GB RAM and Python version 3.8.5,
NumPy 1.20.1, opt einsum 3.3.0, JAX 0.2.9, Dask 2021.02.0 and SfePy 2021.1 (development version) installed.
We were interested mostly in the single-thread performance of the einsum backends because
that was directly influenced by the contraction path optimality in terms of the number of floating
point operations (flops) and some of the calculations were memory-demanding — the largest tasks
used all the available RAM. To ensure single-threaded execution of all backends, the relevant
environment variables were set appropriately and the CPU affinity parameter was set to a single
value <sup>4</sup> . Vice-versa, the environment variables and affinity were unset in the potentially multithreaded runs in Appendix A.
A 1D bar made of a varying number of 3D hexahedral cells served as the finite element mesh.
Note that the mesh topology is irrelevant for matrix mode linear weak form evaluations - it
plays some role only for the nonlinear convective term form and for residual mode evaluations:
the mesh cell connectivity is used to index the DOF vector. On this mesh, the finite element
approximations of orders from 1 to 5 were defined. The used cell and DOF counts for the five
forms are summarized in Tab. 5: the scalar weak Laplacian form employs variables with a single
component per quadrature point, the other, vector, forms contain variables with three components
per quadrature point, i.e. the largest vector problem involved 12,582,924 DOFs. For the sake of
the performance measurements, the same numbers of quadrature points as given in the table were
applied to integrating all the five weak forms, although in practice those numbers would lead to
inexact integration e.g. in the convective term case.
#cells order #QP #DOFs/comp. repeat _<u>|rs|</u>_ [MB] _<u>|Ms|</u>_ [MB] _<u>|rv|</u>_ [MB] _<u>|Mv|</u>_ [MB]
1,024 1 8 4,100 6 0.1 0.5 0.2 4.7
2 27 18,441 6 0.2 6.0 0.7 53.7
3 64 49,168 5 0.5 33.6 1.6 302.0
4 125 102,425 5 1.0 128.0 3.1 1,152.0
5 216 184,356 4 1.8 382.2 5.3 3,439.9
2,048 1 8 8,196 6 0.1 1.0 0.4 9.4
2 27 36,873 6 0.4 11.9 1.3 107.5
3 64 98,320 5 1.0 67.1 3.1 604.0
4 125 204,825 4 2.0 256.0 6.1 2,304.0
4,096 1 8 16,388 6 0.3 2.1 0.8 18.9
2 27 73,737 6 0.9 23.9 2.7 215.0
3 64 196,624 5 2.1 134.2 6.3 1,208.0
8,192 1 8 32,772 6 0.5 4.2 1.6 37.7
2 27 147,465 5 1.8 47.8 5.3 430.0
3 64 393,232 4 4.2 268.4 12.6 2,415.9
16,384 1 8 65,540 6 1.0 8.4 3.1 75.5
2 27 294,921 5 3.5 95.6 10.6 860.0
32,768 1 8 131,076 6 2.1 16.8 6.3 151.0
2 27 589,833 5 7.1 191.1 21.2 1,719.9
65,536 1 8 262,148 6 4.2 33.6 12.6 302.0
2 27 1,179,657 5 14.2 382.2 42.5 3,439.9
131,072 1 8 524,292 6 8.4 67.1 25.2 604.0
262,144 1 8 1,048,580 5 16.8 134.2 50.3 1,208.0
524,288 1 8 2,097,156 5 33.6 268.4 100.7 2,415.9
1,048,576 1 8 4,194,308 5 67.1 536.9 201.3 4,831.8
Table 5: The numbers of cells _nc_, FE approximation orders, numbers of quadrature points, DOF
counts per component, number of evaluation repetitions and the array sizes of the scalar and
vector weak form residuals _|rs|_, _|rv|_ and matrices _|Ms|_, _|Mv|_ .
Note that only the form evaluations (einsum function calls), leading to arrays of dense vec
4It is a known issue (https://github.com/google/jax/issues/1539) that JAX cannot run using a single thread,
so the affinity workaround was used.
tors/matrices, were measured, not the subsequent FE assembling into the global residual vector
or sparse matrix forming the linear system, except the comparison results in Section 6.3. The
residuals _rs_, _rv_ in Tab. 5 are arrays of shapes ( _nc, ndr_ ), where _ndr_ is the number of DOFs in one
cell (the number of shape functions), the matrices _Ms_, _Mv_ have shapes ( _nc, ndr, ndc_ ), i.e. the local
theelementweakmatricesform, seearealso _ndr_ Algorithms _× ndc_ and 1, _ndr_ 2,in _ndc_ Sectiondepend4.1.on the approximation order and the type of
In relation to the reference implementation performance in Section 6.3, we first explore the
influence of the operand memory layouts on the performance of the weak Laplacian and NavierStokes convection forms in Section 6.4 and then report both relative and absolute results for all
the five forms in Section 6.5, considering only the default, SfePy-compatible, layout. All data
presented below are available in the form of Pandas DataFrames [20] online [8].
6.1 Measuring Memory Consumption
A time-based memory usage including child processes was tracked using memory ~~p~~ rofiler, version
0.58.0 [23]. The individual evaluation functions were tagged in the data, and the memory consumption of a function was defined as the maximum minus minimum in the tagged interval of that
function. The sampling periods from 0 _._ 001 seconds to 0 _._ 1 seconds were used, depending on the
problem size. Due to the time-based sampling nature of the memory tracking, values for very small
problems may be skewed. In such cases the memory requirements were negligible with respect to
the available memory. On the other hand, memory consumption values for large problems, which
are of most interest, were measured accurately.
6.2 Choice of Performance Indicators
The first evaluation of a weak form using the Algorithm 3 is slower then subsequent evaluations
because of the necessary first-time steps. Each weak form was evaluated using a single backend/optimization combination several times according to the repeat parameter for various mesh
sizes and function approximation orders, see Tab. 5. To omit the additional setup time of the
first evaluation, which is amortized e.g. in practical time-dependent problems, the mean elapsed
times reported below are the means without the worst case, denoted _T_ <sup>¯ww</sup>, the worst case being
the largest elapsed time among each set of repeated evaluations. This is important especially
for the JAX-based backends because of the JIT-compilation during the first call. On the other
hand, the memory consumption is given as the maximum over the repeated evaluations, denoted
_M_ <sup>max</sup>, because it determines whether a problem can be calculated within available RAM or not.
Although not included in the paper, the complete data [8] contain all the other statistics (means,
minima, maxima, ranks etc.)
6.3 Reference Implementation Performance
The reference implementation performance in evaluating the five selected weak forms is illustrated
in Fig. 2. The reference results shown, i.e. the elapsed time mean without the worst case _T_ <sup>¯</sup> _r_ <sup>ww</sup> [s]
and the maximum memory consumption _Mr_ <sup>max</sup> [MB], are with respect to the repeat parameter in
Tab. 5.
The results demonstrate a linear dependence of the elapsed times as well as the memory
consumption on the number of mesh cells. For small meshes and the approximation order 1 it is
apparent - especially in the residual mode, where the resulting arrays are much smaller than in
the matrix mode - that there is a small fixed time overhead and that this overhead is amortized
for more than 10 <sup>4</sup> cells. Similarly, the memory sampling measurements are not very accurate
for very fast evaluations/small data even with the sampling period of 0.001 seconds, however, for
larger data (e.g. the matrix mode) the measurements are reliable enough for comparison purposes.
The relative data in subsequent sections are w.r.t. the results shown in Fig. 2.
<u>1.8</u>
1
2
3
~~4~~
Laplacian 5
vector dot
weighted vec. dot
NS convective
elasticity
10 <sup>2</sup>
10 <sup>1</sup>
10 <sup>0</sup>
10 <sup>_−_</sup> <sup>1</sup>
10 <sup>_−_</sup> <sup>2</sup>
10 <sup>3</sup>
10 <sup>2</sup>
10 <sup>1</sup>
10 <sup>0</sup>
10 <sup>0</sup>
10 <sup>_−_</sup> <sup>1</sup>
10 <sup>_−_</sup> <sup>2</sup>
10 <sup>3</sup>
10 <sup>2</sup>
10 <sup>1</sup>
10 <sup>0</sup>
<u>residual</u> <u>mode</u>
<u>0.77</u>
~~0.64~~
0.45 0.51
<u>490.0</u> <u>matrix</u> <u>mode</u>
173.5
100.7
23.5
14.1
<u><mark>1</mark></u>
2
3
~~4~~
Laplacian 5
vector dot
~~weighted~~ ~~vec.~~ ~~dot~~
NS convective
elasticity
10 <sup>3</sup> 10 <sup>4</sup> 10 <sup>5</sup> 10 <sup>6</sup>
#cells
~~4702.1~~ <u>matrix</u> <u>mode</u> <u>5952.3</u>
<u>3564.3</u>
2505.7 2423.7
1
<u>2</u>
3
4
Laplacian <u>5</u>
<u>vector</u> <u>dot</u>
weighted vec. dot
NS convective
~~elasticity~~
10 <sup>3</sup> 10 <sup>4</sup> 10 <sup>5</sup> 10 <sup>6</sup>
#cells
10 <sup>3</sup> 10 <sup>4</sup> 10 <sup>5</sup> 10 <sup>6</sup>
#cells
<u>residual</u> <u>mode</u>
~~472.0~~
142.8
<u>2240.1</u>
<u>1</u>
2
3
4
~~Laplacian~~ <u>5</u>
vector dot
weighted vec. dot
<u>NS</u> <u>convective</u>
elasticity
<u>60.7</u> <u>67.1</u>
10 <sup>3</sup> 10 <sup>4</sup> 10 <sup>5</sup> 10 <sup>6</sup>
#cells
Figure 2: Reference implementation performance in evaluating the five selected weak forms denoted by markers. Left: residual mode, right: matrix mode, top: the elapsed time mean without
the worst case _T_ <sup>¯</sup> _r_ <sup>ww</sup>, bottom: the maximum memory consumption with respect to the repeat pa
rameter _Mr_ <sup>max</sup> . The highest values for each color-coded approximation order are annotated by
arrows.
Comparison with FEniCS The aim of this auxiliary study is not to provide a comprehensive
comparison, indeed the results discussed below were obtained using a single software/hardware
configuration, but to provide a broader context of the our main results in the following sections.
We compare the serial performance of the reference implementation in SfePy with a widely acknowledged and used package FEniCS [18], version 2019.1.0. The weak Laplacian and convective
term weak forms were used for the comparison. The results presented in Fig. 3 show the elapsed
time mean without the worst case _T_ <sup>¯ww</sup> [s] with respect to five repetitions and the maximum memory consumption _M_ <sup>max</sup> [MB] (max. - min. consumption over all the repetitions together). Unlike
results in Fig. 2, the measurements correspond to combined weak form data allocation, evaluation
and assembling to a sparse matrix, i.e. the whole procedure of FEM application to a weak form.
The memory sampling measurements were done with the sampling period of 0.001 seconds. The
results are summarized in Tab. 6, where the ratios SfePy/FEniCS are given for all approximation
orders, using medians over the various numbers of mesh cells. Missing data are due to the time-out
of 2000 seconds and/or insufficient memory.
The evaluation and assembling of the matrix corresponding to the weak Laplacian is faster
in SfePy, almost three times for the order 3: the _T_ <sup>¯ww</sup> ratios in Tab. 6 are decreasing up to
the order 3 and then again increasing. However, SfePy needed about two times more memory
than FEniCS, which caused calculation failures for several higher-order/large number of cells
cases (missing circles in Fig. 3 top left). On the other hand, in the case of the convective term
the memory consumption of both packages was comparable. The calculation speed was also
essentially the same for the order 1, but SfePy was getting progressively worse with the increasing
Laplacian
10 <sup>3</sup>
10 <sup>2</sup>
10 <sup>1</sup>
10 <sup>0</sup>
10 <sup>_−_</sup> <sup>1</sup>
10 <sup>_−_</sup> <sup>2</sup>
10 <sup>3</sup>
10 <sup>2</sup>
10 <sup>1</sup>
10 <sup>0</sup>
10 <sup>_−_</sup> <sup>1</sup>
<u>1511.4</u>
<u>787.0</u>
<u>494.7</u>
149.1
7.7
1
2
3
~~4~~
5
fenics
~~sfepy~~
10 <sup>3</sup> 10 <sup>4</sup> 10 <sup>5</sup> 10 <sup>6</sup>
#cells
1
~~2~~
3
4
<u>5</u>
<u>fenics</u>
sfepy
10 <sup>3</sup> 10 <sup>4</sup> 10 <sup>5</sup> 10 <sup>6</sup>
#cells
10 <sup>4</sup>
10 <sup>3</sup>
10 <sup>2</sup>
10 <sup>1</sup>
<u>21535.7</u> <u>22657.9</u>
~~16036.4~~ ~~1654~~ 9.3
3632.8
1
<u>2</u>
3
4
5
<u>fenics</u>
<u>sfepy</u>
10 <sup>3</sup> 10 <sup>4</sup> 10 <sup>5</sup> 10 <sup>6</sup>
#cells
<u>24887.4</u> <u>25647.0</u>
~~19495.6~~ ~~19758.9~~
13368.9
1
2
~~3~~
4
5
fenics
sfepy
<u>1342.9</u>
~~973.7~~
<u>598.9</u>
124.7
NS convective
10 <sup>4</sup>
~~39.0~~
10 <sup>3</sup>
10 <sup>2</sup>
10 <sup>3</sup> 10 <sup>4</sup> 10 <sup>5</sup> 10 <sup>6</sup>
#cells
Figure 3: Performance of matrix mode evaluations of the SfePy reference implementation (circles) in comparison with FEniCS (crosses) for various approximation orders. Left: the elapsed
time mean without the worst case _T_ <sup>¯ww</sup>, right: the memory consumption _M_ <sup>max</sup> . Top: the weak
Laplacian, bottom: the convective term weak form. The highest values for each color-coded
approximation order are annotated by arrows.
Laplacian NS convective
1 2 3 4 5 1 2 3 4 5
med( _T_ <sup>¯</sup> sfepy <sup>ww</sup>
sfepy <sup>ww</sup> <sup>_/T_</sup> <sup>¯</sup> fenics <sup>ww</sup>
med( _T_ <sup>¯</sup> sfepy <sup>ww</sup> <sup>_/T_</sup> <sup>¯</sup> fenics <sup>ww</sup> <sup>)</sup> 0 _._ 50 0 _._ 42 0 _._ 34 0 _._ 63 0 _._ 83 1 _._ 06 1 _._ 49 3 _._ 20 3 _._ 33 4 _._ 65
med( _M_ sfepy <sup>max</sup> <sup>_/M_</sup> fenics <sup>max</sup> <sup>)</sup> 1 _._ 75 1 _._ 96 2 _._ 16 2 _._ 17 2 _._ 04 1 _._ 06 0 _._ 93 1 _._ 00 0 _._ 99
sfepy <sup>max</sup> <sup>_/M_</sup> fenics <sup>max</sup>
fenics <sup>max</sup> <sup>)</sup> 1 _._ 75 1 _._ 96 2 _._ 16 2 _._ 17 2 _._ 04 1 _._ 06 0 _._ 93 1 _._ 00 0 _._ 99
Table 6: The SfePy/FEniCS ratios of the elapsed time mean without the worst case _T_ <sup>¯ww</sup> and the
memory consumption _M_ <sup>max</sup> for the weak Laplacian and convective term weak forms for various
approximation orders. The values correspond to medians over various numbers of mesh cells, see
Fig. 3.
order: up to four and half times for the order 5, where SfePy timed-out and so the corresponding
memory consumption data points are missing. Analogous behavior was observed also for the
vector dot form (not shown here for brevity). To conclude, SfePy assembling performance seemed
on par with FEniCS for low order approximations, and worse for higher order approximations
with about the same memory requirements. Faster SfePy performance when assembling the weak
Laplacian was connected with higher memory consumption. It is worth noting that the weak form
evaluation algorithm based on the developments of Section 5 offers a significant performance boost
w.r.t. the SfePy reference implementation especially for higher order approximations, as will be
demonstrated in the following text.
6.4 Influence of Tensor Memory Layouts
This section explores the influence of the various possible memory layouts on the weak form
evaluation performance, to establish the position of the default, SfePy-compatible, layout within
other possible layouts. The default layout elapsed time mean without the worst case is denoted
by _T_ <sup>¯</sup> _d_ <sup>ww</sup> .
The default layout specification is constructed as follows. The scalar basis function gradient
tensor has 4 dimensions (cells, quadrature points, gradient components, DOFs) and the layout
`cqgd` ( _L_ 1). The DOFs tensor has 3 dimensions (cells, variable components, cell DOFs) with the
layout `cvd` ( _L_ 2). Material parameter tensors default layout is `cq0` ( _L_ 3), where `0` is a placeholder
for any number of axes. Compressing the three specifications into a single string yields the default
specification `cqgvd0` . Other possible memory layouts of the weak form einsum expression operands
were generated by permuting the layout specification letters of _L_ 1, _L_ 2, _L_ 3 and compressing them
together, leading to 216 different layouts <sup>5</sup>, that were applied to the operands of the matrix mode
einsum expression of the weak Laplacian and convective terms.
6.4.1 Weak Laplacian Layouts
The results below were obtained by a parametric study involving 1461 calculations run using soops
[9], all with the mesh of 8192 cells. The FE approximation order 3 runs had a time-out set to 50
seconds for 4 repetitions, the order 1 and 2 runs used 6 and 5 repetitions, respectively, and no
time-out. The number of runs that timed-out is excluded from the calculations count.
The dependence of the weak Laplacian einsum expression evaluation performance on the
operand memory layouts is first summarized in Tab. 7, where the fastest layouts for each FE
approximation order and einsum backend are listed, together with _T_ <sup>¯ww</sup> _/T_ <sup>¯</sup> _r_ <sup>ww</sup> and _T_ <sup>¯ww</sup> _/T_ <sup>¯</sup> _d_ <sup>ww</sup> . The
layouts are specified using permutations of the reduced default layout `cqgd`, because the FE space
is scalar (no `v` ) and the weak form has no material parameters (no `0` ).
Elapsed time and memory requirements of the individual backends are shown in Fig. 4 for
the FE approximation orders 1 (top), 2 (middle) and 3 (bottom). Both _T_ <sup>¯ww</sup> _/T_ <sup>¯</sup> _r_ <sup>ww</sup> with _T_ <sup>¯ww</sup>
and _M_ <sup>max</sup> _/Mr_ <sup>max</sup> with _M_ <sup>max</sup> are provided. The libraries and contraction paths are indicated
in _y_ axis labels. The contraction paths are used instead of the optimization algorithms because
the paths actually significantly influence the performance, and furthermore the optimization time
was negligible. The paths are written in a condensed way, where e.g. 12 _._ 01 corresponds to
the [(1 _,_ 2) _,_ (0 _,_ 1)], see Section 5.3. Note that several optimization algorithms can lead to a single
contraction path, so each (library, path) pair corresponds to the number of calculations equal to 216
layouts times the number of optimizations with the given path. However, only the values at most
4 _×_ slower than the reference SfePy implementation are shown in Fig. 4, with the corresponding
memory consumption. To reduce the color/marker legend size, only positions of `cq` axes are
indicated in the legend, `*` denotes any letter from `gd` . For comparison, a hand-written weak
Laplacian element matrix evaluation loop implementation, JIT-compiled using Numba (version
0.52.0) [16], was included in this study.
_r_ <sup>ww</sup> and _T_ <sup>¯ww</sup> _/T_ <sup>¯</sup> _d_ <sup>ww</sup>
and _M_ <sup>max</sup> _/Mr_ <sup>max</sup>
_r_ <sup>ww</sup> with _T_ <sup>¯ww</sup>
6.4.2 Weak Convective Term Layouts
The results below were obtained by a parametric study involving 3602 calculations run using
soops [9], all with the mesh of 8192 cells. The FE approximation order 1 and 2 runs used 6 and 5
repetitions, respectively, and no time-out.
The dependence of the weak convective term expression evaluation performance on the operand
memory layouts is first summarized in Tab. 8, where the fastest layouts for each FE approximation
order and einsum backend are listed, together with _T_ <sup>¯ww</sup> _/T_ <sup>¯</sup> _r_ <sup>ww</sup> and _T_ <sup>¯ww</sup> _/T_ <sup>¯</sup> _d_ <sup>ww</sup> . The layouts are
_r_ <sup>ww</sup> and _T_ <sup>¯ww</sup> _/T_ <sup>¯</sup> _d_ <sup>ww</sup>
_d_ <sup>ww</sup> . The layouts are
5This is less than 4!3!3! because the operand layouts _Li_ share letters.
12,01
12,01
oel: 02,01
01,01
12,01
oel: 02,01
01,01
12,01
oedas: 02,01
01,01
12,01
oe: 02,01
01,01
oedas: 02,01
01,01
12,01
numba:
oe: 02,01
01,01
numba:
npl: 01,01
np: 01,01
jxv: 12,01
01,01
jx: 12,01
01,01
npl: 01,01
np: 01,01
jxv: 12,01
01,01
jx: 12,01
01,01
das: 01,01
das: 01,01
12,01
oel: 02,01
01,01
12,01
12,01
oel: 02,01
01,01
12,01
oedas: 02,01
01,01
12,01
oe: 02,01
01,01
oedas: 02,01
01,01
12,01
numba:
oe: 02,01
01,01
numba:
npl: 01,01
np: 01,01
jxv: 12,01
01,01
jx: 12,01
01,01
npl: 01,01
np: 01,01
jxv: 12,01
01,01
jx: 12,01
01,01
das: 01,01
das: 01,01
12,01
~~<u>cqgd</u>~~
<u>cq</u> _<u>∗∗</u>_
<u>c</u> _<u>∗</u>_ <u>q</u> _<u>∗</u>_
~~<u>c</u>~~ _~~<u>∗∗</u>~~_ ~~<u>q</u>~~
<u>qc</u> _<u>∗∗</u>_
_<u>∗</u>_ <u>cq</u> _<u>∗</u>_
_~~<u>∗</u>~~_ ~~<u>c</u>~~ _~~<u>∗</u>~~_ ~~<u>q</u>~~
~~<u>q</u>~~ _~~<u>∗</u>~~_ ~~<u>c</u>~~ _~~<u>∗</u>~~_
_~~<u>∗</u>~~_ ~~<u>qc</u>~~ _~~<u>∗</u>~~_
_~~<u>∗∗</u>~~_ ~~<u>cq</u>~~
<u>q</u> _<u>∗∗</u>_ <u>c</u>
_~~<u>∗</u>~~_ ~~<u>q</u>~~ _~~<u>∗</u>~~_ ~~<u>c</u>~~
_<u>∗∗</u>_ ~~<u>def</u>~~ <u>qc</u> ~~<u><mark>au</mark></u>~~ ~~<u>lt</u>~~
0.5 0.7 1 1.5 2 3 4
_<u>T</u>_ <u>¯</u> <sup>ww</sup> _<u>/</u>_ <u>¯</u> _<u>T</u>_ _~~r~~_ <sup>_ww_</sup>
0.01 _T_ ¯ <sup>ww</sup> [s]0.02 0.05
~~<u>cqgd</u>~~
<u>cq</u> _<u>∗∗</u>_
<u>c</u> _<u>∗</u>_ <u>q</u> _<u>∗</u>_
~~<u>c</u>~~ _~~<u>∗∗</u>~~_ ~~<u>q</u>~~
<u>qc</u> _<u>∗∗</u>_
_<u>∗</u>_ <u>cq</u> _<u>∗</u>_
_~~<u>∗</u>~~_ ~~<u>c</u>~~ _~~<u><mark>∗</mark></u>~~_ ~~<u>q</u>~~
~~<u>q</u>~~ _~~<u>∗</u>~~_ ~~<u><mark>c</mark></u>~~ _~~<u><mark>∗</mark></u>~~_
_~~<u>∗</u>~~_ ~~<u>qc</u>~~ _~~<u>∗</u>~~_
_~~<u>∗∗</u>~~_ ~~<u>cq</u>~~
<u>q</u> _<u>∗∗</u>_ <u>c</u>
_~~<u>∗</u>~~_ ~~<u>q</u>~~ _~~<u>∗</u>~~_ ~~<u>c</u>~~
_<u>∗</u>_ ~~<u>d</u>~~ _<u><mark>∗</mark></u>_ ~~<u><mark>efa</mark></u>~~ <u>qc</u> ~~<u>ult</u>~~
0.5 0.7 1 1.5 2 3 4
_<u>T</u>_ <u>¯</u> <sup>ww</sup> _<u>/</u>_ <u>¯</u> _<u>T</u>_ _~~r~~_ <sup>_ww_</sup>
0.2 _T_ ¯ <sup>ww</sup> [s] 0.5 1
~~<u>cqgd</u>~~
<u>cq</u> _<u>∗∗</u>_
<u>c</u> _<u>∗</u>_ <u>q</u> _<u>∗</u>_
~~<u>c</u>~~ _~~<u>∗</u>~~_ _~~<u><mark>∗</mark></u>~~_ ~~<u>q</u>~~
<u>qc</u> _<u><mark>∗∗</mark></u>_
_<u>∗</u>_ <u>c</u> <u><mark>q</mark></u> _<u><mark>∗</mark></u>_
_~~<u>∗</u>~~_ ~~<u>c</u>~~ _~~<u>∗</u>~~_ ~~<u>q</u>~~
~~<u>q</u>~~ _~~<u><mark>∗</mark></u>~~_ ~~<u>c</u>~~ _~~<u><mark>∗</mark></u>~~_
_~~<u>∗</u>~~_ ~~<u><mark>qc</mark></u>~~ _~~<u><mark>∗</mark></u>~~_
_~~<u>∗∗</u>~~_ ~~<u>cq</u>~~
<u>q</u> _<u>∗∗</u>_ <u>c</u>
_~~<u>∗</u>~~_ ~~<u>q</u>~~ _~~<u>∗</u>~~_ ~~<u>c</u>~~
_<u>∗∗</u>_ ~~<u>default</u>~~ <u>qc</u>
0.5 0.7 1 1.5 2 3 4
_<u>T</u>_ <u>¯</u> <sup>ww</sup> _<u>/</u>_ <u>¯</u> _<u>T</u>_ _~~r~~_ <sup>_ww_</sup>
2 _T_ ¯ <sup>ww</sup> [s] 5 10
12,01
~~<u>cqgd</u>~~
<u>cq</u> _<u>∗∗</u>_
<u>c</u> _<u>∗</u>_ <u>q</u> _<u>∗</u>_
~~<u>c</u>~~ _~~<u>∗∗</u>~~_ ~~<u>q</u>~~
<u>qc</u> _<u>∗∗</u>_
_<u>∗</u>_ <u>cq</u> _<u>∗</u>_
_~~<u>∗</u>~~_ ~~<u>c</u>~~ _~~<u>∗</u>~~_ ~~<u>q</u>~~
~~<u>q</u>~~ _~~<u>∗</u>~~_ ~~<u>c</u>~~ _~~<u>∗</u>~~_
_~~<u>∗</u>~~_ ~~<u>qc</u>~~ _~~<u>∗</u>~~_
_~~<u>∗∗</u>~~_ ~~<u>cq</u>~~
<u>q</u> _<u>∗</u>_ _<u><mark>∗</mark></u>_ <u>c</u>
_~~<u>∗</u>~~_ ~~<u>q</u>~~ _~~<u><mark>∗</mark></u>~~_ ~~<u><mark>c</mark></u>~~
_<u>∗</u>_ ~~<u>default</u>~~ _<u><mark>∗</mark></u>_ <u><mark>qc</mark></u>
0.02 0.05 0.1 0.2 0.5 1 2 5 10 20
_<u>M</u>_ <sup>max</sup> _<u>/Mr</u>_ <sup>max</sup>
0.1 0.2 0.5 1 _M_ <sup>max</sup> 2 [MB]5 10 20 50 100
~~<u>cqgd</u>~~
<u>cq</u> _<u>∗∗</u>_
<u>c</u> _<u>∗</u>_ <u>q</u> _<u>∗</u>_
~~<u>c</u>~~ _~~<u>∗∗</u>~~_ ~~<u>q</u>~~
<u>qc</u> _<u>∗∗</u>_
_<u>∗</u>_ <u>cq</u> _<u>∗</u>_
_~~<u>∗</u>~~_ ~~<u>c</u>~~ _~~<u>∗</u>~~_ ~~<u>q</u>~~
~~<u>q</u>~~ _~~<u>∗</u>~~_ ~~<u>c</u>~~ _~~<u>∗</u>~~_
_~~<u>∗</u>~~_ ~~<u>qc</u>~~ _~~<u>∗</u>~~_
_~~<u>∗∗</u>~~_ ~~<u>cq</u>~~
<u>q</u> _<u>∗∗</u>_ <u>c</u>
_~~<u>∗</u>~~_ ~~<u>q</u>~~ _~~<u>∗</u>~~_ ~~<u>c</u>~~
_<u>∗∗</u>_ ~~<u>default</u>~~ <u>qc</u>
1 2 5 10 20 50
_<u>M</u>_ <sup>max</sup> _<u>/Mr</u>_ <sup>max</sup>
50 100 200 _M_ <sup>max</sup> [MB]500 1000 2000
~~<u>cqgd</u>~~
<u>cq</u> _<u>∗∗</u>_
<u>c</u> _<u>∗</u>_ <u>q</u> _<u>∗</u>_
~~<u>c</u>~~ _~~<u>∗∗</u>~~_ ~~<u>q</u>~~
<u>qc</u> _<u>∗∗</u>_
_<u>∗</u>_ <u>cq</u> _<u>∗</u>_
_~~<u>∗</u>~~_ ~~<u>c</u>~~ _~~<u>∗</u>~~_ ~~<u>q</u>~~
~~<u>q</u>~~ _~~<u>∗</u>~~_ ~~<u>c</u>~~ _~~<u>∗</u>~~_
_~~<u>∗</u>~~_ ~~<u>qc</u>~~ _~~<u>∗</u>~~_
_~~<u>∗∗</u>~~_ ~~<u>cq</u>~~
<u>q</u> _<u>∗∗</u>_ <u>c</u>
_~~<u>∗</u>~~_ ~~<u>q</u>~~ _~~<u>∗</u>~~_ ~~<u>c</u>~~
_<u>∗∗</u>_ ~~<u>default</u>~~ <u>qc</u>
1 2 5 10 20 50
_<u>M</u>_ <sup>max</sup> _<u>/Mr</u>_ <sup>max</sup>
500 1000 _M_ <sup>max</sup> 2000[MB] 5000 10000 20000
oel: 02,01
01,01
12,01
oel: 02,01
01,01
12,01
oedas: 02,01
01,01
12,01
oe: 02,01
01,01
numba:
npl: 01,01
np: 01,01
jxv: 12,01
01,01
oedas: 02,01
01,01
12,01
numba:
numba:
jx: 12,01
01,01
oe: 02,01
01,01
numba:
npl: 01,01
np: 01,01
jxv: 12,01
01,01
jx: 12,01
01,01
das: 01,01
das: 01,01
Figure 4: Elapsed time and memory requirements of the weak Laplacian einsum expression depending on the operand memory layouts for 8192 cells, FE approximation orders 1 (top), 2 (middle),
3 (bottom). Left: (relative) elapsed time mean without the worst case ( _T_ <sup>¯ww</sup> _/T_ <sup>¯</sup> _r_ <sup>ww</sup>, _T_ <sup>¯ww</sup> ). Right:
(relative) maximum memory consumption ( _M_ <sup>max</sup> _/Mr_ <sup>max</sup>, _M_ <sup>max</sup> ). The reference values obtained
by SfePy are marked by vertical red lines. The libraries and contraction paths are indicated in _y_
axis labels. The colors/markers indicate positions of cell and quadrature axes in the layout string,
the SfePy layout is marked by black crosses among einsum expression backends.
order lib _T_ ¯ <sup>_ww_</sup> _/T_ ¯ _<u>r</u>_ <sup>_ww_</sup>
_<u>r</u>_ <sup>_ww_</sup> layout _T_ ¯ <sup>_ww_</sup> _/_ ¯ _Td_ <sup>_ww_</sup>
_<u>r</u>_ _<u>d</u>_
1 das 1 _._ 65 cdgq 0.54
jx 0 _._ 58 cgqd 0.79
jxv 12 _._ 91 cdgq 0.54
np 1 _._ 33 cdgq 0.50
npl 57 _._ 76 cgqd 0.95
oe 1 _._ 27 cdgq 0.48
oedas 1 _._ 70 cdgq 0.54
oel 60 _._ 52 gcdq 0.79
2 das 1 _._ 12 cdgq 0.43
jx 0 _._ 87 cdgq 0.87
jxv 1 _._ 83 cgqd 0.91
np 0 _._ 95 cdgq 0.39
npl 3 _._ 42 cgqd 0.98
oe 1 _._ 06 cdgq 0.41
oedas 1 _._ 94 cdgq 0.56
oel 4 _._ 87 cqgd 0.99
3 das 0 _._ 88 cdgq 0.35
jx 0 _._ 50 cgqd 0.78
jxv 0 _._ 51 cgqd 0.81
np 0 _._ 82 cdgq 0.33
npl 0 _._ 75 gcdq 0.99
oe 0 _._ 83 cdgq 0.33
oedas 0 _._ 97 cdgq 0.36
oel 0 _._ 87 cgdq 0.98
Table 7: The fastest layouts per FE approximation order and backend in the case of the weak
Laplacian einsum expression, _T_ <sup>¯ww</sup> _/T_ <sup>¯</sup> _d_ <sup>ww</sup> terms the relative speed-up of the fastest layout w.r.t.
the default layout.
specified using permutations of the reduced default layout `cqgvd`, because the weak form has no
material parameters (no `0` ).
Elapsed time and memory requirements of the individual backends are shown in Fig. 5 for the
FE approximation orders 1 (top), 2 (bottom). Both _T_ <sup>¯ww</sup> _/T_ <sup>¯</sup> _r_ <sup>ww</sup> with _T_ <sup>¯ww</sup> and _M_ <sup>max</sup> _/Mr_ <sup>max</sup> with
_M_ <sup>max</sup> are shown. The libraries and contraction paths are indicated in _y_ axis labels. Again the
values at most 4 _×_ slower than the reference SfePy implementation are shown, with the corresponding memory consumption. To reduce the color/marker legend size, only positions of `cq` axes
are indicated in the legend, `*` denotes any letter from `gvd` . Abbreviations given in Tab. 9 are used
to save space, the plus sign denotes addition of two einsum expressions due to the convective term
nonlinearity.
6.4.3 Layouts Discussion
Based on the above results, the following observations were made:
- For each approximation order, there was a single contraction path per library/optimization
pair, independent of the layout.
- The layouts were both slower and faster than the default `cqgvd0` layout. Although there was
not a single best layout, some patterns can be observed in Figs. 4, 5. According to Tab. 7,
`cdgq` was 14 _×_, and `cgqd` 6 _×_ the fastest layout for the weak Laplacian, while, according to
Tab. 8, `cqgdv` was 3 _×_, and `cgvdq` 2 _×_ the fastest layout for the weak convective term.
- In the weak Laplacian case, 37.3%, of layouts were no more than 4 _×_ slower and 3.2%
18
15
14
13
oel: 12
10
08
07
01
11
oedas: 05
02
14
11
oe: 05
04
03
02
17
npl: 16
10
06
np: 09
05
18
jxv: 15
10
07
jx: 05
02
das: 09
05
<u>cqgvd</u>
~~<u>cq</u>~~ _~~<u>∗∗∗</u>~~_
<u>c</u> _<u>∗</u>_ <u>q</u> _<u>∗∗</u>_
<u>c</u> _<u>∗∗</u>_ <u>q</u> _<u>∗</u>_
<u>c</u> _<u>∗∗∗</u>_ <u>q</u>
<u>qc</u> _<u>∗∗∗</u>_
_<u>∗</u>_ <u>cq</u> _<u>∗∗</u>_
_~~<u>∗</u>~~_ ~~<u>c</u>~~ _~~<u>∗</u>~~_ ~~<u>q</u>~~ _~~<u>∗</u>~~_
_<u>∗</u>_ <u>c</u> _<u>∗∗</u>_ <u>q</u>
<u>q</u> _<u>∗</u>_ <u>c</u> _<u>∗∗</u>_
_<u>∗</u>_ <u>qc</u> _<u>∗∗</u>_
_~~<u>∗∗</u>~~_ ~~<u>cq</u>~~ _~~<u>∗</u>~~_
_<u>∗∗</u>_ <u>c</u> _<u>∗</u>_ <u>q</u>
~~<u>q</u>~~ _~~<u>∗∗</u>~~_ ~~<u>c</u>~~ _~~<u>∗</u>~~_
_<u>∗</u>_ <u>q</u> _<u>∗</u>_ <u>c</u> _<u>∗</u>_
_<u>∗∗</u>_ <u>qc</u> _<u>∗</u>_
_<u>∗∗∗</u>_ <u>cq</u>
~~<u>q</u>~~ _~~<u>∗∗∗</u>~~_ ~~<u>c</u>~~
_<u>∗</u>_ <u>q</u> _<u>∗∗</u>_ <u>c</u>
_~~<u>∗∗</u>~~_ ~~<u>q</u>~~ _~~<u>∗</u>~~_ ~~<u>c</u>~~
_<u>∗∗∗</u>_ <u>qc</u>
18
15
14
13
oel: 12
10
08
07
01
11
oedas: 05
02
14
11
oe: 05
04
03
02
17
npl: 16
10
06
np: 09
05
18
jxv: 15
10
07
jx: 05
02
das: 09
05
0.2 0.3 0.5 0.7 1 1.5 2 3 4
_T_ ¯ <sup>ww</sup> _/_ ¯ _Tr_ <sup>_ww_</sup>
0.02 0.05 0.1 0.2 0.5
_T_ ¯ <sup>ww</sup> [s]
<u>cqgvd</u>
~~<u><mark>cq</mark></u>~~ _~~<u><mark>∗∗∗</mark></u>~~_
<u>c</u> _<u>∗</u>_ <u>q</u> _<u>∗∗</u>_
<u>c</u> _<u>∗∗</u>_ <u>q</u> _<u>∗</u>_
<u>c</u> _<u>∗∗∗</u>_ <u>q</u>
<u>qc</u> _<u>∗∗∗</u>_
_<u>∗</u>_ <u>cq</u> _<u>∗∗</u>_
_~~<u>∗</u>~~_ ~~<u>c</u>~~ _~~<u>∗</u>~~_ ~~<u>q</u>~~ _~~<u>∗</u>~~_
_<u>∗</u>_ <u>c</u> _<u>∗∗</u>_ <u>q</u>
<u>q</u> _<u>∗</u>_ <u>c</u> _<u>∗∗</u>_
_<u>∗</u>_ <u>qc</u> _<u>∗∗</u>_
_~~<u>∗∗</u>~~_ ~~<u>cq</u>~~ _~~<u>∗</u>~~_
_<u>∗∗</u>_ <u>c</u> _<u>∗</u>_ <u>q</u>
~~<u>q</u>~~ _~~<u>∗∗</u>~~_ ~~<u>c</u>~~ _~~<u>∗</u>~~_
_<u>∗</u>_ <u>q</u> _<u>∗</u>_ <u>c</u> _<u>∗</u>_
_<u>∗∗</u>_ <u>qc</u> _<u>∗</u>_
_<u>∗∗∗</u>_ <u>cq</u>
~~<u>q</u>~~ _~~<u>∗∗∗</u>~~_ ~~<u>c</u>~~
_<u>∗</u>_ <u>q</u> _<u>∗∗</u>_ <u>c</u>
_~~<u>∗∗</u>~~_ ~~<u>q</u>~~ _~~<u>∗</u>~~_ ~~<u>c</u>~~
_<u>∗∗∗</u>_ <u>qc</u>
~~<u>cqgvd</u>~~
~~<mark>cq</mark>~~ _~~<u><mark>∗∗∗</mark></u>~~_
~~c~~ _~~<u>∗</u>~~_ ~~q~~ _~~<u>∗∗</u>~~_
~~c~~ _~~<u>∗∗</u>~~_ ~~q~~ _~~<u>∗</u>~~_
~~c~~ _~~<u>∗∗∗</u>~~_ ~~q~~
~~qc~~ _~~<u>∗∗∗</u>~~_
_~~<u>∗</u>~~_ ~~<u>cq</u>~~ _~~<u>∗∗</u>~~_
_~~<u>∗</u>~~_ ~~c~~ _~~<u>∗</u>~~_ ~~q~~ _~~<u>∗</u>~~_
_~~<u>∗</u>~~_ ~~c~~ _~~<u>∗∗</u>~~_ ~~q~~
~~q~~ _~~<u>∗</u>~~_ ~~c~~ _~~<u>∗∗</u>~~_
_~~<u>∗</u>~~_ ~~<u>qc</u>~~ _~~<u>∗∗</u>~~_
_~~<u>∗∗</u>~~_ ~~cq~~ _~~<u>∗</u>~~_
_~~<u>∗∗</u>~~_ ~~<u>c</u>~~ _~~<u>∗</u>~~_ ~~<u>q</u>~~
~~q~~ _~~<u>∗∗</u>~~_ ~~c~~ _~~<u>∗</u>~~_
_~~<u>∗</u>~~_ ~~q~~ _~~<u>∗</u>~~_ ~~c~~ _~~<u>∗</u>~~_
_~~<u>∗∗</u>~~_ <u>qc</u> _~~<u>∗</u>~~_
_~~<u>∗∗∗</u>~~_ ~~<u>cq</u>~~
<u>q</u> _<u>∗∗∗</u>_ <u>c</u>
_~~<u>∗</u>~~_ ~~<u>q</u>~~ _~~<u>∗∗</u>~~_ ~~<u>c</u>~~
_<u>∗∗</u>_ <u>q</u> _<u>∗</u>_ <u>c</u>
_<u>∗∗∗</u>_ <u>qc</u>
18
15
14
13
oel: 12
10
08
07
01
11
18
15
14
13
1 2
_M_ <sup>max</sup> _/Mr_ <sup>max</sup>
50 100
_M_ <sup>max</sup> [MB]
1 2
_M_ <sup>max</sup> _/Mr_ <sup>max</sup>
500 1000
_M_ <sup>max</sup> [MB]
oel: 12
10
08
07
01
11
oedas: 05
02
14
11
oedas: 05
02
14
11
oe: 05
04
03
02
17
npl: 16
10
06
np: 09
05
18
jxv: 15
10
07
jx: 05
02
~~<u>cqgvd</u>~~
~~cq~~ _~~<u>∗∗∗</u>~~_
~~c~~ _~~<u>∗</u>~~_ ~~q~~ _~~<u>∗∗</u>~~_
~~c~~ _~~<u>∗∗</u>~~_ ~~q~~ _~~<u>∗</u>~~_
~~c~~ _~~<u>∗∗∗</u>~~_ ~~q~~
~~qc~~ _~~<u>∗∗∗</u>~~_
_~~<u>∗</u>~~_ ~~<u>cq</u>~~ _~~<u>∗∗</u>~~_
_~~<u>∗</u>~~_ ~~c~~ _~~<u>∗</u>~~_ ~~q~~ _~~<u>∗</u>~~_
_~~<u>∗</u>~~_ ~~c~~ _~~<u>∗∗</u>~~_ ~~q~~
~~q~~ _~~<u>∗</u>~~_ ~~c~~ _~~<u>∗∗</u>~~_
_~~<u><mark>∗</mark></u>~~_ ~~<u>qc</u>~~ _~~<u>∗∗</u>~~_
_~~<u><mark>∗</mark></u>~~_ _~~<u>∗</u>~~_ ~~cq~~ _~~<u>∗</u>~~_
_~~<u><mark>∗</mark></u>~~_ _~~<u>∗</u>~~_ ~~<u>c</u>~~ _~~<u>∗</u>~~_ ~~<u>q</u>~~
~~q~~ _~~<u>∗∗</u>~~_ ~~c~~ _~~<u>∗</u>~~_
_~~<u>∗</u>~~_ ~~q~~ _~~<u>∗</u>~~_ ~~c~~ _~~<u>∗</u>~~_
_~~<u>∗∗</u>~~_ ~~qc~~ _~~<u>∗</u>~~_
_~~<u>∗∗∗</u>~~_ ~~<u>cq</u>~~
<u>q</u> _<u>∗∗∗</u>_ <u>c</u>
_~~<u>∗</u>~~_ ~~<u>q</u>~~ _~~<u>∗∗</u>~~_ ~~<u>c</u>~~
_<u>∗∗</u>_ <u>q</u> _<u>∗</u>_ <u>c</u>
_<u>∗∗∗</u>_ <u>qc</u>
0.2 0.3 0.5 0.7 1 1.5 2 3 4
_T_ ¯ <sup>ww</sup> _/_ ¯ _Tr_ <sup>_ww_</sup>
1 2 5 10
_T_ ¯ <sup>ww</sup> [s]
oe: 05
04
03
02
17
npl: 16
10
06
np: 09
05
18
jxv: 15
10
07
jx: 05
02
das: 09
05
das: 09
05
Figure 5: Elapsed time and memory requirements of the weak convective term einsum expression
depending on the operand memory layouts for 8192 cells, FE approximation orders 1 (top), 2
(bottom). Left: (relative) elapsed time mean without the worst case ( _T_ <sup>¯ww</sup> _/T_ <sup>¯</sup> _r_ <sup>ww</sup>, _T_ <sup>¯ww</sup> ). Right:
(bottom). Left: (relative) elapsed time mean without the worst case ( _T_ <sup>¯ww</sup> _/T_ <sup>¯</sup> _r_ <sup>ww</sup>, _T_ <sup>¯ww</sup> ). Right:
(relative) maximum memory consumption ( _M_ <sup>max</sup> _/Mr_ <sup>max</sup>, _M_ <sup>max</sup> ). The reference values obtained
(relative) maximum memory consumption ( _M_ <sup>max</sup> _/Mr_ <sup>max</sup>, _M_ <sup>max</sup> ). The reference values obtained
by SfePy are marked by vertical red lines. The libraries and contraction paths are indicated in _y_
axis labels, see Tab. 9. The colors/markers indicate positions of cell and quadrature axes in the
layout string, the SfePy layout is marked by black crosses among einsum expression backends.
order lib _T_ ¯ <sup>_ww_</sup> _/T_ ¯ _<u>r</u>_ <sup>_ww_</sup>
_<u>r</u>_ <sup>_ww_</sup> layout _T_ ¯ <sup>_ww_</sup> _/_ ¯ _Td_ <sup>_ww_</sup>
_<u>r</u>_ _<u>d</u>_
1 das 1 _._ 05 vdgcq 0.82
jx 0 _._ 47 cqgdv 0.98
jxv 3 _._ 71 cqgvd 1.00
np 2 _._ 18 gvdcq 0.89
npl 25 _._ 73 cdgqv 1.00
oe 0 _._ 58 vdcqg 0.82
oedas 1 _._ 00 dvcqg 0.88
oel 32 _._ 74 cqgdv 0.99
2 das 0 _._ 82 cgdqv 0.95
jx 0 _._ 18 cqgdv 0.96
jxv 0 _._ 28 vcqgd 0.99
np 1 _._ 25 gdvcq 0.98
npl 0 _._ 92 cvdgq 0.98
oe 0 _._ 19 cgvdq 0.85
oedas 0 _._ 28 cgvdq 0.90
oel 1 _._ 20 gcdqv 0.95
Table 8: The fastest layouts per FE approximation order and backend in the case of the weak
convective term einsum expression, _T_ <sup>¯ww</sup> _/T_ <sup>¯</sup> _d_ <sup>ww</sup> terms the relative speed-up of the fastest layout
w.r.t. the default layout.
contraction paths abbreviations
- 01,02,12,03,02,01+01,02,04,13,02,01 01
01,02,12,03,02,01+06,04,02,03,02,01 02
03,34,34,03,01,01+03,12,01,12,02,01 03
03,34,34,03,01,01+15,13,14,03,02,01 04
03,34,34,03,01,01+34,05,14,23,01,01 05
24,34,04,13,02,01+01,02,04,02,01,01 06
24,34,04,13,02,01+01,02,04,13,01,01 07
24,34,04,13,02,01+05,05,02,03,02,01 08
24,34,04,13,02,01+06,04,02,03,02,01 09
24,34,04,13,02,01+06,13,14,23,02,01 10
24,34,04,13,02,01+15,13,14,13,02,01 11
24,34,04,13,02,01+24,25,34,03,12,01 12
24,34,24,01,12,01+24,01,03,13,01,01 13
24,34,24,03,02,01+34,45,34,23,02,01 14
56,35,01,23,01,01+34,01,34,13,02,01 15
56,35,01,23,01,01+34,05,14,23,02,01 16
56,35,23,01,02,01+34,25,34,01,02,01 17
56,35,23,01,02,01+34,25,34,01,20,01 18
Table 9: The mapping of convective term einsum expression contraction paths to short labels in
Fig. 5.
were faster than the reference implementation for the approximation order 1 while for the
approximation orders 2 it was 27.0% and 1.9%, respectively. For the approximation order 3,
due to the 50 s time-out, all layouts times were within the 4 _×_ limit and 49.1% were faster
than the reference implementation. In the case of the weak convective term, 51.2% resp.
99.1% of layouts were no more than 4 _×_ slower and 20.1% resp. 44.8% were faster than the
reference implementation for the approximation orders 1 resp. 2.
- In the weak Laplacian case, the jx backend performed the best in terms of the elapsed time,
but required much more memory. For the approximation order 1, it was the only backend
faster than the reference implementation, together with the hand-written Numba code, due
to the low numerical intensity of the calculations. From the order 2, np and oe backends
started to be competitive and for the order 3 also the loop-based npl and oel backends with
their low memory footprint, as well as oedas.
- In the weak convective term case, being more computationally intensive, many oe backend
layouts were faster than the reference implementation already for the approximation order
1, together with the again fastest jx layouts. For the order 2, also jxv and das, oedas (lower
memory usage than oe) layouts out-performed the reference implementation.
We can conclude that alternative layouts can be used as another simple way of speeding the FE
weak form evaluation calculations using einsum expressions, additional to optimized contraction
paths.
6.5 Performance of Selected Weak Forms Contractions
A parametric study run using soops [9] lead to 6478 finished simulations <sup>6</sup>, each evaluating a single
weak form using a single backend/optimization combination several times according to the repeat
parameter for various mesh sizes and function approximation orders, see Tab. 5. The default
`cqgvd0` layout of the weak form einsum expression operands and result arrays was used.
First the overall results, i.e. the fastest backend for each weak form, number of cells and FE
approximation order, are presented in Section 6.5.1. Because many backends/contraction paths
performed similarly, we provide also a detailed comparison in Sections 6.5.3– 6.5.7, where both the
elapsed time differences among the backends/contraction paths are shown, alongside the memory
consumption. The discussions of evaluation performance are included directly in the respective
sections.
6.5.1 Overall Results
The overall results are summarized in Tab. 10 for the residual mode and in Tab. 11 for the matrix
mode evaluations. For each weak form, mesh size and FE approximation order, the shortest elapsed
time mean without the worst case _T_ <sup>¯ww</sup> across all backends is given, as well as the corresponding
backend and _T_ <sup>¯ww</sup> _/T_ <sup>¯</sup> _r_ <sup>ww</sup> .
In the residual mode, the oe and np backends were the fastest for the weak Laplacian, oe,
followed by np and jx for vector dot product weak form and mostly jx, with several occurrences
of oe and np for the other three weak forms with the exception of the order 4 and 5 of the linear
elastic form, where the loop-based backends npl and oel performed the best. According to the
relative elapsed times means, the evaluations were mostly faster or comparable with the reference
implementation, except the case of the linear elastic weak form.
In the case of the much more memory demanding matrix mode, the jx backend was mostly
the fastest when evaluating the weak Laplacian, the convective and the linear elasticity weak
forms. Notable exceptions occurred for the largest mesh size, where the memory-demanding jx
was replaced by oedas (convective term) and oe (elasticity), see also the detailed analysis in the
following sections. Note also that jx was much slower for small problems in the _T_ <sup>¯</sup> metric, because
of the JIT initialization in the first evaluation, omitted in _T_ <sup>¯ww</sup> . The jxv backend, followed by npl,
were mostly the fastest in the case of the vector dot product form, while for the weighted vector
dot product, the oe (most orders 1) and np (most orders 2) backends were the fastest.
Analogical tables summarizing the results of the simulations without the single-thread limitation are presented in Appendix A. A detailed comparison of the backends and tensors contraction
paths follows in the next sections.
6This includes the reference implementation simulations shown in Fig. 2. 26 backend/optimization pairs, 25
mesh size/order combinations, 5 terms and 2 evaluation modes, 6500 in total, 22 failed due to insufficient memory.
#cells order Laplacian v. dot weighted v. dot NS convective elasticity
1,024 1 0 _._ 01 (oe 0.9) 0 _._ 01 (oe 0.9) 0 _._ 01 (jx 1.0) 0 _._ 01 (jx 1.0) 0 _._ 01 (jx 1.1)
2 0 _._ 01 (oe 0.9) 0 _._ 01 (oe 0.8) 0 _._ 01 (jx 0.9) 0 _._ 02 (jx 0.8) 0 _._ 03 (jx 1.5)
3 0 _._ 02 (oe 0.6) 0 _._ 02 (jx 0.5) 0 _._ 02 (jx 0.5) 0 _._ 04 (jx 0.6) 0 _._ 12 (jx 1.6)
4 0 _._ 06 (oe 0.5) 0 _._ 03 (jx 0.3) 0 _._ 03 (jx 0.4) 0 _._ 11 (jx 0.5) 0 _._ 41 (jx 1.8)
5 0 _._ 15 (oe 0.4) 0 _._ 06 (jx 0.2) 0 _._ 07 (jx 0.3) 0 _._ 30 (jx 0.5) 0 _._ 74 (npl 1.2)
2,048 1 0 _._ 01 (oe 1.1) 0 _._ 01 (jx 1.0) 0 _._ 01 (jx 1.0) 0 _._ 01 (jx 1.0) 0 _._ 02 (jx 1.1)
2 0 _._ 02 (np 0.9) 0 _._ 02 (jx 0.8) 0 _._ 02 (jx 0.8) 0 _._ 02 (jx 0.6) 0 _._ 06 (jx 1.8)
3 0 _._ 04 (np 0.5) 0 _._ 02 (jx 0.4) 0 _._ 03 (jx 0.5) 0 _._ 07 (jx 0.5) 0 _._ 22 (jx 1.7)
4 0 _._ 11 (oe 0.4) 0 _._ 05 (jx 0.3) 0 _._ 06 (jx 0.3) 0 _._ 20 (jx 0.5) 0 _._ 81 (jx 1.8)
4,096 1 0 _._ 01 (oe 0.9) 0 _._ 01 (np 1.0) 0 _._ 02 (jx 1.1) 0 _._ 01 (jx 0.9) 0 _._ 02 (jx 1.1)
2 0 _._ 02 (oe 0.8) 0 _._ 02 (jx 0.6) 0 _._ 02 (jx 0.7) 0 _._ 03 (jx 0.5) 0 _._ 11 (jx 2.1)
3 0 _._ 06 (oe 0.5) 0 _._ 04 (jx 0.4) 0 _._ 05 (jx 0.4) 0 _._ 12 (jx 0.5) 0 _._ 45 (jx 1.8)
8,192 1 0 _._ 01 (oe 1.0) 0 _._ 01 (jx 1.0) 0 _._ 02 (jx 0.9) 0 _._ 02 (jx 0.7) 0 _._ 03 (jx 1.2)
2 0 _._ 03 (oe 0.7) 0 _._ 03 (jx 0.6) 0 _._ 04 (jx 0.7) 0 _._ 06 (jx 0.6) 0 _._ 21 (jx 2.0)
3 0 _._ 12 (oe 0.4) 0 _._ 07 (jx 0.3) 0 _._ 10 (jx 0.5) 0 _._ 23 (jx 0.5) 0 _._ 82 (jx 1.6)
16,384 1 0 _._ 02 (np 1.0) 0 _._ 02 (jx 0.9) 0 _._ 02 (jx 0.9) 0 _._ 02 (jx 0.7) 0 _._ 05 (jx 1.3)
2 0 _._ 06 (np 0.7) 0 _._ 05 (jx 0.5) 0 _._ 07 (jx 0.7) 0 _._ 10 (jx 0.5) 0 _._ 41 (jx 2.0)
32,768 1 0 _._ 03 (oe 0.9) 0 _._ 03 (jx 0.9) 0 _._ 04 (jx 0.9) 0 _._ 04 (jx 0.6) 0 _._ 09 (jx 1.4)
2 0 _._ 10 (oe 0.6) 0 _._ 08 (jx 0.5) 0 _._ 13 (jx 0.7) 0 _._ 19 (jx 0.5) 0 _._ 81 (jx 2.1)
65,536 1 0 _._ 04 (oe 0.9) 0 _._ 05 (jx 0.9) 0 _._ 08 (jx 1.1) 0 _._ 06 (jx 0.6) 0 _._ 17 (jx 1.3)
2 0 _._ 20 (oe 0.6) 0 _._ 17 (jx 0.5) 0 _._ 29 (jx 0.8) 0 _._ 39 (jx 0.6) 1 _._ 61 (jx 2.1)
131,072 1 0 _._ 07 (oe 0.9) 0 _._ 08 (oe 0.9) 0 _._ 13 (jx 1.0) 0 _._ 12 (jx 0.6) 0 _._ 33 (jx 1.4)
262,144 1 0 _._ 13 (oe 1.0) 0 _._ 15 (oe 0.9) 0 _._ 30 (jx 1.1) 0 _._ 24 (jx 0.6) 0 _._ 66 (jx 1.4)
524,288 1 0 _._ 26 (oe 0.9) 0 _._ 30 (oe 0.9) 0 _._ 58 (jx 1.1) 0 _._ 47 (jx 0.6) 1 _._ 33 (jx 1.5)
1,048,576 1 0 _._ 50 (oe 0.9) 0 _._ 58 (oe 0.9) 1 _._ 13 (jx 1.1) 0 _._ 92 (jx 0.5) 2 _._ 63 (jx 1.5)
Table 10: Summary results of residual evaluation mode. For each weak form, mesh size and FE
approximation order, the shortest elapsed time mean without the worst case _T_ <sup>¯ww</sup> [s] across all
backends is given, as well as the corresponding backend and _T_ <sup>¯ww</sup> _/T_ <sup>¯</sup> _r_ <sup>ww</sup> (in parentheses).
6.5.2 Detailed Weak Form Analyses — Common Settings
Two kinds of figures are presented below for the five selected weak forms:
- To allow comparison among the five weak forms, the highest throughput of each backend is
presented in Figs. 6–14. The throughput is defined as the the size (in MB) of the resulting
array of vectors (residual mode) or matrices (matrix mode) divided by the shortest elapsed
time means without the worst case _T_ <sup>¯ww</sup> for each backend, i.e. _|r|/T_ <sup>¯ww</sup>, resp. _|M_ _|/T_ <sup>¯ww</sup>,
corresponding to the highest number of megabytes each backend evaluates per second. The
backends are indicated by markers, while the fastest einsum contraction paths by color. The
cell counts ( _x_ axis) are grouped by the approximation orders.
- Relative elapsed time means without the worst case _T_ <sup>¯ww</sup> _/T_ <sup>¯</sup> _r_ <sup>ww</sup> and relative maximum memory consumption _M_ <sup>max</sup> _/Mr_ <sup>max</sup> are reported in Figs. 7–15 using the _x_ axis logarithmic scale.
The backends are indicated by markers, while the einsum contraction paths by color, the
same as in the throughput figures. The cell counts ( _y_ axis) are grouped by the approximation
orders. Only cases no more than 5 _×_ slower than the reference implementation are shown.
6.5.3 Weak Laplacian
The performance of the einsum backends applied to the evaluation of the weak Laplacian einsum
expression is shown in Figs. 6 (evaluation throughput) and 7 (relative performance).
#cells order Laplacian v. dot weighted v. dot NS convective elasticity
1,024 1 0 _._ 01 (jx 1.0) 0 _._ 02 (jx 1.0) 0 _._ 02 (jx 1.0) 0 _._ 02 (jx 0.8) 0 _._ 03 (jx 1.4)
2 0 _._ 04 (jx 1.0) 0 _._ 10 (np 0.5) 0 _._ 10 (np 0.5) 0 _._ 14 (jx 0.4) 0 _._ 37 (jx 1.5)
3 0 _._ 24 (jx 0.6) 0 _._ 33 (npl 0.0) 0 _._ 73 (np 0.1) 0 _._ 83 (jx 0.1) 1 _._ 99 (jx 0.4)
4 1 _._ 72 (jx 0.3) 1 _._ 29 (npl 0.0) 3 _._ 57 (jx 0.1) 4 _._ 38 (jxv 0.1) 13 _._ 89 (jx 0.4)
5 5 _._ 07 (jx 0.2) 4 _._ 78 (npl 0.0) 15 _._ 53 (jx 0.1) 17 _._ 71 (jx 0.0) 46 _._ 30 (jx 0.3)
2,048 1 0 _._ 01 (jx 1.0) 0 _._ 02 (jx 1.0) 0 _._ 02 (np 0.9) 0 _._ 02 (jx 0.7) 0 _._ 05 (jx 1.7)
2 0 _._ 07 (jx 0.9) 0 _._ 18 (jx 0.5) 0 _._ 18 (np 0.5) 0 _._ 27 (jx 0.4) 0 _._ 70 (jx 1.4)
3 0 _._ 49 (jx 0.7) 0 _._ 65 (npl 0.0) 1 _._ 45 (jx 0.1) 1 _._ 62 (jx 0.1) 4 _._ 01 (jx 0.4)
4 3 _._ 48 (npl 0.3) 2 _._ 54 (npl 0.0) 7 _._ 18 (jx 0.1) 8 _._ 60 (jxv 0.0) 27 _._ 70 (jx 0.4)
4,096 1 0 _._ 02 (jx 1.0) 0 _._ 05 (jx 1.4) 0 _._ 03 (oe 0.9) 0 _._ 04 (jx 0.6) 0 _._ 09 (jx 1.9)
2 0 _._ 12 (jx 0.9) 0 _._ 39 (jxv 0.6) 0 _._ 34 (np 0.5) 0 _._ 53 (jx 0.4) 1 _._ 39 (jx 1.4)
3 1 _._ 01 (jxv 0.7) 1 _._ 27 (npl 0.0) 2 _._ 92 (np 0.1) 3 _._ 31 (jx 0.1) 8 _._ 25 (jx 0.4)
8,192 1 0 _._ 02 (jx 1.0) 0 _._ 06 (jx 1.2) 0 _._ 05 (oe 0.9) 0 _._ 08 (jx 0.7) 0 _._ 19 (jx 2.2)
2 0 _._ 25 (jx 1.0) 0 _._ 69 (jxv 0.5) 0 _._ 66 (np 0.5) 1 _._ 05 (jx 0.4) 2 _._ 79 (jx 1.4)
3 1 _._ 85 (jx 0.6) 2 _._ 55 (npl 0.0) 5 _._ 70 (jx 0.1) 6 _._ 50 (jx 0.1) 15 _._ 97 (jx 0.4)
16,384 1 0 _._ 04 (jx 1.1) 0 _._ 19 (jxv 1.9) 0 _._ 10 (oe 0.8) 0 _._ 14 (jx 0.7) 0 _._ 34 (jx 2.2)
2 0 _._ 47 (jx 0.9) 1 _._ 21 (jxv 0.5) 1 _._ 33 (np 0.5) 2 _._ 04 (jxv 0.3) 5 _._ 44 (jx 1.4)
32,768 1 0 _._ 06 (jx 1.1) 0 _._ 28 (jxv 1.5) 0 _._ 18 (oe 0.8) 0 _._ 28 (jx 0.6) 0 _._ 67 (jx 2.3)
2 0 _._ 95 (jx 1.0) 2 _._ 26 (jxv 0.4) 2 _._ 66 (np 0.5) 3 _._ 94 (jxv 0.3) 11 _._ 12 (jx 1.5)
65,536 1 0 _._ 13 (jx 1.2) 0 _._ 44 (jxv 1.2) 0 _._ 35 (oe 0.9) 0 _._ 54 (jx 0.7) 1 _._ 32 (jx 2.2)
2 1 _._ 84 (jx 0.9) 4 _._ 74 (jxv 0.5) 5 _._ 29 (np 0.5) 7 _._ 70 (jxv 0.3) 22 _._ 29 (jx 1.4)
131,072 1 0 _._ 24 (jx 1.2) 0 _._ 79 (jxv 1.2) 0 _._ 68 (oe 0.9) 1 _._ 07 (jx 0.6) 2 _._ 62 (jx 2.3)
262,144 1 0 _._ 46 (jx 1.2) 1 _._ 49 (jxv 1.1) 1 _._ 39 (oe 0.9) 2 _._ 11 (jx 0.7) 5 _._ 23 (jx 2.3)
524,288 1 0 _._ 95 (jx 1.3) 2 _._ 87 (jxv 1.1) 2 _._ 79 (oe 0.9) 4 _._ 30 (jx 0.7) 10 _._ 55 (jx 2.4)
1,048,576 1 1 _._ 86 (jx 1.3) 5 _._ 64 (jxv 1.1) 5 _._ 56 (oe 0.9) 13 _._ 75 (oedas 1.0) 57 _._ 33 (oe 6.4)
Table 11: Summary results of matrix evaluation mode. For each weak form, mesh size and FE
approximation order, the shortest elapsed time mean without the worst case _T_ <sup>¯ww</sup> [s] across all
backends is given, as well as the corresponding backend and _T_ <sup>¯ww</sup> _/T_ <sup>¯</sup> _r_ <sup>ww</sup> (in parentheses).
In the residual mode, the oe backend was the fastest in most cases, followed by np and das
with oedas. It was faster than the reference implementation even for the order 1. From the order
2, also das and oedas, and for the order 5 also npl, oel backends out-performed the reference
implementation. The memory consumption was in general higher than the reference one for
smaller data, while for large problems several backends had a lower memory footprint: the das,
oedas backends due to array chunking, and npl, oel thanks to looping over the mesh cells.
In the matrix mode, the jx backend was the fastest and out-performed the reference implementation from the order 2. From the order 3, also npl, oel and jxv backends were faster than
the reference implementation. The cell loop backends (npl, oel) performance seemed to be less
dependent on the particular contraction paths. We attribute this to the fact that the restriction
of the operands to a cell is small and so also the temporary allocations are small - compare with
the huge memory consumption differences among the contraction paths of other backends. The
npl backend was faster than oel, probably due to a simpler code path, important again for the
small cell-restricted data.
6.5.4 Weak Convective Term
The performance of the einsum backends applied to the evaluation of the weak convective term
einsum expression is shown in Figs. 8 (evaluation throughput) and 9 (relative performance).
In the residual mode, the jx backend was the fastest by a large margin, followed by jxv. The
jx backend out-performed the reference implementation, while jxv only in some cases and all the
140
120
100
80
60
40
20
0
23,02,01
~~23,12,01~~
400
350
300
250
200
150
100
50
0
<u>01,01</u>
02,01
12,01
das
jx
<u>jxv</u>
np
npl
<u>oe</u>
oe <mark>da</mark> s
<mark>o</mark> el
~~<u>sf</u>~~ <u>e</u> ~~<u>py</u>~~
<u>das</u>
jx
jxv
~~np~~
npl
oe
~~<mark>o</mark>~~ ~~edas~~
oel
~~<u>sf</u>~~ <u>e</u> ~~<u>py</u>~~
Figure 6: The highest throughput of each backend (number of megabytes evaluated per second)
for the weak Laplacian einsum expression. Left: residual mode evaluations _|r|/T_ <sup>¯ww</sup>, right: matrix
mode evaluations _|M_ _|/T_ <sup>¯ww</sup> . The backends are indicated by markers, the einsum contraction paths
by color. The cell counts ( _x_ axis) are grouped by the approximation orders.
5: 1024
4: 2048
1024
8192
3: 4096
2048
1024
65536
32768
16384
2: 8192
4096
2048
1024
1048576
524288
262144
131072
65536
1: 32768
16384
8192
4096
2048
1024
5: 1024
4: 2048
1024
8192
3: 4096
2048
1024
65536
32768
16384
2: 8192
4096
2048
1024
1048576
524288
262144
131072
65536
1: 32768
16384
8192
4096
2048
1024
<u>das</u>
<u>jx</u>
<u>jxv</u>
<u>np</u>
<u>npl</u>
<u>oe</u>
<u>oedas</u>
<u>oel</u>
<u>sfepy</u>
<u>-</u>
<u>01,01,01</u>
<u>23,02,01</u>
<u>23,12,01</u>
<u>-</u>
<u>01,01</u>
<u>02,01</u>
<u>12,01</u>
<u>das</u>
<u>jx</u>
<u>jxv</u>
<u>np</u>
<u>npl</u>
<u>oe</u>
<u>oedas</u>
<u>oel</u>
<u>sfepy</u>
0.5 1 2 5
_T_ ¯ <sup>ww</sup> _/_ ¯ _Tr_ <sup>_ww_</sup>
0.2 0.5 1 2 5
_T_ ¯ <sup>ww</sup> _/_ ¯ _Tr_ <sup>_ww_</sup>
<u>das</u>
<u>jx</u>
<u>jxv</u>
<u>np</u>
<u>npl</u>
<u>oe</u>
<u>oedas</u>
<u>oel</u>
<u>sfepy</u>
<u>-</u>
<u>01,01,01</u>
<u>23,02,01</u>
<u>23,12,01</u>
<u>-</u>
<u>01,01</u>
<u>02,01</u>
<u>12,01</u>
5: 1024
4: 2048
1024
8192
3: 4096
2048
1024
65536
32768
16384
2: 8192
4096
2048
1024
1048576
524288
262144
131072
65536
1: 32768
16384
8192
4096
2048
1024
5: 1024
4: 2048
1024
8192
3: 4096
2048
1024
65536
32768
16384
2: 8192
4096
2048
1024
1048576
524288
262144
131072
65536
1: 32768
16384
8192
4096
2048
1024
<u>das</u>
<u>jx</u>
<u>jxv</u>
<u>np</u>
<u>npl</u>
<u>oe</u>
<u>oedas</u>
<u>oel</u>
<u>sfepy</u>
0.5 1 2 5 10 20 50 100 200
_M_ <sup>max</sup> _/Mr_ <sup>max</sup>
1 2 5 10 20 50 100
_M_ <sup>max</sup> _/Mr_ <sup>max</sup>
Figure 7: Relative elapsed time and memory requirements of the weak Laplacian einsum expression
w.r.t. the reference implementation. Left: residual mode, right: matrix mode, top: _T_ <sup>¯ww</sup> _/T_ <sup>¯</sup> _r_ <sup>ww</sup>,
bottom: _M_ <sup>max</sup> _/Mr_ <sup>max</sup> . The backends are indicated by markers, the einsum contraction paths by
color. The cell counts ( _y_ axis) are grouped by the approximation orders.
other backends were slower (mostly no more than 2 _×_ ). However, the fastest contraction paths
memory consumption of jx, jxv was up to 10 _×_ more than reference consumption. For higher order
approximations, npl, oel, das, oedas but also eo and np approached the reference times and had
lower memory consumption.
In the matrix mode, the jx backend was again the fastest, but its lead over jxv, oedas or oe
was small from the order 2. The jx backend was faster than the reference implementation from
the order 1, jxv, oedas and oe from the order 2 and essentially all backends from the order 3. The
npl, oel backends performed very well from the order 3, and unlike other backends (especially jx,
jxv) had a lower memory consumption than the reference implementation. Overall the memory
consumption stayed less than 5 _×_ reference, in contrast to the weak Laplacian in the previous
section.
6.5.5 Vector Dot Product
The performance of the einsum backends applied to the evaluation of the vector dot product
einsum expression is shown in Figs. 10 (evaluation throughput) and 11 (relative performance).
In the residual mode, the jx backend was the fastest, together with oe for the order 1, where
it out-performed the reference implementation. From the order 2 also np, oedas, das and from
the order 3 jxv backends were faster than the reference code. The memory consumption mostly
stayed less than 5 _×_ reference, except jx, jxv and oe for some contraction paths.
In the matrix mode, jxv replaced jx as the overall fastest backend for orders 1, 2, but from
the order 3 it was replaced by npl and oel. The jxv, npl backends were faster than the reference
implementation from the order 2, jx from the order 3 and das, oedas from the order 4. The
memory requirements stayed within 3 _×_ reference, npl and oel backends had memory consumption
lower than reference from the order 3.
6.5.6 Weighted Vector Dot Product
The performance of the einsum backends applied to the evaluation of the weighted vector dot
product einsum expression is shown in Figs. 12 (evaluation throughput) and 13 (relative performance).
In the residual mode, the jx backend was the fastest, followed by oe and np. From the order
2 it consistently out-performed the reference implementation, from the order 3 also oe, np, oedas
and jxv and from the order 4 also das. The memory consumption stayed mostly less than 5 _×_
reference.
In the matrix mode, most backends performed well. The oe and np backends were the fastest
in most cases and out-performed the reference implementation. From the order 2 also jx, oedas,
das and jxv, from the order 3 npl and oel were faster than the reference code. The jx and jxv
backends were the fastest from the order 4. The memory consumption stayed mostly less than 3 _×_
reference, the npl and oel backends had smaller footprint from the order 3.
6.5.7 Linear Elasticity
The performance of the einsum backends applied to the evaluation of the weak linear elasticity
term einsum expression is shown in Figs. 14 (evaluation throughput) and 15 (relative performance).
In the residual mode, the jx backend was the fastest but mostly almost 2 _×_ slower than the
reference implementation. For the order 5, the npl and oel backends performed better than jx,
but they were still slower than the reference code. The memory consumption of oel, npl and das
was smaller and of oedas, das smaller or comparable to the reference implementation. Overall it
mostly stayed less than 5 _×_ reference, except for jx and jxv from the order 3, where it reached
almost 30 _×_ reference values.
In the matrix mode, the jx, jxv backends performed the best and were faster than reference
from the order 3, together with the oel backend. The memory consumption was mostly less than
7 _×_ reference values.
600
500
400
300
200
100
0
200
150
100
50
0
<u>01,02,12,03,12,01</u>
24,34,04,13,12,01
24,34,24,23,02,01
34,34,34,03,02,01
34,34,34,23,02,01
~~56,35,34,23,02,01~~
das
jx
jxv
<u>np</u>
<u>npl</u>
oe
oe <mark>da</mark> s
<mark>o</mark> el
~~sfepy~~
da <mark>s</mark>
<u>jx</u>
<mark>jx</mark> v
np
npl
~~oe~~
oedas
oel
~~<u>sf</u>~~ <u>e</u> ~~<u>py</u>~~
01
02
<u>04</u>
05
06
07
08
<u>09</u>
10
11
12
13
~~14~~
17
18
Figure 8: The highest throughput of each backend (number of megabytes evaluated per second) for
the weak convective term einsum expression. Left: residual mode evaluations _|r|/T_ <sup>¯ww</sup>, right: matrix mode evaluations _|M_ _|/T_ <sup>¯ww</sup> . The backends are indicated by markers, the einsum contraction
paths by color. The cell counts ( _x_ axis) are grouped by the approximation orders.
5: 1024
4: 2048
1024
8192
3: 4096
2048
1024
65536
32768
16384
2: 8192
4096
2048
1024
1048576
524288
262144
131072
65536
1: 32768
16384
8192
4096
2048
1024
5: 1024
4: 2048
1024
8192
3: 4096
2048
1024
65536
32768
16384
2: 8192
4096
2048
1024
1048576
524288
262144
131072
65536
1: 32768
16384
8192
4096
2048
1024
<u>das</u>
<u>jx</u>
<u>jxv</u>
<u>np</u>
<u>npl</u>
<u>oe</u>
<u>oedas</u>
<u>oel</u>
<u>sfepy</u>
<u>das</u>
<u>jx</u>
<u>jxv</u>
<u>np</u>
<u>npl</u>
<u>oe</u>
<u>oedas</u>
<u>oel</u>
<u>sfepy</u>
<u>-</u>
<u>01,02</u> <u><mark>,12</mark></u> <u>,03,12,01</u>
<u>03,34,</u> <u><mark>34</mark></u> <u>,23,02,01</u>
<u>24,</u> <u><mark>34,</mark></u> <u>04,13,12,01</u>
<u><mark>34</mark></u> <u>,05,23,23,02,01</u>
<u><mark>34</mark></u> <u>,34,34,01,12,01</u>
<u>34,34,34,03,02,01</u>
<u>34,34,34,23,01,01</u>
<u>34,34,34,23,02,01</u>
<u>56,35,34,23,02,01</u>
~~-~~
~~01~~
~~02~~
<u>03</u>
~~<u>04</u>~~
<u>05</u>
<u>07</u>
<u>09</u>
<u>10</u>
<u>11</u>
<u>12</u>
<u>14</u>
<u>15</u>
<u>16</u>
<u>18</u>
0.5 1 2 5
_T_ ¯ <sup>ww</sup> _/_ ¯ _Tr_ <sup>_ww_</sup>
0.05 0.1 0.2 0.5 1 2 5
_T_ ¯ <sup>ww</sup> _/_ ¯ _Tr_ <sup>_ww_</sup>
5: 1024
4: 2048
1024
8192
3: 4096
2048
1024
65536
32768
16384
2: 8192
4096
2048
1024
1048576
524288
262144
131072
65536
1: 32768
16384
8192
4096
2048
1024
5: 1024
4: 2048
1024
8192
3: 4096
2048
1024
65536
32768
16384
2: 8192
4096
2048
1024
1048576
524288
262144
131072
65536
1: 32768
16384
8192
4096
2048
1024
<u>das</u>
<u>jx</u>
<u>jxv</u>
<u>np</u>
<u>npl</u>
<u>oe</u>
<u>oedas</u>
<u>oel</u>
<u>sfepy</u>
<u>das</u>
<u>jx</u>
<u>jxv</u>
<u>np</u>
<u>npl</u>
<u>oe</u>
<u>oedas</u>
<u>oel</u>
<u>sfepy</u>
<u>-</u>
<u>01,02,12,03,12,01</u>
<u>03,34,34,23,02,01</u>
<u>24,34,04,13,12,01</u>
<u>34,05,23,23,02,01</u>
<u>34,34,34,01,12,01</u>
<u>34,34,34,03,02,01</u>
<u>34,34,34,23,01,01</u>
<u>34,34,34,23,02,01</u>
<u>56,35,34,23,02,01</u>
~~-~~
~~01~~
~~02~~
~~03~~
~~<u>04</u>~~
<u>05</u>
<u>07</u>
<u>09</u>
<u>10</u>
<u>11</u>
<u>12</u>
<u>14</u>
<u>15</u>
<u>16</u>
<u>18</u>
0.2 0.5 1 2 5 10 20
_M_ <sup>max</sup> _/Mr_ <sup>max</sup>
1 2 5
_M_ <sup>max</sup> _/Mr_ <sup>max</sup>
Figure 9: Relative elapsed time and memory requirements of the weak convective term einsum
expression w.r.t. the reference implementation. Left: residual mode, right: matrix mode, top:
_T_ ¯ <sup>ww</sup> _/T_ ¯ _r_ <sup>ww</sup>
_r_ <sup>ww</sup>, bottom: _M_ <sup>max</sup> _/Mr_ <sup>max</sup>
_T_ ¯ <sup>ww</sup> _/T_ ¯ _r_ <sup>ww</sup>, bottom: _M_ <sup>max</sup> _/Mr_ <sup>max</sup> . The backends are indicated by markers, the einsum contraction
paths by color. The cell counts ( _y_ axis) are grouped by the approximation orders.
350
300
250
200
150
100
50
0
<u>-</u>
01,02,02,01
<u>24,23,02,01</u>
34,03,02,01
34,23,01,01
<u>34,23,02,01</u>
800
600
400
200
0
01,02,01,01
<u>01,</u> ~~13,~~ 01,01
~~13,03,01,01~~
24,01,02,01
24,02,02,0 ~~1~~
24,12,02,01
das
jx
<u>jxv</u>
np
npl
<u>oe</u>
oe <mark>da</mark> s
<mark>o</mark> el
~~sfepy~~
~~das~~
jx
jxv
<mark>n</mark> p
~~np~~ ~~<mark>l</mark>~~
oe
oedas
oel
~~<u>sf</u>~~ <u>e</u> ~~<u>py</u>~~
Figure 10: The highest throughput of each backend (number of megabytes evaluated per second)
for the vector dot product einsum expression. Left: residual mode evaluations _|r|/T_ <sup>¯ww</sup>, right: matrix mode evaluations _|M_ _|/T_ <sup>¯ww</sup> . The backends are indicated by markers, the einsum contraction
paths by color. The cell counts ( _x_ axis) are grouped by the approximation orders.
5: 1024
4: 2048
1024
8192
3: 4096
2048
1024
65536
32768
16384
2: 8192
4096
2048
1024
1048576
524288
262144
131072
65536
1: 32768
16384
8192
4096
2048
1024
5: 1024
4: 2048
1024
8192
3: 4096
2048
1024
65536
32768
16384
2: 8192
4096
2048
1024
1048576
524288
262144
131072
65536
1: 32768
16384
8192
4096
2048
1024
<u>das</u>
<u>jx</u>
<u>jxv</u>
<u>np</u>
<u>npl</u>
<u>oe</u>
<u>oedas</u>
<u>oel</u>
<u>sfepy</u>
1 2 5 10 20
_M_ <sup>max</sup> _/Mr_ <sup>max</sup>
<u>das</u>
<u>jx</u>
<u>jxv</u>
<u>np</u>
<u>npl</u>
<u>oe</u>
<u>oedas</u>
<u>oel</u>
<u>sfepy</u>
1 2 5
_M_ <sup>max</sup> _/Mr_ <sup>max</sup>
<u>das</u>
<u>jx</u>
<u>jxv</u>
<u>np</u>
<u>npl</u>
<u>oe</u>
<u>oedas</u>
<u>oel</u>
<u>sfepy</u>
<u>das</u>
<u>jx</u>
<u>jxv</u>
<u>np</u>
<u>npl</u>
<u>oe</u>
<u>oedas</u>
<u>oel</u>
<u>sfepy</u>
<u>-</u>
<u>01,02,02,01</u>
<u>01,12,12,01</u>
<u>03,01,01,01</u>
<u>24,01,01,01</u>
<u>24,23,02,01</u>
<u>34,01,12,01</u>
<u>34,03,02,01</u>
<u>34,23,01,01</u>
<u>34,23,02,01</u>
<u>-</u>
<u>01,02,01,01</u>
<u>01,13,01,01</u>
<u>13,03,01,01</u>
<u>24,</u> <u><mark>01,0</mark></u> <u>2,01</u>
<u><mark>24,</mark></u> <u>02,02,01</u>
<u><mark>24,</mark></u> <u>12,02,01</u>
0.2 0.5 1 2 5
_T_ ¯ <sup>ww</sup> _/_ ¯ _Tr_ <sup>_ww_</sup>
0.2 0.5 1 2 5
_T_ ¯ <sup>ww</sup> _/_ ¯ _Tr_ <sup>_ww_</sup>
0.02 0.05 0.1 0.2 0.5 1 2 5
_T_ ¯ <sup>ww</sup> _/_ ¯ _Tr_ <sup>_ww_</sup>
5: 1024
4: 2048
1024
8192
3: 4096
2048
1024
65536
32768
16384
2: 8192
4096
2048
1024
1048576
524288
262144
131072
65536
1: 32768
16384
8192
4096
2048
1024
5: 1024
4: 2048
1024
8192
3: 4096
2048
1024
65536
32768
16384
2: 8192
4096
2048
1024
1048576
524288
262144
131072
65536
1: 32768
16384
8192
4096
2048
1024
<u>-</u>
<u>01,02,01,01</u>
<u>01,13,01,01</u>
<u>13,03,01,01</u>
<u>24,01,02,01</u>
<u>24,02,02,01</u>
<u>24,12,02,01</u>
<u>-</u>
<u>01,02,02,01</u>
<u>01,12,12,01</u>
<u>03,01,01,01</u>
<u>24,01,01,01</u>
<u>24,23,02,01</u>
<u>34,01,12,01</u>
<u>34,03,02,01</u>
<u>34,23,01,01</u>
<u>34,23,02,01</u>
Figure 11: Relative elapsed time and memory requirements of the vector dot product einsum
expression w.r.t. the reference implementation. Left: residual mode, right: matrix mode, top:
_T_ ¯ <sup>ww</sup> _/T_ ¯ _r_ <sup>ww</sup>
_r_ <sup>ww</sup>, bottom: _M_ <sup>max</sup> _/Mr_ <sup>max</sup>
_T_ ¯ <sup>ww</sup> _/T_ ¯ _r_ <sup>ww</sup>, bottom: _M_ <sup>max</sup> _/Mr_ <sup>max</sup> . The backends are indicated by markers, the einsum contraction
paths by color. The cell counts ( _y_ axis) are grouped by the approximation orders.
200
175
150
125
100
75
50
25
0
<u>-</u>
01,23,13,12,01
~~03,23,23,02,01~~
45,04,23,02,01
45,04,23,12,01
<u>45,34,03,02,01</u>
45,34,23,01,01
~~45,34,23,02,01~~
800
600
400
200
0
01,01,02,01,01
01,01,13,02,01
~~02,02,01,02,01~~
02,13,23,02,01
03,02,02,02,01
03,14,23,01,01
03,14,23,02,01
04,04,12,02,01
~~14,23,13,02,01~~
23,34,01,02,01
23,34,01,20,01
35,24,03,12,01
35,34,23,02,01
<u>das</u>
<u>jx</u>
jxv
~~np~~
npl
oe
<u><mark>o</mark></u> <u>edas</u>
oel
~~<u>sf</u>~~ <u>e</u> ~~<u>py</u>~~
das
<mark>jx</mark>
jxv
np
~~npl~~
oe
oedas
oel
~~<u>sf</u>~~ <u>e</u> ~~<u>py</u>~~
Figure 12: The highest throughput of each backend (number of megabytes evaluated per second)
for the weighted vector dot product einsum expression. Left: residual mode evaluations _|r|/T_ <sup>¯ww</sup>,
right: matrix mode evaluations _|M_ _|/T_ <sup>¯ww</sup> . The backends are indicated by markers, the einsum
contraction paths by color. The cell counts ( _x_ axis) are grouped by the approximation orders.
5: 1024
4: 2048
1024
8192
3: 4096
2048
1024
65536
32768
16384
2: 8192
4096
2048
1024
1048576
524288
262144
131072
65536
1: 32768
16384
8192
4096
2048
1024
5: 1024
4: 2048
1024
8192
3: 4096
2048
1024
65536
32768
16384
2: 8192
4096
2048
1024
1048576
524288
262144
131072
65536
1: 32768
16384
8192
4096
2048
1024
5: 1024
4: 2048
1024
8192
3: 4096
2048
1024
65536
32768
16384
2: 8192
4096
2048
1024
1048576
524288
262144
131072
65536
1: 32768
16384
8192
4096
2048
1024
5: 1024
4: 2048
1024
8192
3: 4096
2048
1024
65536
32768
16384
2: 8192
4096
2048
1024
1048576
524288
262144
131072
65536
1: 32768
16384
8192
4096
2048
1024
<u>das</u>
<u>jx</u>
<u>jxv</u>
<u>np</u>
<u>npl</u>
<u>oe</u>
<u>oedas</u>
<u>oel</u>
<u>sfepy</u>
<u>das</u>
<u>jx</u>
<u>jxv</u>
<u>np</u>
<u>npl</u>
<u>oe</u>
<u>oedas</u>
<u>oel</u>
<u>sfepy</u>
<u>das</u>
<u>jx</u>
<u>jxv</u>
<u>np</u>
<u>npl</u>
<u>oe</u>
<u>oedas</u>
<u>oel</u>
<u>sfepy</u>
~~<u>-</u>~~
<u>03,02,12,12,01</u>
<u>03,14,12,12,01</u>
<u>03,23,23,02,01</u>
<u>04,01,12,02,01</u>
<u>45,04,23,02,01</u>
<u>45,04,23,12,01</u>
<u>45,34,01,12,01</u>
<u>45,34,03,02,01</u>
<u>45,34,23,01,01</u>
<u>45,34,23,02,01</u>
0.5 1 2 5
_T_ ¯ <sup>ww</sup> _/_ ¯ _Tr_ <sup>_ww_</sup>
~~<u>-</u>~~
<u>03,02,12,12,01</u>
<u>03,14,12,12,01</u>
<u>03,23,23,02,01</u>
<u>04,01,12,02,01</u>
<u>45,04,23,02,01</u>
<u>45,04,23,12,01</u>
<u>45,34,01,12,01</u>
<u>45,34,03,02,01</u>
<u>45,34,23,01,01</u>
<u>45,34,23,02,01</u>
<u>das</u>
<u>jx</u>
<u>jxv</u>
<u>np</u>
<u>npl</u>
<u>oe</u>
<u>oedas</u>
<u>oel</u>
<u>sfepy</u>
<u>-</u>
~~<u>01,0</u>~~ ~~<u><mark>1,0</mark></u>~~ ~~<u>2,01,01</u>~~
<u>01,0</u> <u><mark>1,</mark></u> <u>13,02,01</u>
<u>02,0</u> <u><mark>2,0</mark></u> <u>1,02,01</u>
<u>02,1</u> <u><mark>3,2</mark></u> <u>3,02,01</u>
<u>03,</u> <u><mark>02</mark></u> <u>,02,02,01</u>
<u>0</u> <u><mark>3,1</mark></u> <u>4,23,01,01</u>
<u>03,14,23,02,01</u>
<u>14,23,13,02,01</u>
<u>23,34,01,20,01</u>
<u>35,24,03,12,01</u>
<u>35,34,23,02,01</u>
0.1 0.2 0.5 1 2 5
_T_ ¯ <sup>ww</sup> _/_ ¯ _Tr_ <sup>_ww_</sup>
~~-~~
~~<u>01,01,02,01,01</u>~~
<u>01,01,13,02,01</u>
<u>02,02,01,02,01</u>
<u>02,13,23,02,01</u>
<u>03,02,02,02,01</u>
<u>03,14,23,01,01</u>
<u>03,14,23,02,01</u>
<u>14,23,13,02,01</u>
<u>23,34,01,20,01</u>
<u>35,24,03,12,01</u>
<u>35,34,23,02,01</u>
0.5 1 2 5 10 20
_M_ <sup>max</sup> _/Mr_ <sup>max</sup>
1 2 5
_M_ <sup>max</sup> _/Mr_ <sup>max</sup>
Figure 13: Relative elapsed time and memory requirements of the weighted vector dot product
einsum expression w.r.t. the reference implementation. Left: residual mode, right: matrix mode,
top: _T_ ¯ <sup>ww</sup> _/_ ¯ _Tr_ <sup>ww</sup>, bottom: _M_ <sup>max</sup> _/Mr_ <sup>max</sup> . The backends are indicated by markers, the einsum
contraction paths by color. The cell counts ( _y_ axis) are grouped by the approximation orders.
The relatively low performance in this case, especially in the residual mode, was caused by not
exploiting the sparsity of the `Psg` tensor, see the last paragraph of Section 5.3.3.
### 7 Conclusion
In this paper, we proposed and described a simple transpiler from generalized einsum-like expressions, suitable for describing multi-linear finite element weak forms, to regular tensor contraction
expressions. We applied the transpiler and presented a very simple implementation of several
standard weak forms. The transpiler supports several Python libraries as backends implementing
the einsum function which allowed us to perform a large numerical study comparing the backends
(NumPy, opt ~~e~~ insum, Dask and JAX) mutually and with the reference implementations of the
weak forms in the finite element SfePy.
An indispensable feature of the backends was their ability to optimize the tensor contraction
paths. Our study confirmed that using contraction paths optimizations is crucial for good performance. However, the theoretical speedup, as e.g. calculated by opt ~~e~~ insum, was found to be not
a good metric for estimating performance when applied to simple einsum expressions occurring
in the FE calculations - here the additional memory consumed by temporary storage was much
more important. This was also one of the motivations for realizing the presented numerical study.
Concerning the study results, we first studied the influence of the memory layout of the expression operands on the evaluation performance, to establish the position of the default, SfePy
compatible layout, with other possible layouts. We found that marked improvements could be
achieved by using alternative memory layouts.
Then five selected weak forms were evaluated for various mesh sizes and FE approximation
orders using the default layout. The evaluations were repeated several times for each parameter
set and statistics such as means without the worst case were computed.
Significant differences in performance were found between the residual (operator/matrix application to a DOF vector without the global sparse matrix assembly) and matrix (calculating
local element matrices) evaluation modes as well as among the various weak forms - no single
backend/contraction path was the best in all the cases.
Overall, JAX based backends were the fastest, but very memory demanding. The JIT compilation warm-up was disregarded by omitting the worst case repetition in calculating the elapsed
time mean. Without this, the JAX backends were much slower for small problems. GPU/TPU
performance was not considered in this study.
A good compromise between speed and memory overhead w.r.t. the reference implementation
was achieved by using the opt einsum or NumPy backends. Especially their cell-loop based variants
had very low memory requirements and offered good performance for FE approximation orders
greater or equal to three in the matrix evaluation mode. Also the Dask-based backends were
suitable for large problems, where the automatic chunking of operands decreased the memory
consumption. Dask allows out-of-core calculations with data not fitting into RAM, but this feature
was not used in this study.
In many cases the einsum expression based evaluations were faster than the reference implementation (a hand-crafted C code, called from Python via SfePy’s lightweight Cython wrappers)
which is in our opinion a good result considering the simplicity of the transpiler implementation
and especially of the weak form definitions. For forms with low numerical intensity (e.g. the weak
Laplacian in matrix mode) or unused sparsity (the linear elasticity term), going beyond einsum
might be required for further speed-up. A very preliminary result included in the memory layouts
study indicates that using Numba might be promising.
The transpiler and einsum expression based weak form implementations are available in SfePy
from version 2021.1, allowing a rapid prototyping of multi-physical finite element models and
subsequent calculations in various fields such as biomechanics [30] or solid state physics [22]. All
data used in preparation of this paper are available online [8].
500
400
300
200
100
0
<u>01,01,0123</u>
01,01,13,02,01
03,14,23,012
03,14,23,02,01
~~03,34,13,12,01~~
04,23,13,12,01
12,23,13,02,01
100
80
60
40
20
0
03,24,24,23,12,01
~~46,45,04,23,12,01~~
46,45,34,01,12,01
46,45,34,03,02,01
<u>46,45,34,03,12,01</u>
46,45,34,23,02,01
46,45,34,23,12,01
das
~~jx~~
jxv
np
npl
<u>oe</u>
<mark>o</mark> e <mark>da</mark> s
oel
~~<u>sf</u>~~ <u>e</u> ~~<u>py</u>~~
das
~~jx~~
jxv
np
<u>npl</u>
oe
<mark>o</mark> e <mark>da</mark> s
<u>oel</u>
~~<u>sfepy</u>~~
Figure 14: The highest throughput of each backend (number of megabytes evaluated per second)
for the weak linear elasticity term einsum expression. Left: residual mode evaluations _|r|/T_ <sup>¯ww</sup>,
right: matrix mode evaluations _|M_ _|/T_ <sup>¯ww</sup> . The backends are indicated by markers, the einsum
contraction paths by color. The cell counts ( _x_ axis) are grouped by the approximation orders.
5: 1024
4: 2048
1024
8192
3: 4096
2048
1024
65536
32768
16384
2: 8192
4096
2048
1024
1048576
524288
262144
131072
65536
1: 32768
16384
8192
4096
2048
1024
5: 1024
4: 2048
1024
8192
3: 4096
2048
1024
65536
32768
16384
2: 8192
4096
2048
1024
1048576
524288
262144
131072
65536
1: 32768
16384
8192
4096
2048
1024
<u>das</u>
<u>jx</u>
<u>jxv</u>
<u>np</u>
<u>npl</u>
<u>oe</u>
<u>oedas</u>
<u>oel</u>
<u>sfepy</u>
<u>-</u>
<u>01,24,24,13,</u> <u><mark>02,</mark></u> <u>01</u>
<u>03,15,24,12</u> <u><mark>,12</mark></u> <u>,01</u>
<u>03,24,24,</u> <u><mark>23</mark></u> <u>,12,01</u>
<u>46,45,04</u> <u><mark>,23</mark></u> <u>,12,01</u>
<u>46,</u> <u><mark>45,</mark></u> <u>34,</u> <u><mark>01</mark></u> <u>,12,01</u>
<u><mark>46</mark></u> <u>,4</u> <u><mark>5,34,0</mark></u> <u>3,02,01</u>
<u><mark>46</mark></u> <u>,45,34,03,12,01</u>
<u>46,45,34,23,02,01</u>
<u>46,45,34,23,12,01</u>
<u>-</u>
<u>01,01,13,02,01</u>
<u>03,14,23,012</u>
<u>03,14,23,02,01</u>
<u>03,34,13,12,01</u>
<u>04,23,13,1</u> <u><mark>2,0</mark></u> <u>1</u>
<u>12,23,</u> <u><mark>13</mark></u> <u>,0</u> <u><mark>2,0</mark></u> <u>1</u>
0.5 1 2 5
_T_ ¯ <sup>ww</sup> _/_ ¯ _Tr_ <sup>_ww_</sup>
<u>-</u>
<u>01,01,13,02,01</u>
<u>03,14,23,012</u>
<u>03,14,23,02,01</u>
<u>03,34,13,12,01</u>
<u>04,</u> <u><mark>23,1</mark></u> <u>3,12,01</u>
<u>12,</u> <u><mark>23,1</mark></u> <u>3,02,01</u>
1 2 5
_T_ ¯ <sup>ww</sup> _/_ ¯ _Tr_ <sup>_ww_</sup>
5: 1024
4: 2048
1024
8192
3: 4096
2048
1024
65536
32768
16384
2: 8192
4096
2048
1024
1048576
524288
262144
131072
65536
1: 32768
16384
8192
4096
2048
1024
5: 1024
4: 2048
1024
8192
3: 4096
2048
1024
65536
32768
16384
2: 8192
4096
2048
1024
1048576
524288
262144
131072
65536
1: 32768
16384
8192
4096
2048
1024
<u>das</u>
<u>jx</u>
<u>jxv</u>
<u>np</u>
<u>npl</u>
<u>oe</u>
<u>oedas</u>
<u>oel</u>
<u>sfepy</u>
<u>das</u>
<u>jx</u>
<u>jxv</u>
<u>np</u>
<u>npl</u>
<u>oe</u>
<u>oedas</u>
<u>oel</u>
<u>sfepy</u>
<u>das</u>
<u>jx</u>
<u>jxv</u>
<u>np</u>
<u>npl</u>
<u>oe</u>
<u>oedas</u>
<u>oel</u>
<u>sfepy</u>
<u>-</u>
<u>01,24,24,13,02,01</u>
<u>03,15,24,12,12,01</u>
<u>03,24,24,23,12,01</u>
<u>46,45,04,23,12,01</u>
<u>46,45,34,01,12,01</u>
<u>46,45,34,03,02,01</u>
<u>46,45,34,03,12,01</u>
<u>46,45,34,23,02,01</u>
<u>46,45,34,23,12,01</u>
0.1 0.2 0.5 1 2 5 10 20
_M_ <sup>max</sup> _/Mr_ <sup>max</sup>
1 2 5 10
_M_ <sup>max</sup> _/Mr_ <sup>max</sup>
Figure 15: Relative elapsed time and memory requirements of the weak linear elasticity term
einsum expression w.r.t. the reference implementation. Left: residual mode, right: matrix mode,
top: _T_ ¯ <sup>ww</sup> _/_ ¯ _Tr_ <sup>ww</sup>, bottom: _M_ <sup>max</sup> _/Mr_ <sup>max</sup> . The backends are indicated by markers, the einsum
contraction paths by color. The cell counts ( _y_ axis) are grouped by the approximation orders.
### Acknowledgements
The work was supported from European Regional Development Fund - Project “Application of
Modern Technologies in Medicine and Industry” (No. CZ.02.1.01/0.0/0.0/17 ~~0~~ 48/0007280).
### A Performance of Selected Weak Forms Contractions with Threads
This appendix complements Section 6.5 by using the same setup but the single-threaded execution
was not enforced — default settings of each backend library were in effect. Two additional backends
- dat and oedat - were included, i.e. Dask based backends with multiple threads enabled.
A parametric study run using soops [9] lead to 8326 finished simulations <sup>7</sup>, each evaluating
a single weak form using a single backend/optimization combination several times according to
the repeat parameter for various mesh sizes and function approximation orders, see Tab. 5. The
default `cqgvd0` layout of the weak form einsum expression operands and result arrays was used.
The overall results are summarized in Tab. 12 for the residual mode and in Tab. 13 for the
matrix mode evaluations. The evaluation throughput of the einsum backends applied to the
evaluation of five selected einsum expression is shown in Figs. 16–20.
The performance of most backends was similar to the single-threaded case with the exception
of the JAX-based backends jx and jxv. Those backends had a significantly increased performance
for large problems, both in terms of the mesh size (the number of cells) and the FE approximation order, most visible in the matrix mode evaluations. The new backends dat and oedat also
performed very well for the largest problems considered, often replacing jx in Tab. 12 (Laplacian,
NS convective and linear elasticity weak forms) and Tab. 13 (Laplacian, weighted vector dot and
linear elasticity weak forms). Their performance, when applied to the same contraction paths,
was very similar.
By comparing with data in Section 6.5, we can conclude that enabling threads resulted in
about halved times for the largest problems considered.
300
250
200
150
100
50
0
23,02,01
23,12,01
600
500
400
300
200
100
0
~~-~~
01,01
02,01
<u>12,01</u>
~~das~~
dat
jx
<u>jxv</u>
np
npl
oe
~~oedas~~
oeda <mark>t</mark>
- <mark>el</mark>
~~<mark>s</mark>~~ ~~fepy~~
<u>das</u>
dat
jx
<u>jxv</u>
<u>np</u>
npl
oe
~~oeda~~ ~~<mark>s</mark>~~
- <mark>eda</mark> t
<mark>o</mark> el
~~<u>s</u>~~ <u>f</u> ~~<u>epy</u>~~
Figure 16: The highest throughput of each backend (number of megabytes evaluated per second)
for the weak Laplacian einsum expression with allowed threads. Left: residual mode evaluations
_|r|/T_ <sup>¯ww</sup>, right: matrix mode evaluations _|M_ _|/T_ <sup>¯ww</sup> . The backends are indicated by markers, the
einsum contraction paths by color. The cell counts ( _x_ axis) are grouped by the approximation
orders.
7This includes the reference implementation simulations shown in Fig. 2. 31 backend/optimization pairs, 27
mesh size/order combinations, 5 terms and 2 evaluation modes, 8370 in total, 44 failed due to insufficient memory.
#cells order Laplacian v. dot weighted v. dot NS convective elasticity
1,024 1 0 _._ 01 (oe 1.0) 0 _._ 01 (oe 1.0) 0 _._ 01 (jx 1.0) 0 _._ 01 (jx 1.0) 0 _._ 02 (jx 1.2)
2 0 _._ 01 (np 0.9) 0 _._ 01 (np 0.9) 0 _._ 02 (jx 1.0) 0 _._ 02 (jx 0.9) 0 _._ 04 (jx 1.6)
3 0 _._ 02 (oe 0.6) 0 _._ 02 (jx 0.4) 0 _._ 02 (jx 0.6) 0 _._ 04 (jx 0.6) 0 _._ 09 (jx 1.3)
4 0 _._ 05 (dat 0.3) 0 _._ 02 (jx 0.2) 0 _._ 03 (jx 0.3) 0 _._ 11 (dat 0.5) 0 _._ 20 (dat 0.8)
5 0 _._ 12 (oedat 0.3) 0 _._ 03 (jx 0.1) 0 _._ 04 (jx 0.2) 0 _._ 19 (dat 0.3) 0 _._ 25 (oedat 0.4)
2,048 1 0 _._ 01 (oe 1.0) 0 _._ 01 (np 1.0) 0 _._ 01 (jx 1.1) 0 _._ 02 (jx 1.1) 0 _._ 02 (jx 1.4)
2 0 _._ 02 (oe 0.8) 0 _._ 01 (jx 0.7) 0 _._ 02 (jx 0.8) 0 _._ 03 (jx 0.8) 0 _._ 06 (jx 1.7)
3 0 _._ 04 (oe 0.5) 0 _._ 02 (jx 0.3) 0 _._ 03 (jx 0.4) 0 _._ 07 (jx 0.5) 0 _._ 17 (jx 1.2)
4 0 _._ 06 (dat 0.2) 0 _._ 03 (jx 0.1) 0 _._ 04 (jx 0.2) 0 _._ 15 (dat 0.3) 0 _._ 22 (dat 0.5)
4,096 1 0 _._ 01 (oe 1.0) 0 _._ 01 (np 1.0) 0 _._ 02 (oe 1.2) 0 _._ 02 (jx 1.2) 0 _._ 03 (jx 1.5)
2 0 _._ 02 (oe 0.8) 0 _._ 02 (jx 0.6) 0 _._ 02 (jx 0.7) 0 _._ 04 (jx 0.7) 0 _._ 09 (jx 1.6)
3 0 _._ 05 (dat 0.3) 0 _._ 03 (jx 0.2) 0 _._ 04 (jx 0.4) 0 _._ 12 (jx 0.5) 0 _._ 25 (dat 0.9)
4 0 _._ 09 (oedat 0.2) 0 _._ 04 (jx 0.1) 0 _._ 08 (jx 0.2) 0 _._ 19 (dat 0.2) 0 _._ 32 (oedat 0.3)
8,192 1 0 _._ 01 (np 1.0) 0 _._ 02 (jx 1.0) 0 _._ 02 (jx 1.0) 0 _._ 02 (jx 1.0) 0 _._ 03 (jx 1.3)
2 0 _._ 04 (oe 0.7) 0 _._ 02 (jx 0.5) 0 _._ 03 (jx 0.6) 0 _._ 06 (jx 0.6) 0 _._ 17 (jx 1.5)
3 0 _._ 06 (dat 0.2) 0 _._ 04 (jx 0.2) 0 _._ 08 (jx 0.3) 0 _._ 16 (dat 0.3) 0 _._ 28 (dat 0.5)
16,384 1 0 _._ 02 (oe 1.0) 0 _._ 02 (jx 0.9) 0 _._ 03 (jx 0.9) 0 _._ 03 (jx 1.0) 0 _._ 06 (jx 1.5)
2 0 _._ 04 (dat 0.5) 0 _._ 03 (jx 0.4) 0 _._ 06 (jx 0.6) 0 _._ 10 (jx 0.5) 0 _._ 27 (dat 1.3)
3 0 _._ 10 (dat 0.2) 0 _._ 06 (jx 0.1) 0 _._ 12 (jx 0.3) 0 _._ 23 (dat 0.2) 0 _._ 42 (oedat 0.4)
32,768 1 0 _._ 03 (oe 1.0) 0 _._ 02 (jx 0.8) 0 _._ 04 (jx 0.9) 0 _._ 04 (jx 0.7) 0 _._ 10 (jx 1.5)
2 0 _._ 06 (dat 0.4) 0 _._ 05 (jx 0.3) 0 _._ 10 (jx 0.5) 0 _._ 15 (dat 0.4) 0 _._ 33 (dat 0.8)
65,536 1 0 _._ 04 (oe 0.9) 0 _._ 03 (jx 0.6) 0 _._ 07 (jx 0.9) 0 _._ 07 (jx 0.7) 0 _._ 18 (jx 1.4)
2 0 _._ 10 (dat 0.3) 0 _._ 09 (jx 0.3) 0 _._ 19 (jx 0.5) 0 _._ 22 (dat 0.3) 0 _._ 50 (oedat 0.6)
131,072 1 0 _._ 07 (dat 0.9) 0 _._ 05 (jx 0.6) 0 _._ 11 (jx 0.8) 0 _._ 12 (jx 0.6) 0 _._ 33 (jx 1.4)
262,144 1 0 _._ 08 (dat 0.6) 0 _._ 10 (jx 0.6) 0 _._ 22 (jx 0.8) 0 _._ 24 (jx 0.6) 0 _._ 57 (dat 1.2)
524,288 1 0 _._ 15 (oedat 0.5) 0 _._ 18 (jx 0.6) 0 _._ 42 (jx 0.8) 0 _._ 38 (dat 0.5) 0 _._ 87 (dat 0.9)
1,048,576 1 0 _._ 23 (dat 0.4) 0 _._ 35 (jx 0.6) 0 _._ 81 (jx 0.8) 0 _._ 60 (dat 0.4) 1 _._ 68 (oedat 0.9)
Table 12: Summary results of residual evaluation mode, no single-thread limitation. For each weak
form, mesh size and FE approximation order, the shortest elapsed time mean without the worst
case _T_ <sup>¯ww</sup> [s] across all backends is given, as well as the corresponding backend and _T_ <sup>¯ww</sup> _/T_ <sup>¯</sup> _r_ <sup>ww</sup> (in
parentheses).
350
300
250
200
150
100
50
0
01,02,12,03,12,01
~~24,34,04,13,12,01~~
24,34,24,23,02,01
34,05,23,23,02,01
~~34,34,34,03,02,01~~
34,34,34,23,02,01
56,35,34,23,02,01
1000
800
600
400
200
0
das
<u>dat</u>
jx
jxv
<u>np</u>
npl
oe
<u>oedas</u>
oeda <mark>t</mark>
<mark>oel</mark>
~~sfepy~~
das
dat
~~jx~~
jxv
np
n <mark>pl</mark>
~~<mark>o</mark>~~ ~~e~~
oedas
oedat
oel
~~<u>s</u>~~ <u>f</u> ~~<u>ep</u>~~ <u>y</u>
01
02
03
04
~~05~~
06
07
08
09
<u>10</u>
<u>11</u>
12
13
14
15
~~16~~
17
18
Figure 17: The highest throughput of each backend (number of megabytes evaluated per second)
for the weak convective term einsum expression with allowed threads. Left: residual mode evaluations _|r|/T_ <sup>¯ww</sup>, right: matrix mode evaluations _|M_ _|/T_ <sup>¯ww</sup> . The backends are indicated by markers,
the einsum contraction paths by color. The cell counts ( _x_ axis) are grouped by the approximation
orders.
#cells order Laplacian v. dot weighted v. dot NS convective elasticity
1,024 1 0 _._ 01 (jx 1.0) 0 _._ 01 (jx 0.9) 0 _._ 02 (oe 1.0) 0 _._ 02 (jx 0.8) 0 _._ 03 (jx 1.6)
2 0 _._ 04 (jx 1.0) 0 _._ 06 (jx 0.3) 0 _._ 07 (jx 0.4) 0 _._ 08 (jx 0.2) 0 _._ 27 (jx 1.1)
3 0 _._ 17 (jx 0.4) 0 _._ 30 (jxv 0.0) 0 _._ 30 (jx 0.0) 0 _._ 38 (jx 0.0) 0 _._ 97 (jx 0.2)
4 0 _._ 51 (jx 0.1) 0 _._ 88 (jxv 0.0) 1 _._ 09 (jx 0.0) 1 _._ 33 (jxv 0.0) 3 _._ 71 (jx 0.1)
5 1 _._ 33 (jx 0.0) 2 _._ 58 (jxv 0.0) 3 _._ 50 (jx 0.0) 3 _._ 92 (jxv 0.0) 11 _._ 56 (jx 0.1)
2,048 1 0 _._ 02 (jx 1.1) 0 _._ 02 (jx 0.9) 0 _._ 02 (oe 0.9) 0 _._ 03 (jx 0.7) 0 _._ 05 (jx 1.7)
2 0 _._ 06 (jx 0.9) 0 _._ 10 (jx 0.3) 0 _._ 11 (jx 0.3) 0 _._ 14 (jx 0.2) 0 _._ 50 (jx 1.0)
3 0 _._ 33 (jx 0.4) 0 _._ 51 (jxv 0.0) 0 _._ 56 (jx 0.0) 0 _._ 72 (jx 0.0) 1 _._ 92 (jx 0.2)
4 1 _._ 01 (jx 0.1) 1 _._ 71 (jxv 0.0) 2 _._ 12 (jx 0.0) 2 _._ 46 (jxv 0.0) 7 _._ 28 (jx 0.1)
4,096 1 0 _._ 02 (jx 1.2) 0 _._ 03 (jx 0.9) 0 _._ 03 (jx 0.8) 0 _._ 03 (jx 0.5) 0 _._ 09 (jx 1.8)
2 0 _._ 11 (jx 0.8) 0 _._ 18 (jx 0.3) 0 _._ 21 (jx 0.3) 0 _._ 25 (jx 0.2) 0 _._ 99 (jx 1.0)
3 0 _._ 66 (jx 0.4) 1 _._ 00 (jxv 0.0) 1 _._ 12 (jx 0.0) 1 _._ 37 (jxv 0.0) 3 _._ 80 (jx 0.2)
4 1 _._ 95 (jx 0.1) 3 _._ 30 (jxv 0.0) 4 _._ 15 (jx 0.0) 7 _._ 09 (oedat 0.0) 44 _._ 14 (oedat 0.3)
8,192 1 0 _._ 03 (jx 1.1) 0 _._ 05 (jx 0.9) 0 _._ 05 (oe 0.9) 0 _._ 06 (jx 0.5) 0 _._ 15 (jx 1.9)
2 0 _._ 20 (jx 0.8) 0 _._ 34 (jx 0.3) 0 _._ 39 (jx 0.3) 0 _._ 48 (jx 0.2) 1 _._ 93 (jx 1.0)
3 1 _._ 22 (jx 0.4) 1 _._ 84 (jxv 0.0) 2 _._ 10 (jx 0.0) 2 _._ 60 (jxv 0.0) 7 _._ 45 (jx 0.2)
16,384 1 0 _._ 04 (jx 1.1) 0 _._ 08 (jx 0.8) 0 _._ 10 (oe 0.9) 0 _._ 11 (jx 0.5) 0 _._ 30 (jx 1.9)
2 0 _._ 40 (jx 0.8) 0 _._ 67 (jx 0.3) 0 _._ 75 (jx 0.3) 0 _._ 93 (jx 0.2) 3 _._ 85 (jx 1.0)
3 2 _._ 05 (dat 0.3) 3 _._ 60 (jxv 0.0) 4 _._ 17 (jx 0.0) 9 _._ 03 (oedat 0.0) 32 _._ 33 (oedat 0.4)
32,768 1 0 _._ 06 (jx 1.0) 0 _._ 13 (jx 0.7) 0 _._ 17 (jx 0.8) 0 _._ 19 (jx 0.5) 0 _._ 56 (jx 1.9)
2 0 _._ 51 (dat 0.5) 1 _._ 34 (jx 0.3) 1 _._ 58 (jx 0.3) 1 _._ 78 (jx 0.1) 5 _._ 93 (oedat 0.8)
65,536 1 0 _._ 11 (jx 1.1) 0 _._ 26 (jx 0.7) 0 _._ 33 (jx 0.8) 0 _._ 36 (jx 0.4) 1 _._ 11 (jx 1.9)
2 0 _._ 86 (oedat 0.4) 2 _._ 60 (jxv 0.2) 3 _._ 11 (jx 0.3) 3 _._ 55 (jx 0.1) 10 _._ 01 (oedat 0.6)
131,072 1 0 _._ 20 (jx 1.1) 0 _._ 49 (jx 0.7) 0 _._ 63 (jx 0.8) 0 _._ 66 (jx 0.4) 2 _._ 16 (jx 1.9)
262,144 1 0 _._ 40 (jx 1.1) 0 _._ 98 (jxv 0.7) 1 _._ 21 (oedat 0.8) 1 _._ 32 (jx 0.4) 3 _._ 93 (oedat 1.7)
524,288 1 0 _._ 54 (dat 0.7) 1 _._ 84 (jxv 0.7) 2 _._ 17 (oedat 0.7) 2 _._ 60 (jx 0.4) 6 _._ 53 (oedat 1.4)
1,048,576 1 0 _._ 89 (dat 0.6) 3 _._ 65 (jxv 0.7) 4 _._ 07 (oedat 0.6) 17 _._ 78 (oedas 1.4) 24 _._ 93 (oedat 2.7)
Table 13: Summary results of matrix evaluation mode, no single-thread limitation. For each weak
form, mesh size and FE approximation order, the shortest elapsed time mean without the worst
case _T_ <sup>¯ww</sup> [s] across all backends is given, as well as the corresponding backend and _T_ <sup>¯ww</sup> _/T_ <sup>¯</sup> _r_ <sup>ww</sup> (in
parentheses).
1400
1200
1000
800
600
400
200
0
~~-~~
01,02,01,01
01,13,01,01
<u>13,03,01,01</u>
24,01,02,01
<u>24,02,02,01</u>
24,12,02,01
500
400
300
200
100
0
01,02,02,01
<u>24,23,02,01</u>
34,03,02,01
34,23,02,01
<u>das</u>
dat
jx
~~jxv~~
np
npl
oe
<u>oeda</u> <u><mark>s</mark></u>
oeda <mark>t</mark>
<mark>oel</mark>
~~sfepy~~
das
dat
<u>jx</u>
jxv
<u>np</u>
npl
oe
<u><mark>oeda</mark></u> <u>s</u>
- <mark>edat</mark>
oel
~~<u>s</u>~~ <u>f</u> ~~<u>ep</u>~~ <u>y</u>
Figure 18: The highest throughput of each backend (number of megabytes evaluated per second)
for the vector dot product einsum expression with allowed threads. Left: residual mode evaluations
_|r|/T_ <sup>¯ww</sup>, right: matrix mode evaluations _|M_ _|/T_ <sup>¯ww</sup> . The backends are indicated by markers, the
einsum contraction paths by color. The cell counts ( _x_ axis) are grouped by the approximation
orders.
250
200
150
100
50
0
<u>-</u>
01,23,13,12,01
03,23,23,02,01
45,04,23,02,01
<u>45,04,23,12,01</u>
45,34,03,02,01
45,34,23,01,01
45,34,23,02,01
1200
1000
800
600
400
200
0
~~-~~
01,01,02,01,01
02,02,01,02,01
02,13,23,02,01
<u>03,02,02,02,01</u>
03,14,23,01,01
04,04,12,02,01
14,23,13,02,01
23,34,01,02,01
~~23,34,01,20,01~~
35,24,03,12,01
35,34,23,02,01
das
dat
~~jx~~
jxv
np
npl
~~oe~~
- <mark>eda</mark> s
oedat
<mark>o</mark> el
~~<u>s</u>~~ <u>f</u> ~~<u>epy</u>~~
~~das~~
dat
jx
<u>jxv</u>
np
<mark>n</mark> pl
oe
~~oedas~~
oedat
oel
~~<u>s</u>~~ <u>f</u> ~~<u>ep</u>~~ <u>y</u>
Figure 19: The highest throughput of each backend (number of megabytes evaluated per second)
for the weighted vector dot product einsum expression with allowed threads. Left: residual mode
evaluations _|r|/T_ <sup>¯ww</sup>, right: matrix mode evaluations _|M_ _|/T_ <sup>¯ww</sup> . The backends are indicated by
markers, the einsum contraction paths by color. The cell counts ( _x_ axis) are grouped by the
approximation orders.
120
100
80
60
40
20
0
~~-~~
01,24,24,13,02,01
03,24,24,23,12,01
~~46,45,04,23,12,01~~
46,45,34,01,12,01
46,45,34,03,02,01
<u>46,45,34,03,12,01</u>
46,45,34,23,02,01
46,45,34,23,12,01
500
400
300
200
100
0
<u>-</u>
<u>01,01,0123</u>
01,01,13,02,01
03,14,23,012
<u>03,14,23,02,01</u>
03,34,13,12,01
04,23,13,12,01
12,23,13,02,01
~~das~~
dat
jx
<u>jxv</u>
np
npl
oe
~~oeda~~ ~~<mark>s</mark>~~
<mark>oeda</mark> t
oel
~~<u>s</u>~~ <u>f</u> ~~<u>epy</u>~~
das
dat
<u>jx</u>
jxv
np
npl
<u>oe</u>
- <mark>edas</mark>
<mark>o</mark> edat
<u>oel</u>
~~<u>sfepy</u>~~
Figure 20: The highest throughput of each backend (number of megabytes evaluated per second)
for the weak linear elasticity term einsum expression with allowed threads. Left: residual mode
evaluations _|r|/T_ <sup>¯ww</sup>, right: matrix mode evaluations _|M_ _|/T_ <sup>¯ww</sup> . The backends are indicated by
markers, the einsum contraction paths by color. The cell counts ( _x_ axis) are grouped by the
approximation orders.
### References
[1] Martin S. Alnæs, Anders Logg, Kristian B. Ølgaard, Marie E. Rognes, and Garth N. Wells.
Unified form language: A domain-specific language for weak formulations of partial differential
equations. _ACM_ _Transactions_ _on_ _Mathematical_ _Software_, 40(2):9:1–9:37, March 2014.
[2] I. Babuˇska and B. Q. Guo. The h, p and h-p version of the finite element method; basis
theory and applications. _Advances_ _in_ _Engineering_ _Software_, 15(3):159–174, January 1992.
[3] Valeria Barra, Jed Brown, Jeremy Thompson, and Yohann Dudouit. High-performance op
erator evaluations with ease of use: libCEED’s Python interface. In _Python_ _in_ _Science_ _Con-_
_ference_, pages 85–90, Austin, Texas, 2020.
[4] S. Behnel, R. Bradshaw, C. Citro, L. Dalcin, D.S. Seljebotn, and K. Smith. Cython: The
best of both worlds. _Computing_ _in_ _Science_ _Engineering_, 13(2):31 –39, 3,4 2011.
[5] L. S. Blackford, J. Demmel, J. Dongarra, I. Duff, S. Hammarling, G. Henry, M. Heroux,
L. Kaufman, A. Lumsdaine, A. Petitet, R. Pozo, K. Remington, and R. C. Whaley. An
updated set of basic linear algebra subprograms (BLAS). _ACM Transactions on Mathematical_
_Software_, 28(2):135–151, June 2002.
[6] St´ephane Bordas, Phu Vinh Nguyen, Cyrille Dunant, Amor Guidoum, and Hung Nguyen
Dang. An extended finite element library. _International_ _Journal_ _for_ _Numerical_ _Methods_ _in_
_Engineering_, 71(6):703–732, 2007.
[7] James Bradbury, Roy Frostig, Peter Hawkins, Matthew James Johnson, Chris Leary,
Dougal Maclaurin, and Skye Wanderman-Milne. JAX: composable transformations of
Python+NumPy programs. `[https://github.com/google/jax](https://github.com/google/jax)`, 2021. ver. 0.2.9.
[8] Robert Cimrman. Performance measurements of Python tensor contraction packages in the
finite element context. `[https://doi.org/10.5281/zenodo.4750560](https://doi.org/10.5281/zenodo.4750560)`, May 2021.
[9] Robert Cimrman. soops: run parametric studies runner and collect results. `[https://github.](https://github.com/rc/soops)`
`[com/rc/soops](https://github.com/rc/soops)`, 2021. ver. 2021.1.
[10] Robert Cimrman, Vladim´ır Lukeˇs, and Eduard Rohan. Multiscale finite element calculations
in python using sfepy. _Advances_ _in_ _Computational_ _Mathematics_, 2019.
[11] Dask Development Team. Dask: Library for dynamic task scheduling. `[https://dask.org](https://dask.org)`,
2021. ver. 2021.02.0.
[12] Johnnie Gray and Stefanos Kourtis. Hyper-optimized tensor network contraction. _Quantum_,
5:410, March 2021.
[13] Tom Gustafsson and G. McBain. Scikit-fem: A Python package for finite element assembly.
_Journal_ _of_ _Open_ _Source_ _Software_, 5(52):2369, August 2020.
[14] Jack S. Hale, Matteo Brunetti, St´ephane P. A. Bordas, and Corrado Maurini. Simple and
extensible plate and shell finite element models through automatic code generation tools.
_Computers_ _&_ _Structures_, 209:163–181, October 2018.
[15] Charles R. Harris, K. Jarrod Millman, St´efan J. van der Walt, Ralf Gommers, Pauli Vir
tanen, David Cournapeau, Eric Wieser, Julian Taylor, Sebastian Berg, Nathaniel J. Smith,
Robert Kern, Matti Picus, Stephan Hoyer, Marten H. van Kerkwijk, Matthew Brett, Allan
Haldane, Jaime Fern´andez del R´ıo, Mark Wiebe, Pearu Peterson, Pierre G´erard-Marchant,
Kevin Sheppard, Tyler Reddy, Warren Weckesser, Hameer Abbasi, Christoph Gohlke, and
Travis E. Oliphant. Array programming with NumPy. _Nature_, 585(7825):357–362, September
2020.
[16] Siu Kwan Lam, Antoine Pitrou, and Stanley Seibert. Numba: A LLVM-based Python JIT
compiler. In _Proceedings_ _of_ _the_ _Second_ _Workshop_ _on_ _the_ _LLVM_ _Compiler_ _Infrastructure_ _in_
_HPC_, LLVM ’15, pages 1–6, New York, NY, USA, November 2015. Association for Computing
Machinery.
[17] Ling Liang, Jianyu Xu, Lei Deng, Mingyu Yan, Xing Hu, Zheng Zhang, Guoqi Li, and Yuan
Xie. Fast Search of the Optimal Contraction Sequence in Tensor Networks. _IEEE_ _Journal_ _of_
_Selected_ _Topics_ _in_ _Signal_ _Processing_, 15(3):574–586, April 2021.
[18] Anders Logg, Kent-Andre Mardal, and Garth Wells, editors. _Automated_ _Solution_ _of_ _Dif-_
_ferential_ _Equations_ _by_ _the_ _Finite_ _Element_ _Method:_ _The_ _FEniCS_ _Book_ . Lecture Notes in
Computational Science and Engineering. Springer-Verlag, Berlin Heidelberg, 2012.
[19] Linjian Ma, Jiayu Ye, and Edgar Solomonik. AutoHOOT: Automatic High-Order Optimiza
tion for Tensors. _arXiv:2005.04540_ _[cs,_ _math]_, May 2020.
[20] Wes McKinney. Data Structures for Statistical Computing in Python. In _Python_ _in_ _Science_
_Conference_, pages 56–61, Austin, Texas, 2010.
[21] Nicolas Mo¨es, John Dolbow, and Ted Belytschko. A finite element method for crack growth
without remeshing. _International_ _Journal_ _for_ _Numerical_ _Methods_ _in_ _Engineering_, 46(1):131–
150, 1999.
[22] Maty´aˇs Nov´ak, Jiˇr´ı Vack´aˇr, and Robert Cimrman. Evaluating Hellmann–Feynman forces
within non-local pseudopotentials. _Computer_ _Physics_ _Communications_, 250:107034, May
2020.
[23] Fabian Pedregosa and et al. memory ~~p~~ rofiler: a python module for monitoring memory
consumption. `[https://github.com/pythonprofilers/memory_profiler](https://github.com/pythonprofilers/memory_profiler)`, 2021. ver. 0.58.0.
[24] Talal Rahman and Jan Valdman. Fast MATLAB assembly of FEM matrices in 2D and 3D:
Nodal elements. _Applied_ _Mathematics_ _and_ _Computation_, 219(13):7151–7158, March 2013.
[25] Shi-Ju Ran, Emanuele Tirrito, Cheng Peng, Xi Chen, Luca Tagliacozzo, Gang Su, and Maciej
Lewenstein. _Tensor_ _Network_ _Contractions:_ _Methods_ _and_ _Applications_ _to_ _Quantum_ _Many-_
_Body_ _Systems_, volume 964 of _Lecture_ _Notes_ _in_ _Physics_ . Springer International Publishing,
Cham, 2020.
[26] E. Samaniego, C. Anitescu, S. Goswami, V. M. Nguyen-Thanh, H. Guo, K. Hamdia,
X. Zhuang, and T. Rabczuk. An energy approach to the solution of partial differential
equations in computational mechanics via machine learning: Concepts, implementation and
applications. _Computer_ _Methods_ _in_ _Applied_ _Mechanics_ _and_ _Engineering_, 362:112790, April
2020.
[27] Frank Schindler and Adam S. Jermyn. Algorithms for tensor network contraction ordering.
_Machine_ _Learning:_ _Science_ _and_ _Technology_, 1(3):035001, July 2020.
[28] Daniel G. A. Smith and Johnnie Gray. opt ~~e~~ insum - a python package for optimizing con
traction order for einsum-like expressions. _Journal_ _of_ _Open_ _Source_ _Software_, 3(26):753, 2018.
[29] Kasia Swirydowicz, Noel Chalmers, Ali Karakus, and Tim Warburton. <sup>´</sup> Acceleration of tensor
product operations for high-order finite element methods:. _The_ _International_ _Journal_ _of_ _High_
_Performance_ _Computing_ _Applications_, January 2019.
[30] Jana Turjanicov´a, Eduard Rohan, and Vladim´ır Lukeˇs. Homogenization based two-scale
modelling of ionic transport in fluid saturated deformable porous media. _Computers_ _&_ _Math-_
_ematics_ _with_ _Applications_, 78(9):3211–3235, November 2019.
[31] O. C. Zienkiewicz and R. L. Taylor. _The_ _Finite_ _Element_ _Method:_ _The_ _Basis_ . Butterworth
Heinemann, 2000.
섹션 본문
섹션 본문이 없습니다.
참고문헌
참고문헌 정보가 없습니다.