scieee AI-readable full text Open interactive document viewer

A Case for Malleable Thread-Level Linear Algebra Libraries: The LU Factorization With Partial Pivoting

Catalán, Sandra; Herrero Zaragoza, José R.; Quintana-Orti, Enrique S.; Rodríguez Sánchez, Rafael; Van de Geijn, Robert A.

Abstract

We propose two novel techniques for overcoming load-imbalance encountered when implementing so-called look-ahead mechanisms in relevant dense matrix factorizations for the solution of linear systems. Both techniques target the scenario where two thread teams are created/activated during the factorization, with each team in charge of performing an independent task/branch of execution. The first technique promotes worker sharing (WS) between the two tasks, allowing the threads of the task that completes first to be reallocated for use by the costlier task. The second technique allows a fast task to alert the slower task of completion, enforcing the early termination (ET) of the second task, and a smooth transition of the factorization procedure into the next iteration. The two mechanisms are instantiated via a new malleable thread-level implementation of the basic linear algebra subprograms, and their benefits are illustrated via an implementation of the LU factorization with partial pivoting enhanced with look-ahead. Concretely, our experimental results on an Intel-Xeon system with 12 cores show the benefits of combining WS+ET, reporting competitive performance in comparison with a task-parallel runtime-based solution.

Full text

