MFEM v4.8.0
Finite element discretization library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
mfem::BatchedLinAlg Class Reference

Class for performing batched linear algebra operations, potentially using accelerated algorithms (GPU BLAS or MAGMA). Accessed using static member functions. More...

#include <batched.hpp>

Public Types

enum  Backend { NATIVE , GPU_BLAS , MAGMA , NUM_BACKENDS }
 Available backends for implementations of batched algorithms. More...
 
enum  Op { N , T }
 Operation type (transposed or not transposed) More...
 

Static Public Member Functions

static void AddMult (const DenseTensor &A, const Vector &x, Vector &y, real_t alpha=1.0, real_t beta=1.0, Op op=Op::N)
 Computes y=αAopx+βy.
 
static void Mult (const DenseTensor &A, const Vector &x, Vector &y)
 Computes y=Ax (e.g. by calling AddMult(A,x,y,1,0,Op::N)).
 
static void MultTranspose (const DenseTensor &A, const Vector &x, Vector &y)
 Computes y=ATx (e.g. by calling AddMult(A,x,y,1,0,Op::T)).
 
static void Invert (DenseTensor &A)
 Replaces the block diagonal matrix A with its inverse A1.
 
static void LUFactor (DenseTensor &A, Array< int > &P)
 Replaces the block diagonal matrix A with its LU factors. The pivots are stored in P.
 
static void LUSolve (const DenseTensor &A, const Array< int > &P, Vector &x)
 Replaces x with A1x, given the LU factors A and pivots P of the block-diagonal matrix A.
 
static bool IsAvailable (Backend backend)
 Returns true if the requested backend is available.
 
static void SetActiveBackend (Backend backend)
 Set the default backend for batched linear algebra operations.
 
static Backend GetActiveBackend ()
 Get the default backend for batched linear algebra operations.
 
static const BatchedLinAlgBaseGet (Backend backend)
 Get the BatchedLinAlgBase object associated with a specific backend.
 

Detailed Description

Class for performing batched linear algebra operations, potentially using accelerated algorithms (GPU BLAS or MAGMA). Accessed using static member functions.

The static member functions will delegate to the active backend (which can be set using SetActiveBackend(), see BatchedLinAlg::Backend for all available backends and the order in which they will be chosen initially). Operations can be performed directly with a specific backend using Get().

Definition at line 31 of file batched.hpp.

Member Enumeration Documentation

◆ Backend

Available backends for implementations of batched algorithms.

The initially active backend will be the first available backend in this order: MAGMA, GPU_BLAS, NATIVE.

Enumerator
NATIVE 

The standard MFEM backend, implemented using mfem::forall kernels. Not as performant as the other kernels.

GPU_BLAS 

Either cuBLAS or hipBLAS, depending on whether MFEM is using CUDA or HIP. Not available otherwise.

MAGMA 

MAGMA backend, only available if MFEM is compiled with MAGMA support.

NUM_BACKENDS 

Counter for the number of backends.

Definition at line 38 of file batched.hpp.

◆ Op

Operation type (transposed or not transposed)

Enumerator

Not transposed.

Transposed.

Definition at line 53 of file batched.hpp.

Member Function Documentation

◆ AddMult()

void mfem::BatchedLinAlg::AddMult ( const DenseTensor & A,
const Vector & x,
Vector & y,
real_t alpha = 1.0,
real_t beta = 1.0,
Op op = Op::N )
static

Computes y=αAopx+βy.

Aop is either A or AT depending on the value of op. A is a block diagonal matrix, represented by the DenseTensor A with shape (m, n, n_mat). x has shape (tr?m:n, k, n_mat), and y has shape (tr?n:m, k, n_mat), where 'tr' is true in the transposed case.

Definition at line 54 of file batched.cpp.

◆ Get()

const BatchedLinAlgBase & mfem::BatchedLinAlg::Get ( BatchedLinAlg::Backend backend)
static

Get the BatchedLinAlgBase object associated with a specific backend.

This allows the user to perform specific operations with a backend different from the active backend.

Definition at line 103 of file batched.cpp.

◆ GetActiveBackend()

BatchedLinAlg::Backend mfem::BatchedLinAlg::GetActiveBackend ( )
static

Get the default backend for batched linear algebra operations.

Definition at line 98 of file batched.cpp.

◆ Invert()

void mfem::BatchedLinAlg::Invert ( DenseTensor & A)
static

Replaces the block diagonal matrix A with its inverse A1.

A is represented by the DenseTensor A with shape (m, m, n_mat).

Definition at line 71 of file batched.cpp.

◆ IsAvailable()

bool mfem::BatchedLinAlg::IsAvailable ( BatchedLinAlg::Backend backend)
static

Returns true if the requested backend is available.

The available backends depend on which third-party libraries MFEM is compiled with, and whether the CUDA/HIP device is enabled.

Definition at line 87 of file batched.cpp.

◆ LUFactor()

void mfem::BatchedLinAlg::LUFactor ( DenseTensor & A,
Array< int > & P )
static

Replaces the block diagonal matrix A with its LU factors. The pivots are stored in P.

A is represented by the DenseTensor A with shape (n, n, n_mat). On output, P has shape (n, n_mat).

Definition at line 76 of file batched.cpp.

◆ LUSolve()

void mfem::BatchedLinAlg::LUSolve ( const DenseTensor & A,
const Array< int > & P,
Vector & x )
static

Replaces x with A1x, given the LU factors A and pivots P of the block-diagonal matrix A.

The LU factors and pivots of A should be obtained by first calling LUFactor(). A has shape (n, n, n_mat) and x has shape (n, n_rhs, n_mat).

Warning
LUSolve() and LUFactor() should be called using the same backend because of potential incompatibilities (e.g. 0-based or 1-based indexing).

Definition at line 81 of file batched.cpp.

◆ Mult()

void mfem::BatchedLinAlg::Mult ( const DenseTensor & A,
const Vector & x,
Vector & y )
static

Computes y=Ax (e.g. by calling AddMult(A,x,y,1,0,Op::N)).

Definition at line 60 of file batched.cpp.

◆ MultTranspose()

void mfem::BatchedLinAlg::MultTranspose ( const DenseTensor & A,
const Vector & x,
Vector & y )
static

Computes y=ATx (e.g. by calling AddMult(A,x,y,1,0,Op::T)).

Definition at line 65 of file batched.cpp.

◆ SetActiveBackend()

void mfem::BatchedLinAlg::SetActiveBackend ( BatchedLinAlg::Backend backend)
static

Set the default backend for batched linear algebra operations.

Definition at line 92 of file batched.cpp.


The documentation for this class was generated from the following files: