12#ifndef MFEM_DEVICE_HPP
13#define MFEM_DEVICE_HPP
31 enum Id:
unsigned long
126 enum MODES {SEQUENTIAL, ACCELERATED};
128 static bool device_env, mem_host_env, mem_device_env, mem_types_set;
129 MFEM_ENZYME_INACTIVE
static MFEM_EXPORT
Device device_singleton;
131 MODES mode = Device::SEQUENTIAL;
137 bool destroy_mm =
false;
138 bool mpi_gpu_aware =
false;
148 char *device_option = NULL;
150 void operator=(
Device const&);
151 static Device& Get() {
return device_singleton; }
154 void Setup(
const int device_id = 0);
158 void UpdateMemoryTypeAndClass();
169 static void Enable();
186 Device(
const std::string &device,
const int dev = 0)
224 void Configure(
const std::string &device,
const int dev = 0);
247 static inline bool IsEnabled() {
return Get().mode == ACCELERATED; }
253 static inline int GetId() {
return Get().dev; }
259 static inline bool Allows(
unsigned long b_mask)
260 {
return Get().backends & b_mask; }
289 { Get().mpi_gpu_aware = force; }
The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as ...
static MemoryType GetHostMemoryType()
Get the current Host MemoryType. This is the MemoryType used by most MFEM classes when allocating mem...
static MemoryClass GetMemoryClass()
(DEPRECATED) Equivalent to GetDeviceMemoryClass().
static MemoryClass GetHostMemoryClass()
Get the current Host MemoryClass. This is the MemoryClass used by most MFEM host Memory objects.
static bool IsAvailable()
Return true if an actual device (e.g. GPU) has been configured.
static void SetGPUAwareMPI(const bool force=true)
static MemoryType GetMemoryType()
(DEPRECATED) Equivalent to GetDeviceMemoryType().
static bool IsConfigured()
Return true if Configure() has been called previously.
void Configure(const std::string &device, const int dev=0)
Configure the Device backends.
void Print(std::ostream &out=mfem::out)
Print the configuration of the MFEM virtual device object.
static bool Allows(unsigned long b_mask)
Return true if any of the backends in the backend mask, b_mask, are allowed.
Device(const std::string &device, const int dev=0)
Construct a Device and configure it based on the device string. See Configure() for more details.
static void SetMemoryTypes(MemoryType h_mt, MemoryType d_mt)
Set the default host and device MemoryTypes, h_mt and d_mt.
static bool GetGPUAwareMPI()
static MemoryClass GetDeviceMemoryClass()
Get the current Device MemoryClass. This is the MemoryClass used by most MFEM device kernels to acces...
static int GetId()
Get the device id of the configured device.
static bool IsEnabled()
Return true if any backend other than Backend::CPU is enabled.
Device()
Default constructor. Unless Configure() is called later, the default Backend::CPU will be used.
static MemoryType GetDeviceMemoryType()
Get the current Device MemoryType. This is the MemoryType used by most MFEM classes when allocating m...
static bool IsDisabled()
The opposite of IsEnabled().
Class used by MFEM to store pointers to host and/or device memory.
T * Write(MemoryClass mc, int size)
Get write-only access to the memory with the given MemoryClass.
T * ReadWrite(MemoryClass mc, int size)
Get read-write access to the memory with the given MemoryClass.
bool UseDevice() const
Read the internal device flag.
const T * Read(MemoryClass mc, int size) const
Get read-only access to the memory with the given MemoryClass.
const T * Read(const Memory< T > &mem, int size, bool on_dev=true)
Get a pointer for read access to mem with the mfem::Device's DeviceMemoryClass, if on_dev = true,...
MemoryClass GetMemoryClass(const Memory< T > &mem, bool on_dev)
Return the memory class to be used by the functions Read(), Write(), and ReadWrite(),...
T * HostReadWrite(Memory< T > &mem, int size)
Shortcut to ReadWrite(Memory<T> &mem, int size, false)
const T * HostRead(const Memory< T > &mem, int size)
Shortcut to Read(const Memory<T> &mem, int size, false)
T * Write(Memory< T > &mem, int size, bool on_dev=true)
Get a pointer for write access to mem with the mfem::Device's DeviceMemoryClass, if on_dev = true,...
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
MemoryClass
Memory classes identify sets of memory types.
T * ReadWrite(Memory< T > &mem, int size, bool on_dev=true)
Get a pointer for read+write access to mem with the mfem::Device's DeviceMemoryClass,...
T * HostWrite(Memory< T > &mem, int size)
Shortcut to Write(const Memory<T> &mem, int size, false)
MemoryType
Memory types supported by MFEM.
@ HOST
Host memory; using new[] and delete[].
Id
In the documentation below, we use square brackets to indicate the type of the backend: host or devic...
@ RAJA_OMP
[host] RAJA OpenMP backend. Enabled when MFEM_USE_RAJA = YES and MFEM_USE_OPENMP = YES.
@ RAJA_CUDA
[device] RAJA CUDA backend. Enabled when MFEM_USE_RAJA = YES and MFEM_USE_CUDA = YES.
@ DEBUG_DEVICE
[device] Debug backend: host memory is READ/WRITE protected while a device is in use....
@ RAJA_CPU
[host] RAJA CPU backend: sequential execution on each MPI rank. Enabled when MFEM_USE_RAJA = YES.
@ OMP
[host] OpenMP backend. Enabled when MFEM_USE_OPENMP = YES.
@ HIP
[device] HIP backend. Enabled when MFEM_USE_HIP = YES.
@ OCCA_OMP
[host] OCCA OpenMP backend. Enabled when MFEM_USE_OCCA = YES.
@ RAJA_HIP
[device] RAJA HIP backend. Enabled when MFEM_USE_RAJA = YES and MFEM_USE_HIP = YES.
@ OCCA_CUDA
[device] OCCA CUDA backend. Enabled when MFEM_USE_OCCA = YES and MFEM_USE_CUDA = YES.
@ CEED_CPU
[host] CEED CPU backend. GPU backends can still be used, but with expensive memory transfers....
@ OCCA_CPU
[host] OCCA CPU backend: sequential execution on each MPI rank. Enabled when MFEM_USE_OCCA = YES.
@ CEED_CUDA
[device] CEED CUDA backend working together with the CUDA backend. Enabled when MFEM_USE_CEED = YES a...
@ CPU
[host] Default CPU backend: sequential execution on each MPI rank.
@ CUDA
[device] CUDA backend. Enabled when MFEM_USE_CUDA = YES.
@ CEED_HIP
[device] CEED HIP backend working together with the HIP backend. Enabled when MFEM_USE_CEED = YES and...
@ RAJA_MASK
Biwise-OR of all RAJA backends.
@ DEVICE_MASK
Biwise-OR of all device backends.
@ CEED_MASK
Bitwise-OR of all CEED backends.
@ OCCA_MASK
Biwise-OR of all OCCA backends.
@ HIP_MASK
Biwise-OR of all HIP backends.
@ CPU_MASK
Biwise-OR of all CPU backends.
@ NUM_BACKENDS
Number of backends: from (1 << 0) to (1 << (NUM_BACKENDS-1)).
@ CUDA_MASK
Biwise-OR of all CUDA backends.
@ OMP_MASK
Biwise-OR of all OpenMP backends.