21BatchedLinAlg::BatchedLinAlg()
23 backends[
NATIVE].reset(
new NativeBatchedLinAlg);
27#ifdef MFEM_USE_CUDA_OR_HIP
28 backends[
GPU_BLAS].reset(
new GPUBlasBatchedLinAlg);
32 backends[
MAGMA].reset(
new MagmaBatchedLinAlg);
35#if defined(MFEM_USE_MAGMA)
36 active_backend =
MAGMA;
37#elif defined(MFEM_USE_CUDA_OR_HIP)
49BatchedLinAlg &BatchedLinAlg::Instance()
51 static BatchedLinAlg instance;
63 Get(Instance().active_backend).
Mult(A, x, y);
85 Get(Instance().active_backend).
LUSolve(A, P, x);
90 return Instance().backends[backend] !=
nullptr;
95 MFEM_VERIFY(
IsAvailable(backend),
"Requested backend not supported.");
96 Instance().active_backend = backend;
101 return Instance().active_backend;
106 auto &backend_ptr = Instance().backends[backend];
107 MFEM_VERIFY(backend_ptr,
"Requested backend not supported.")
120 AddMult(A, x, y, 1.0, 0.0, Op::T);
127 const int *d_info = info_array.
Read();
129 info_array.
Size(), status,
130 [=] MFEM_HOST_DEVICE (
int i,
int &r) { r |= d_info[i]; },
132 MFEM_VERIFY(status == 0, message);
int Size() const
Return the logical size of the array.
const T * Read(bool on_dev=true) const
Shortcut for mfem::Read(a.GetMemory(), a.Size(), on_dev).
Abstract base clase for batched linear algebra operations.
virtual void Mult(const DenseTensor &A, const Vector &x, Vector &y) const
See BatchedLinAlg::Mult.
virtual void Invert(DenseTensor &A) const =0
See BatchedLinAlg::Invert.
virtual void LUFactor(DenseTensor &A, Array< int > &P) const =0
See BatchedLinAlg::LUFactor.
virtual void MultTranspose(const DenseTensor &A, const Vector &x, Vector &y) const
See BatchedLinAlg::MultTranspose.
virtual void LUSolve(const DenseTensor &LU, const Array< int > &P, Vector &x) const =0
See BatchedLinAlg::LUSolve.
virtual void AddMult(const DenseTensor &A, const Vector &x, Vector &y, real_t alpha=1.0, real_t beta=1.0, Op op=Op::N) const =0
See BatchedLinAlg::AddMult.
static void Mult(const DenseTensor &A, const Vector &x, Vector &y)
Computes (e.g. by calling AddMult(A,x,y,1,0,Op::N)).
Backend
Available backends for implementations of batched algorithms.
@ 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.
@ NATIVE
The standard MFEM backend, implemented using mfem::forall kernels. Not as performant as the other ker...
static const BatchedLinAlgBase & Get(Backend backend)
Get the BatchedLinAlgBase object associated with a specific backend.
static void MultTranspose(const DenseTensor &A, const Vector &x, Vector &y)
Computes (e.g. by calling AddMult(A,x,y,1,0,Op::T)).
static Backend GetActiveBackend()
Get the default backend for batched linear algebra operations.
static bool IsAvailable(Backend backend)
Returns true if the requested backend is available.
static void LUFactor(DenseTensor &A, Array< int > &P)
Replaces the block diagonal matrix with its LU factors. The pivots are stored in P.
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 .
static void SetActiveBackend(Backend backend)
Set the default backend for batched linear algebra operations.
Op
Operation type (transposed or not transposed)
static void LUSolve(const DenseTensor &A, const Array< int > &P, Vector &x)
Replaces with , given the LU factors A and pivots P of the block-diagonal matrix .
static void Invert(DenseTensor &A)
Replaces the block diagonal matrix with its inverse .
Rank 3 tensor (array of matrices)
static bool Allows(unsigned long b_mask)
Return true if any of the backends in the backend mask, b_mask, are allowed.
void reduce(int N, T &res, B &&body, const R &reducer, bool use_dev, Array< T > &workspace)
Performs a 1D reduction on the range [0,N). res initial value and where the result will be written....
void VerifyBatchedLUInfo(const Array< int > &info_array, const char *message)
Check that all batched LU info values are zero.
@ HIP_MASK
Biwise-OR of all HIP backends.
@ CUDA_MASK
Biwise-OR of all CUDA backends.