Received December 21, 2018, accepted January 14, 2019, date of publication January 31, 2019, date of current version February 14, 2019. Digital Object Identifier 10.1109/ACCESS.2019.2895541 A Case for Malleable Thread-Level Linear Algebra Libraries: The LU Factorization With Partial Pivoting SANDRA CATALÁN1, JOSÉ R. HERRERO 2, ENRIQUE S. QUINTANA-ORTÍ1, RAFAEL RODRÍGUEZ-SÁNCHEZ3, AND ROBERT VAN DE GEIJN4 1Departarmento Ingeniería y Ciencia de Computadores, Universidad Jaume I, 12071 Castellón de la Plana, Spain 2Departamento d’Arquitectura de Computadors, Universitat Politècnica de Catalunya, 08034 Barcelona, Spain 3Departamento de Arquitectura de Computadores y Automática, Universidad Complutense de Madrid, 28040 Madrid, Spain 4Department of Computer Science, Institute for Computational Engineering and Sciences, The University of Texas at Austin, Austin, TX 78712, USA Corresponding author: José R. Herrero ([email protected]) This work was supported in part by the Spanish Ministerio de Economía y Competitividad under Project TIN2014-53495-R, Project TIN2015-65316-P, and Project TIN2017-82972-R, in part by the H2020 EU FETHPC ‘‘INTERTWinE’’ under Project 671602, in part by the Generalitat de Catalunya under Project 2017-SGR-1414, and in part by the NSF under Grant ACI-1550493. ABSTRACT We propose two novel techniques for overcoming load-imbalance encountered when implementing so-called look-ahead mechanisms in relevant dense matrix factorizations for the solution of linear systems. Both techniques target the scenario where two thread teams are created/activated during the factorization, with each team in charge of performing an independent task/branch of execution. The first technique promotes worker sharing (WS) between the two tasks, allowing the threads of the task that completes first to be reallocated for use by the costlier task. The second technique allows a fast task to alert the slower task of completion, enforcing the early termination (ET) of the second task, and a smooth transition of the factorization procedure into the next iteration. The two mechanisms are instantiated via a new malleable thread-level implementation of the basic linear algebra subprograms, and their benefits are illustrated via an implementation of the LU factorization with partial pivoting enhanced with look-ahead. Concretely, our experimental results on an Intel-Xeon system with 12 cores show the benefits of combining WS+ET, reporting competitive performance in comparison with a task-parallel runtime-based solution. INDEX TERMS Solution of linear systems, multi-threading, workload balancing, thread malleability, basic linear algebra subprograms (BLAS), linear algebra package (LAPACK). I. INTRODUCTION In the 1970s and 80s, the scientific community recognized the value of defining standard interfaces for dense linear algebra (DLA) operations with the introduction of the Basic Linear Algebra Subprograms (BLAS) [1]–[3]. Ever since, the key to performance portability in this domain has been the development of highly-optimized, architecture-specific implementations of the BLAS, either by hardware vendors (e.g., Intel MKL [4], AMD ACML [5], IBM ESSL [6], and NVIDIA CUBLAS [7]) or independent developers (e.g., GotoBLAS [8], [9], OpenBLAS [10], ATLAS [11], and BLIS [12]). The associate editor coordinating the review of this manuscript and approving it for publication was Bora Onat. Multi-threaded instances of the BLAS for current multi-core processor architectures take advantage of the simple data dependencies featured by these operations to exploit loop/data-parallelism at the block level (hereafter referred to as block-data parallelism, or BDP). For more complex DLA operations, like those supported by LAPACK [13] and libflame [14], exploiting task-parallelism with dependencies1(TP) is especially efficient when performed by a runtime that semi-automatically decomposes the computation into tasks and orchestrates their dependencyaware scheduling [15]–[18]. For the BLAS kernels though, 1We view TP as the type of concurrency present in an operation that can be decomposed into a collection of suboperations (tasks) connected by a rich set of data dependencies. Compared with this, BDP is present when the operation basically consists of a number of independent (inherently parallel) suboperations, each acting on a disjoint block of data. VOLUME 7, 2019 2169-3536 2019 IEEE. Translations and content mining are permitted for academic research only. Personal use is also permitted, but republication/redistribution requires IEEE permission. See http://www.ieee.org/publications_standards/publications/rights/index.html for more information. 17617 S. Catalán et al.: Case for Malleable Thread-Level Linear Algebra Libraries: LU Factorization With Partial Pivoting exploiting BDP is still the preferred choice, because it allows tighter control on the data movements across the memory hierarchy and avoids the overhead of a runtime that is unnecessary due to the (mostly) nonexistent data dependencies in the BLAS kernels. Exploiting both BDP and TP, in a sort of nested parallelism can yield more efficient solutions as the number of cores in processor architectures continues to grow. For example, consider an application composed of two independent tasks, TAand TB, both of which are inherently parallel and preceded/followed by synchronization points. In this scenario, exploiting TP only is inefficient, because it can keep at most 2 threads busy. To address this, we could take advantage of the BDP inside TAand TBvia TP but, given their inherent parallelism, this is likely to incur certain overhead compared with a direct exploitation of BDP. Finally, extracting BDP only is surely possible, but it may be less scalable than a nested TP+BDP solution that splits the threads into two teams, and puts them to work on TAand TBconcurrently. Let us consider now that the previous scenario occurs during the execution of a complex DLA operation where both tasks, TAand TB, can be computed via simple calls to a multi-threaded instance of BLAS. Although the solution seems obvious, exploiting nested TP+BDP parallelism here can still be suboptimal. In particular, all multi-threaded instances of BLAS offer a rigid interface to control the threading execution of a routine, which only allows one to set the number of threads that will participate before the routine is invoked. Importantly, this number cannot be changed during its execution. Thus, in case TAis completed earlier, the team of threads in charge of its execution will remain idle waiting for the completion of TB, producing a suboptimal execution from a performance perspective. The scenario that we have described is far from being rare in DLA. To illustrate this, we will employ the LU factorization with partial pivoting for the solution of linear systems [19]. High-performance algorithms for this decomposition consist of a loop-body that processes the matrix from its top-left corner to the bottom-right one, at each iteration computing a panel2factorization and updating a trailing submatrix via calls to BLAS. We will review this factorization as a prototypical example to make the following contributions in our paper: •Malleable DLA libraries: We introduce a malleable thread-level implementation of BLIS [12] that allows the number of threads that participate in the execution of a BLAS kernel to dynamically change at execution time. •Worker Sharing (WS): In case the panel factorization is less expensive than the update of the trailing submatrix, we leverage the malleable instance of the BLAS to improve workload balancing and performance, by allowing the thread team in charge of the panel factor- 2In the following, we will refer to a block with more rows than columns as a panel. ization to be reallocated to the execution of the trailing update. •Early Termination (ET): To tackle the opposite case, where panel factorization is more expensive than the update of the trailing submatrix, we design an ET mechanism that allows the thread team in charge of the trailing update to communicate the alternative team of this event. This alert forces an ET of the panel factorization, and the advance of the factorization into the next iteration. •We perform a comprehensive experimental evaluation on a 6-core Intel Xeon E5-2603 v3 processor, using execution traces to illustrate actual benefits of our approach, and comparing its performance to those obtained with a runtime-based solution using OmpSs [15]. Our study includes results using a dual-socket (i.e., twelve-core) configuration. The key to our approach is that we depart from conventional instances of BLAS to instead view the cores/threads as a pool of computational resources that, upon completing the execution of a BLAS/LAPACK routine, can be tapped to participate in the execution of another BLAS/LAPACK routine that is already in progress. This WS supports a dynamic choice of the algorithmic block size as the operation progresses. Furthermore, the same idea carries over to all other major matrix decompositions for the solution of linear systems, such as the QR, Cholesky and LDLTfactorizations [19]. In [20] we leverage the techniques presented in this paper, focussing on the exploitation of hardware/frequencyasymmetric multicore architectures, studying the optimal mapping of the different types of tasks to the existing heterogenous resources in seach of faster global execution and lower energy consumption. II. THE BLIS IMPLEMENTATION OF BASIC LINEAR ALGEBRA KERNELS BLIS is a framework that allows developers to rapidly deploy new high-performance implementations of BLAS and BLAS- like operations on current and future architectures [12]. A key property of the BLIS open source effort is that it exposes the internal implementation of the BLAS kernels at a finergrain level than OpenBLAS or commercial libraries while offering performance that is competitive with GotoBLAS, OpenBLAS, Intel MKL, and ATLAS [21], [22]. We start by reviewing the design principles that underlie BLIS, using the implementation of gemm as a particular case study. Consider the matrices A∈Rm×k,B∈Rk×n, and C∈Rm×n. BLIS mimics GotoBLAS to implement the gemm kernel3 C+= A·B(1) 3Actually, the kernel in the BLAS interface/BLIS implementation for gemm computes C=αC+βop(A)·op(B), where α, β are scalars, op(·) performs an optional transposition/Hermitian-conjugation, and op(A) is m×k,op(B) is k×n,Cis m×n. For simplicity, in the description we address the case where α=β=1 and the operator op(·) does not perform any transformation on the input matrix. 17618 VOLUME 7, 2019 S. Catalán et al.: Case for Malleable Thread-Level Linear Algebra Libraries: LU Factorization With Partial Pivoting FIGURE 1. High performance implementation of gemm in BLIS. In the code, Cc≡C(ic:ic+mc−1,jc:jc+nc−1) is just a notation artifact, introduced to ease the presentation of the algorithm. In contrast, Ac,Bccorrespond to actual buffers that are involved in data copies. FIGURE 2. Distribution of the workload among t=3 threads when Loop 4 of BLIS gemm is parallelized. Different colors in the output Cdistinguish the panels of this matrix that are computed by each thread as the product of Acand corresponding panels of the input Bc. as three nested loops around a macro-kernel plus two packing routines (see Loops 1–3 in FIGURE 1). The macro-kernel is then implemented in terms of two additional loops around a micro-kernel (Loops 4 and 5 in that figure). The loop ordering embedded in BLIS, together with the packing routines and an appropriate choice of the BLIS cache configuration parameters (nc,kc,mc,nrand mr), orchestrate a regular pattern of data transfers across the levels of the memory hierarchy, and amortize the cost of these transfers with enough computation from within the micro-kernel [12] to attain near-peak performance. In most architectures, mr,nrare in the range 4–16; mc,kcare in the order of a few hundreds; and nccan be up to a few thousands [12], [21]. The parallelization of BLIS’s gemm for multi-threaded architectures has been analyzed for conventional symmetric multicore processors [21], modern many-threaded architectures [22], and asymmetric multicore processors [23]. In all these cases, the parallel implementation exploits the BDP exposed by the nested five-loop organization of gemm, at one or more levels (i.e., loops), using OpenMP or POSIX threads. A convenient option in most single-socket systems is to parallelize either Loop 3 (indexed by ic), Loop 4 (indexed by jr), or a combination of both [21]–[23]. For example, when Loop 3 is parallelized, each thread packs a different macro-panel Acinto the L2 cache and executes a different instance of the macro-kernel. In contrast, when Loop 4 is parallelized, different threads will operate on independent instances of the micro-kernel, but access the same macro-panel Acin the L2 cache. Consider, for example, a version of BLIS gemm that extracts BDP from Loop 4 only, to be executed on a multicore architecture with t(physical) cores and one thread mapped per core. The iteration space of Loop 4 is then statically distributed among the tthreads in a round-robin fashion, equivalent to the effect attained by adding an OpenMP directive #pragma omp parallel for, with a static schedule, around that loop; see Figure 2. To improve performance, the packing is also performed in parallel so that, at each iteration of Loop 3, all tthreads collaborate to copy and re-organize the entries of A(ic:ic+mc−1,pc:pc+kc−1) into the buffer Ac. III. ALGORITHMS FOR THE LU FACTORIZATION ON MULTI-THREADED ARCHITECTURES Given a matrix A∈Rm×n, its LU factorization produces lower and upper triangular factors, L∈Rm×nand U∈Rn×n respectively, such that PA =LU, where P∈Rm×mdefines a permutation that is introduced for numerical stability [19]. In this section we first review the conventional unblocked VOLUME 7, 2019 17619 S. Catalán et al.: Case for Malleable Thread-Level Linear Algebra Libraries: LU Factorization With Partial Pivoting and blocked algorithms for the LU factorization, and then describe how BDP is exploited from within them. Next, we introduce a re-organized version of the algorithm that integrates look-ahead in order to enhance performance in a nested TP+BDP execution. The experiments in the remainder of the paper were obtained using ieee double-precision arithmetic on a server equipped with Intel Xeon E5-2603 v3 technology. One socket (six cores) at a nominal frequency 1.6 GHz were used in all experiments except those in section V-C1, which use a dual-socket configuration. The implementations were linked with BLIS version 0.1.8 or a tailored version of this library especially developed for this work. Unless otherwise stated, BDP parallelism is extracted only from Loop 4 of the BLIS kernels. All traces in this paper were obtained using Extrae version 3.3.0 [24]. A. BASIC ALGORITHMS AND BDP There exist a number of algorithmic variants of the LU factorization that can accommodate partial pivoting [19]. Among these, Figure 3(top) shows an unblocked algorithm for the so-called right-looking (RL) variant, expressed using the FLAME notation [25]. For simplicity, we do not include pivoting in the following description of the algorithms, though all our actual implementations, (and in particular those employed in our experimental evaluation,) integrate standard partial pivoting. The cost of computing the LU factorization of an m×nmatrix, via any of the algorithms presented in this paper, is mn2−n3/3 floating-point arithmetic operations (flops). Hereafter, we will consider square matrices of order n for which, the cost boils down to 2n3/3 flops. For the RL variants, the major part of these operations are concentrated in the initial iterations of the algorithm(s). For example, the first 25% iterations account for almost 58% of the flops; the first half for 87.5%; and the first 75% for more than 98%. Thus, the key to high performance mostly lies in the initial stages of the factorization. For performance reasons, dense linear algebra libraries compute the LU factorization via a blocked algorithm that casts most computations in terms of gemm. Figure 3(bottom) presents the blocked RL algorithm. For each iteration, the algorithm processes panels of bcolumns, where bis the algorithmic block size. The three operations in the loop body factorize the ‘‘current’’ panel Ap=A11 A21 , via the unblocked algorithm (LU_unb, RL1); and next update the trailing submatrix, consisting of A12 and A22, via a triangular system solve (trsm, RL2) and a matrix multiplication (gemm, RL3), respectively. In practice, the block size bis chosen so that the successive invocations to the gemm kernel deliver high FLOPS (flops per second) rates. If bis too small, the performance of gemm will suffer, and so will that of the LU factorization. On the other hand, reducing bis appealing as this choice decreases the number of flops that are performed in terms of the panel factorization, an operation that can be expected to offer significantly lower throughput (FLOPS) FIGURE 3. Unblocked and blocked RL algorithms for the LU factorization (top and bottom, respectively). In the notation, n(·) returns the number of columns of its argument, and trilu(·) returns the strictly lower triangular part of its matrix argument, setting the diagonal entries of the result to ones; furthermore, the arrows ‘‘←’’ and ‘‘→’’ are simply used to denote partitioning/repartitionings of the operands. These algorithms correspond to the well-known right-looking version of the factorization and are included for reference. than gemm. (Concretely, provided nb, the cost required for all panel factorizations is about n2b/2 flops.) Thus, there is the tension between these two requisites. When the target platform is a multicore processor, the conventional parallelization of the LU factorization simply relies on multi-threaded instances of trsm and gemm to exploit BDP only. Compared with this, the panel factorization of Ap, which lies in the critical path of the blocked RL factorization algorithm, exhibits a reduced degree of concurrency. Thus, depending on the selected block size band certain hardware features of the target architecture (number of cores, floating-point performance, memory bandwidth, etc.), this operation may easily become a performance bottleneck; see Figure 4. To illustrate the performance relevance of the panel factorization, Figure 5displays a fragment of a trace corresponding to the LU factorization of a 10,000×10,000 matrix, using the blocked RL algorithm in Figure 3, with partial pivoting and ‘‘outer’’ block size b=bo=256. The code is linked with multi-threaded versions of the BLIS kernels for gemm and 17620 VOLUME 7, 2019 S. Catalán et al.: Case for Malleable Thread-Level Linear Algebra Libraries: LU Factorization With Partial Pivoting FIGURE 4. Exploitation of BDP in the blocked RL LU parallelization. A single thread team executes all the operations, with less active threads for RL1 due to the reduced concurrency of this kernel. In this algorithm, RL1 stands in the critical path. trsm. The panel factorization (panel) is performed via a call to the same blocked algorithm, with ‘‘inner’’ block size b= bi=32, and also extracts BDP from the same two kernels. With this configuration, the panel factorization represents less than 2% of the flops performed by the algorithm. However, the trace of the first four iterations reveals that its practical cost is much higher than could be expected. (The cost of factorizing a panel relative to the cost of an iteration becomes even larger as the iteration progresses.) Here we note also the significant cost of the row permutations, which are performed via the sequential legacy code for this routine in LAPACK (laswp). However, this second operation is embarrassingly parallel and its execution time can be expected to decrease linearly with the number of cores. At this point, we note that the operations inside the loop body of the blocked algorithm in Figure 3(bottom) present strict dependencies (denoted heafter with the symbol ‘‘⇒’’) that enforce their computation in the order RL1 ⇒RL2 ⇒ RL3. Therefore, there seems to be no efficient manner to formulate a TP version of the blocked algorithm in that figure. B. STATIC LOOK-AHEAD AND NESTED TP+BDP A strategy to tackle the hurdle represented by the panel factorization in a parallel execution consists in the introduction of look-ahead [26] into the algorithm. Concretely, during each iteration of the decomposition this technique aims to overlap the factorization of the ‘‘next’’ panel with the update of the ‘‘current’’ trailing submatrix, in practice enabling a TP version of the algorithm with two separate branches of execution, as discussed next. Figure 6illustrates a version of the blocked RL algorithm for the LU factorization re-organized to expose look-ahead. The key is to partition the trailing submatrix into two block column panels: A12 A22 → AP 12 AR 12 AP 22 AR 22 !(2) where AP 22 corresponds to the block that, in the conventional version of the algorithm (i.e., without look-ahead,) would be factorized during the next iteration. This effectively separates the blocks that are modified as part of the next panel factorization from the the remainder updates, left and right of the 2 ×2 partitioning in (2), respectively. Proceeding in this manner creates two coarse-grain independent tasks (groups of operations in separate branches of execution): TPF, consisting of PF1,PF2,PF3; and TRU, composed of RU1 and RU2; see Figure 6. The ‘‘decoupling’’ of these block panels thus facilitate that, in a TP execution of an iteration of the loop body of the look-ahead version, the updates on AP 12,AP 22 and the factorization of the latter (operations on the next panel, in TPF) proceed concurrently with the updates of AR 12,AR 22 (remainder operations, in TRU), as there are no dependencies between TPF and TRU. By carefully tuning the block size band adjusting the amount of computational resources (threads) dedicated to each of the two independent tasks, TPF and TRU, a nested TP+BDP execution of the algorithm enhanced with this static look-ahead can partially or totally overcome the bottleneck represented by the panel factorization; see Figure 7. Figure 8illustrates a complete overlap of TRU with TPF attained by the look-ahead technique. The results in that figure correspond to a fragment of a trace obtained for the LU factorization of a 10,000 ×10,000 matrix, using the blocked RL algorithm in Figure 6, with partial pivoting, and outer block size b=bo=256. For this experiment, the t=6 threads are partitioned into two teams: PF with tpf =1 thread in charge of TPF, and RU with tru =5 threads responsible for TRU. The panel factorization (panel) is performed via a call to the same algorithm, with b=bi=32, and this operation proceeds sequentially (as PF consists of a single FIGURE 5. Execution trace of the first four iterations of the blocked RL LU factorization with partial pivoting, using 6 threads, applied to a square matrix of order 10,000, with bo=256,bi=32. The x-axis represents the execution timeline while the different colors correspond to the fraction of the time that the threads spend in each of the different kernels appearing in the LU factorization: from left to right, panel factorization (PANEL), row permutations (LASWP), triangular system solve (TRSM), matrix-matrix multiplication (GEMM), and idle. VOLUME 7, 2019 17621 S. Catalán et al.: Case for Malleable Thread-Level Linear Algebra Libraries: LU Factorization With Partial Pivoting FIGURE 6. Blocked RL algorithm enhanced with look-ahead for the LU factorization. This algorithm is included for reference. Note that there is an implicit schedule in the formulation of this algorithm, as the operations corresponding to the panel factorization can be computed in parallel with those for the remainder update. thread). The application of the row permutations is distributed between all 6 cores. As argued earlier, the net effect of the look-ahead is that the cost of the panel factorization no longer has a practical impact on the execution time of the (first four iterations of) the factorization algorithm, which is now basically determined by the cost of the remaining operations. Given a static mapping of threads to tasks, bshould balance the time spent in the two tasks as, if the operations in TPF take longer than those in TRU, or vice-versa, the threads in charge of the less expensive part will become idle, causing a performance degradation. This was already visible in Figure 8, which shows that, during the first four iterations, the operations in TPF are considerably less expensive than the updates performed as part of the remainder TRU. The complementary case, where TPF requires longer than TRU, is illustrated using the same configuration, for a matrix of dimension 2,000 ×2,000, in Figure 9. Unfortunately, as the factorization proceeds, the theoretical costs and execution times of TPF and TRU vary, making it difficult to determine the optimal value of b, which will need to be adapted during the factorization process. To close this section, note that there exist strict dependencies that serialize the operations within each task: PF1 ⇒ PF2 ⇒PF3 and RU1 ⇒RU2. Therefore, there is no further TP in the loop-body of this re-organized version. However, the basic look-ahead mechanism of level/depth 1 described in this subsection can be refined to accommodate further levels of TP, by ‘‘advancing’’ to the current iteration the panel factorization of the following diterations, in a look-ahead of level/depth d. This considerably complicates the code of the algorithm, but can be seamlessly achieved by a runtime system enhanced with priorities. IV. ADVOCATING FOR MALLEABLE THREAD-LEVEL LA LIBRARIES For simplicity, in the following discussion we will assume that TPF and TRU consist only of the panel factorization involving AP 22 (PF3) and the update of AR 22 (RU2), respectively. Furthermore, we will consider a nested TP+BDP execution FIGURE 7. Exploitation of TP+BDP in the blocked RL LU parallelization with look-ahead. The execution is performed by teams TPF and TRU, consisting of tpf =3 and tru =8 threads, respectively. In this algorithm, the operations on the (k+1)-th panel, including its factorization (PF3), are overlapped with the updates on the remainder of the trailing submatrix (RU1 and RU2). 17622 VOLUME 7, 2019 S. Catalán et al.: Case for Malleable Thread-Level Linear Algebra Libraries: LU Factorization With Partial Pivoting FIGURE 8. Execution trace of the first four iterations of the blocked RL LU factorization with partial pivoting, enhanced with look-ahead, using 6 threads, applied to a square matrix of order 10,000, with bo=256,bi=32. FIGURE 9. Execution trace of the first four iterations of the blocked RL LU factorization with partial pivoting, enhanced with look-ahead, using 6 threads, applied to a square matrix of order 2,000, with bo=256,bi=32. using t=tpf +tru threads, initially with a team PF of tpf threads mapped to the execution of PF3 and a team RU of tru threads computing RU2. Ideally, for the LU factorization with look-ahead, we would like to perform a flexible sharing of the computational resources so that, as soon as the threads in team PF complete VOLUME 7, 2019 17623 S. Catalán et al.: Case for Malleable Thread-Level Linear Algebra Libraries: LU Factorization With Partial Pivoting PF3, they join team RU to help in the execution of RU2 or vice-versa. We next discuss these two cases in detail. A. WORKER SHARING: PANEL FACTORIZATION LESS EXPENSIVE THAN UPDATE Our goal is to enable, at each iteration of the algorithm for the LU factorization with look-ahead, that the threads in team PF that complete the panel factorization join the thread team RU working on the update. The problem is that, if the multiplication to update AR 22 was initiated via an invocation to a traditional gemm, this is not possible as none of the existing high performance implementations of BLAS allow the number of threads working on a kernel that is already in execution to be modified. 1) SUBOPTIMAL SOLUTION: STATIC RE-PARTITIONING A simple workaround for this problem is to split AR 22 into multiple column blocks, for example, AR 22 →A1A2. . . Aq, and to perform a separate call to BLAS gemm in order to exploit BDP during the update of each block. Then, just before each invocation, the kernel’s code queries whether the execution of the panel factorization is completed and, if that is the case, executes the suboperation with the threads from both teams (or only those of RU otherwise). Unfortunately, this approach presents several drawbacks: •Replacing a single invocation to a coarse gemm by multiple calls to smaller gemm may offer lower throughput because the operands passed to gemm are smaller and/or suboptimally ‘‘shaped’’. The consequence is that calling gemm multiple times will internally incur re-packing and data movement overheads, which are more difficult to amortize because of the smaller problem dimensions. •The burden of which loop to partition for parallelism (note that AR 22 could have alternatively been split by rows, or into blocks), and the granularity of this partitioning is then placed upon the programmer’s shoulders, who may lack the information that is necessary to make a good choice. For example, if the granularity is too coarse, this will have negative effect because the integration of the single thread in the update will likely be delayed. A granularity that is too fine, on the other hand, may reduce the parallelism within the BLAS operation or result in the use of cache blocking parameters that are too small. 2) OUR SOLUTION: MALLEABLE THREAD-LEVEL BLAS The alternative that we propose in this work exploits BDP inside RU2,but allows to change the number of threads that participate in this computation even if the task is already in execution! In other words, we view the threads as a resource pool of workers that can be shared between different tasks and reassigned to the execution of a (BLAS) kernel that is already in progress. The key to our approach lies in the explicit exposure of the gemm internals (and other BLAS-3 kernels) in BLIS. Concretely, assume that RU2 is computed via a single invocation to BLIS gemm, and consider that this operation is parallelized by distributing the iteration space of Loop 4 among the threads in team PF; (see Figures 1and 2). Then, just before Loop 4, we force the system to check if the execution of the panel factorization is completed and, based on this information, decides whether this loop is executed using either the union of the threads from both teams or only those in RU; see Figure 10. Let us re-analyze the problems listed in Subsection IV- A1 for the work-around that statically partitioned the update of AR 22, and compare them with our solution that implicitly embeds this partitioning inside BLIS: •The partitioning of gemm into multiple calls to smaller matrix multiplications does not occur. Our solution performs a single call to gemm only, so that there is no additional re-packing nor data movements. For example, in the case just discussed, Bcis already packed and re-used independently of whether tor tru threads participate in the gemm. The buffer Acis packed only once per iteration of Loop 3 (in parallel by both teams or only RU). •The decision of the best partitioning/granularity is left in the hands of BLIS, which likely has more information to do a better job than the programmer. Importantly, the partitioning happens dynamically and is transparent to the programmer. Figure 11 validates the effect of integrating a malleable version4of BLIS into the same configuration that produced the results in Figure 8. A comparison of both figures shows that, with a malleable version of BLIS, the thread executing the operations in TPF, after completing this task, rapidly joins the team that computes the remainder updates, thus avoiding the idle wait. Compared with BLIS, the same approach cannot be integrated into GotoBLAS because the implementation of gemm in this library only exposes the three outermost loops of FIGURE 1, while the remaining loops are encoded in assembly. The BLAS available as part commercial libraries is not an option either because hardware vendors offer black-box implementations which do not permit the migration of threads. B. EARLY TERMINATION: PANEL FACTORIZATION MORE EXPENSIVE THAN UPDATE The analysis of this case will reveal some important insights. In order to discuss them, let us consider that, in the LU factorization with look-ahead, the panel factorization (PF3) is performed via a call to the blocked routine in Figure 3(right). We assume two blocking parameters: b=bofor the outer routine that computes the LU factorization of the complete matrix using look-ahead, and b=bifor the inner routine that factorizes each panel. (Note that, if bi=boor bi=1, 4The discussion on how to create this ‘‘malleable’’ instance of BLIS is an implementation detail, which is not relevant for the discussion of the paper. 17624 VOLUME 7, 2019 S. Catalán et al.: Case for Malleable Thread-Level Linear Algebra Libraries: LU Factorization With Partial Pivoting FIGURE 10. Exploitation of TP+BDP in the blocked RL LU parallelization with look-ahead and WS. The execution is performed by teams TPF and TRU, consisting of tpf =3 and tru =8 threads, respectively. In this example, team TPF completes the factorization PF3 while team TRU is executing the first iteration of Loop 3 that corresponds to RU2/gemm (ic=0). Both teams then merge and jointly continue the update of the remaining iterations of that loop (ic=mc,2mc, . . .). With the parallelization of gemm Loop 4, one such ‘‘entry point’’ enables the merge at the beginning of each iteration of loop ic. the panel factorization is then simply done via the unblocked algorithm.) Furthermore, we will distinguish these two levels by referring to them as the outer LU (factorization with look-ahead) and the inner LU (factorization via the blocked algorithm without look-ahead). Thus, at each iteration of the outer LU, a panel of bocolumns is factorized via a call to LU_blk (inner LU), and this second decomposition proceeds to factorize the panel using a blocked algorithm with block size bi; see Figure 12. From Figure 3(right), the loop body for the inner LU consists of a call to the unblocked version of the algorithm (RL1), followed by the invocations to trsm and gemm that update A12 and A22, respectively (RL2 and RL3). Now, let us assume that the update RU2 by the thread team RU is completed while the threads of team PF are in the middle of the computations corresponding to an iteration of the loop body of the inner LU. Then, provided the versions of the BDP versions trsm and gemm kernels that are invoked from the inner LU are malleable (see subsection IV-A2), inside them the system will perform the actions that are necessary to integrate the thread team RU, which is now idle, into the corresponding (and subsequent) computation(s). Unfortunately, the updates in the loop body of the inner LU involve smallgrained computations (A12 and A22 have at most bo−bi columns, decreasing by bicolumns at each iteration), and little parallel performance can be expected from it especially because of partial pivoting. In order to deal with this scenario, a different option is to force the inner LU to stop at the end of the current iteration, to then rapidly proceed to the next iteration of the outer LU. We refer to this strategy as the early termination (ET). In order to do this though, the transformations computed to factorize the current inner-panel must be propagated first to the remaining columns outside this panel, introducing a certain delay in this version of the ET strategy. A third possibility is to rely on a left-looking (LL) version of the LU factorization for the inner LU, as discussed next. The blocked LL algorithm for the LU factorization differs from the blocked RL variant (see the algorithm in the right-hand side of Figure 3) in the operations performed inside the loop-body, which are replaced by LL1.A01 := trilu(A00)−1A01 LL2. A11 A21 := A11 A21 −A10 A20 A01 LL3. A11 A21 := LU_unb A11 A21  VOLUME 7, 2019 17625 S. Catalán et al.: Case for Malleable Thread-Level Linear Algebra Libraries: LU Factorization With Partial Pivoting of linear systems. The WS mechanism especially benefits from the adoption of a malleable thread-level instance of BLIS, which allows the thread team in charge of the panel factorization, upon completion of this task, to be reallocated to the execution of the trailing update. The ET mechanism tackles the opposite situation, with a panel factorization that is costlier than the trailing update. In such scenario, the team that performed the update communicates to the second team that it should terminate the panel factorization, advancing the factorization process into the next iteration. Our results on a platform equipped with Intel Xeon E5-2603 v3 (12 cores) show the performance benefits of our version enhanced with malleable BLIS and ET compared with a plain LU factorization as well as a version with lookahead. The experiments also report competitive performance compared with an LU factorization that is parallelized by means of a sophisticated runtime, such as OmpSs, that introduces look-ahead of dynamic (variable) depth. Compared with the OmpSs solution, our approach offers higher performance for most problem dimensions, seamlessly tunes the algorithmic block size, and features a considerably smaller memory footprint as it does not require a sophisticated runtime support. We believe that, with the proper scaling of the problem dimension, these advantages carry over to architectures with larger number of cores. To conclude, our paper does not intend to propose an alternative to runtime-based solutions. Instead, the message implicitly carried in our experiments aims to emphasize the benefits of malleable thread-level libraries, which we expect to be crucial in order to exploit the massive thread parallelism of future architectures. This work opens a plethora of interesting questions for future research. In particular, how to generalize the ideas to a multi-task scenario, what kind of interfaces may ease thread-level malleability, and what kind of support is necessary in the runtime for this purpose. ACKNOWLEDGEMENTS The authors would like to thank the other members of the FLAME team for their support. Any opinions, findings and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation (NSF). REFERENCES [1] C. L. Lawson, R. J. Hanson, D. R. Kincaid, and F. T. Krogh, ‘‘Basic linear algebra subprograms for Fortran usage,’’ ACM Trans. Math. Soft., vol. 5, pp. 308–323, Sep. 1979. [2] J. J. Dongarra, J. Du Croz, S. Hammarling, and R. J. Hanson, ‘‘An extended set of FORTRAN basic linear algebra subprograms,’’ ACM Trans. Math. Softw., vol. 14, pp. 1–17, Mar. 1988. [3] J. J. Dongarra, J. Du Croz, S. Hammarling, and I. Duff, ‘‘A set of level 3 basic linear algebra subprograms,’’ ACM Trans. Math. Softw., vol. 16, pp. 1–17, Mar. 1990. [4] Intel. (2015). Math Kernel Library. [Online]. Available: https://software. intel.com/en-us/intel-mkl [5] AMD. (2015). AMD Core Math Library. [Online]. Available: http://developer.amd.com/tools-and-sdks/cpu-development/amd-core- math-library-acml/ [6] (2015). Engineering and Scientific Subroutine Library. [Online]. Available: http://www-03.ibm.com/systems/power/software/essl/ [7] NVIDIA. (2016). cublas. [Online]. Available: https://developer. nvidia.com/cublas [8] K. Goto and R. A. van de Geijn, ‘‘Anatomy of high-performance matrix multiplication,’’ ACM Trans. Math. Softw., vol. 34, p. 12, May 2008. [9] K. Goto and R. van de Geijn, ‘‘High-performance implementation of the level-3 BLAS,’’ ACM Trans. Math. Softw., vol. 35, p. 4, Jul. 2008. [10] OpenBLAS. An Optimized BLAS Library. Accessed: Jan. 2019. [Online]. Available: http://www.openblas.net [11] R. C. Whaley and J. J. Dongarra, ‘‘Automatically tuned linear algebra software,’’ in Proc. SC, Nov. 1998, p. 38. [12] F. G. Van Zee and R. A. van de Geijn, ‘‘BLIS: A framework for rapidly instantiating BLAS functionality,’’ ACM Trans. Math. Softw., vol. 41, no. 3, p. 14, 2015. [13] E. Anderson et al.,LAPACK UsersŠ Guide, 3rd ed. Philadelphia, PA, USA: SIAM, 1999. [14] F. G. V. Zee. (2009). Libflame: The Complete Reference. [Online]. Available: www.lulu.com [15] OmpSs Project Home Page. Accessed: Jan. 2019. [Online]. Available: http://pm.bsc.es/ompss [16] StarPU Project. Accessed: Jan. 2019. [Online]. Available: http://runtime.bordeaux.inria.fr/StarPU/ [17] PLASMA Project Home Page. Accessed: Jan. 2019. [Online]. Available: http://icl.cs.utk.edu/plasma [18] FLAME Project Home Page. Accessed: Jan. 2019. [Online]. Available: http://www.cs.utexas.edu/users/flame/ [19] G. H. Golub and C. F. Van Loan, Matrix Computations, 3rd ed. Baltimore, MD, USA: The Johns Hopkins University Press, 1996. [20] S. Catalán, R. Rodríguez-Sánchez, E. S. Quintana-Ortí, and J. R. Herrero, ‘‘Static versus dynamic task scheduling of the lu factorization on ARM big. LITTLE architectures,’’ in Proc. IEEE Int. Parallel Distrib. Process. Symp. Workshops (IPDPSW), May/Jun. 2017, pp. 733–742. [21] F. G. Van Zee et al., ‘‘The BLIS framework: Experiments in portability,’’ ACM Trans. Math. Softw., vol. 42, p. 12, Jun. 2016. [22] T. M. Smith, R. van de Geijn, M. Smelyanskiy, J. R. Hammond, and F. G. Van Zee, ‘‘Anatomy of high-performance many-threaded matrix multiplication,’’ in Proc. IEEE 28th Int. Parallel Distrib. Process. Symp. (IPDPS), May 2014, pp. 1049–1059. [23] S. Catalán, F. D. Igual, R. Mayo, R. Rodríguez-Sánchez, and E. S. Quintana-Ortí, ‘‘Architecture-aware configuration and scheduling of matrix multiplication on asymmetric multicore processors,’’ Cluster Comput., vol. 19, no. 3, pp. 1037–1051, 2016. [24] Extrae User Guide Manual for Version 2.5.1, Barcelona Supercomputing Center, Barcelona, Spain, 2016. [25] J. A. Gunnels, F. G. Gustavson, G. M. Henry, and R. A. van de Geijn, ‘‘FLAME: Formal linear algebra methods environment,’’ ACM Trans. Math. Softw., vol. 27, no. 4, pp. 422–455, 2001. [26] P. Strazdins, ‘‘A comparison of lookahead and algorithmic blocking techniques for parallel matrix factorization,’’ Dept. Comput. Sci., The Austral. Nat. Univ., Canberra, ACT, Australia, Tech. Rep. TR-CS-98-07, 1998. [27] A. M. Castaldo, R. C. Whaley, and S. Samuel, ‘‘Scaling LAPACK panel operations using parallel cache assignment,’’ ACM Trans. Math. Soft., vol. 39, p. 22, Jul. 2013. SANDRA CATALÁN received the B.Sc. and M.Sc. degrees in intelligent systems and the Ph.D. degree in computer science from Universidad Jaume I, Castelló de la Plana, Spain, in 2012, 2013, and 2018, respectively. She joined the Exa2Green Project, in 2012, and the INTER- TWinE Project, in 2018. In 2018, she was a Postdoctoral Researcher, where she joined the Project Fujitsu-BSC: Porting and Optimization of Math Libraries, Barcelona Supercomputing Center (BSC). She has also been a Visiting Researcher with the Foundations of Cognitive Computing Group, IBM Research–Zurich, Switzerland, also with The University of Texas in Austin, USA, and also with the Parallel Programming Models Group, Barcelona Supercomputing Center, Barcelona, Spain. Her current research interests include moderate-scale clusters and low-power processors, and parallel algorithms for numerical linear algebra. 17632 VOLUME 7, 2019 S. Catalán et al.: Case for Malleable Thread-Level Linear Algebra Libraries: LU Factorization With Partial Pivoting JOSÉ R. HERRERO has been teaching with the Barcelona School of Informatics (FIB), since 1994, where he has taught 15 different courses corresponding to several areas (computer architecture, operating systems, and parallel programming). He has carried out the duties of the Vice-Dean Head of academic studies and the Vice Dean for Institutional and International Relations with FIB. He has combined these management and teaching tasks with research in HPC, mainly in high performance scientific computing. This research work is made tangible in dozens of articles published in scientific magazines and international conferences. He has done research stays in several research centers (UCI, USA; IST, Portugal; NTUA, Greece; BSC, Spain; QUB, UK; ECM, France; and UJI, Spain). He regularly takes part in program committees and acts as an Associate Editor and a Reviewer for scientific publications. He is currently an Associate Professor with the Computer Architecture Department, Universitat Politècnica de Catalunya, BarcelonaTech. ENRIQUE S. QUINTANA-ORTÍ received the bachelor’s and Ph.D. degrees in computer sciences from the Universidad Politecnica de Valencia, Spain, in 1992 and 1996, respectively. He is currently a Professor in computer architecture with Universidad Jaume I, Castellón de la Plana, Spain. He has published more than 200 papers in international conferences and journals, and has contributed to software libraries like PLiC/SLICOT, MAGMA, FLARE, BLIS, and libflame for control theory and parallel linear algebra. Recently, he has participated/participates in EU projects on parallel programming, such as TEXT, INTERTWinE, and energy efficiency such as EXA2GREEN and OPRECOMP. His current research interests include parallel programming, linear algebra, energy consumption, transprecision computing and bioinformatics, and advanced architectures and hardware accelerators. He has also been a member of the programme committe for around 100 international conferences. In 2008, he was a recipient of an NVIDIA Professor Partnership Award for his contributions to the acceleration of dense linear algebra kernels on graphics processors, and was also a recipient of two awards from NASA for his contributions to fault-tolerant dense linear algebra libraries for space vehicles. RAFAEL RODRÍGUEZ-SÁNCHEZ received the M.S. and Ph.D. degrees in computer science from the University of Castilla-La Mancha, Spain, in 2010 and 2013, respectively. From 2008 to 2013, he was with the Albacete Research Institute of Informatics, University of Castilla-La Mancha, Spain. In 2013, he joined the Department of Engineering and Computer Sciences, University Jaume I, Castellón de la Plana, Spain. In 2017, he joined the Computer Architecture and Automatics Department, Universidad Complutense de Madrid, Spain. He has also been a Visiting Researcher with the Multimedia Lab, Ghent University, Belgium, and at ARM Ltd., Cambridge, U.K. He has more than 40 publications in these areas in international refereed journals and conference proceedings. His research interests include video coding, parallel programming, heterogeneous computing, optimization and adaptation of numerical libraries, and power and energy consumption. ROBERT VAN DE GEIJN received the Ph.D. degree in applied mathematics from the University of Maryland at College Park, College Park. He is currently a Professor of computer science and a Core Member of the Institute for Computational Engineering and Sciences, The University of Texas (UT) at Austin. He heads the FLAME Project, a collaboration between UT Austin, Universidad Jaume I, Spain, RWTH Aachen University, Germany, and Carnegie Mellon University, USA. This project pursues foundational research in the field of linear algebra libraries and has led to the development of the libflame and BLIS libraries, modern, and high-performance dense linear algebra libraries. One of the benefits of these libraries lies with their impact on the teaching of numerical linear algebra, for which he received the UT President’s Associates Teaching Excellence Award. His research interests include linear algebra, high-performance computing, parallel computing, and formal derivation of algorithms. VOLUME 7, 2019 17633