MFEM v4.8.0
Finite element discretization library
Loading...
Searching...
No Matches
gpu_blas.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12#ifndef MFEM_GPU_BLAS_LINALG
13#define MFEM_GPU_BLAS_LINALG
14
15#include "batched.hpp"
17#include <cstddef> // std::nullptr_t
18
19#if defined(MFEM_USE_CUDA)
20#include <cublas_v2.h>
21#elif defined(MFEM_USE_HIP)
22#include <hipblas/hipblas.h>
23#endif
24
25namespace mfem
26{
27
28/// @brief Singleton class represented a cuBLAS or hipBLAS handle.
29///
30/// If MFEM is compiled without CUDA or HIP, then this class has no effect.
32{
33#if defined(MFEM_USE_CUDA)
34 using HandleType = cublasHandle_t;
35#elif defined(MFEM_USE_HIP)
36 using HandleType = hipblasHandle_t;
37#else
38 using HandleType = std::nullptr_t;
39#endif
40
41 HandleType handle = nullptr; ///< The internal handle.
42 GPUBlas(); ///< Create the handle.
43 ~GPUBlas(); ///< Destroy the handle.
44 static GPUBlas &Instance(); ///< Get the unique instance.
45public:
46 /// Return the handle, creating it if needed.
47 static HandleType Handle();
48 /// Enable atomic operations.
49 static void EnableAtomics();
50 /// Disable atomic operations.
51 static void DisableAtomics();
52};
53
54#ifdef MFEM_USE_CUDA_OR_HIP
55
57{
58public:
59 void AddMult(const DenseTensor &A, const Vector &x, Vector &y,
60 real_t alpha = 1.0, real_t beta = 1.0,
61 Op op = Op::N) const override;
62 void Invert(DenseTensor &A) const override;
63 void LUFactor(DenseTensor &A, Array<int> &P) const override;
64 void LUSolve(const DenseTensor &LU, const Array<int> &P,
65 Vector &x) const override;
66};
67
68#endif // MFEM_USE_CUDA_OR_HIP
69
70} // namespace mfem
71
72#endif // MFEM_GPU_BLAS_LINALG
Abstract base clase for batched linear algebra operations.
Definition batched.hpp:122
Op
Operation type (transposed or not transposed)
Definition batched.hpp:54
Rank 3 tensor (array of matrices)
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 override
See BatchedLinAlg::AddMult.
Definition gpu_blas.cpp:84
void LUSolve(const DenseTensor &LU, const Array< int > &P, Vector &x) const override
See BatchedLinAlg::LUSolve.
Definition gpu_blas.cpp:132
void LUFactor(DenseTensor &A, Array< int > &P) const override
See BatchedLinAlg::LUFactor.
Definition gpu_blas.cpp:109
void Invert(DenseTensor &A) const override
See BatchedLinAlg::Invert.
Definition gpu_blas.cpp:162
Singleton class represented a cuBLAS or hipBLAS handle.
Definition gpu_blas.hpp:32
static void EnableAtomics()
Enable atomic operations.
Definition gpu_blas.cpp:52
static void DisableAtomics()
Disable atomic operations.
Definition gpu_blas.cpp:53
static HandleType Handle()
Return the handle, creating it if needed.
Definition gpu_blas.cpp:43
Vector data type.
Definition vector.hpp:82
Vector beta
const real_t alpha
Definition ex15.cpp:369
float real_t
Definition config.hpp:43