12 #ifndef MFEM_DEVICE_HPP
13 #define MFEM_DEVICE_HPP
30 enum Id:
unsigned long
118 enum MODES {SEQUENTIAL, ACCELERATED};
120 static bool device_env, mem_host_env, mem_device_env;
121 static Device device_singleton;
126 unsigned long backends;
137 char *device_option = NULL;
139 void operator=(
Device const&);
140 static Device& Get() {
return device_singleton; }
143 void Setup(
const int dev = 0);
147 void UpdateMemoryTypeAndClass();
158 static void Enable();
175 Device(
const std::string &device,
const int dev = 0)
176 : mode(
Device::SEQUENTIAL),
179 mpi_gpu_aware(false),
213 void Configure(
const std::string &device,
const int dev = 0);
225 static inline bool IsEnabled() {
return Get().mode == ACCELERATED; }
234 static inline bool Allows(
unsigned long b_mask)
235 {
return Get().backends & b_mask; }
264 { Get().mpi_gpu_aware = force; }
276 template <
typename T>
294 template <
typename T>
301 template <
typename T>
311 template <
typename T>
318 template <
typename T>
328 template <
typename T>
335 template <
typename T>
343 #endif // MFEM_DEVICE_HPP
static MemoryClass GetMemoryClass()
(DEPRECATED) Equivalent to GetDeviceMemoryClass().
static bool IsAvailable()
Return true if an actual device (e.g. GPU) has been configured.
static bool IsConfigured()
Return true if Configure() has been called previously.
[device] OCCA CUDA backend. Enabled when MFEM_USE_OCCA = YES and MFEM_USE_CUDA = YES.
static MemoryClass GetHostMemoryClass()
Get the current Host MemoryClass. This is the MemoryClass used by most MFEM host Memory objects...
[host] OCCA OpenMP backend. Enabled when MFEM_USE_OCCA = YES.
[device] CEED CUDA backend working together with the CUDA backend. Enabled when MFEM_USE_CEED = YES a...
[host] RAJA OpenMP backend. Enabled when MFEM_USE_RAJA = YES and MFEM_USE_OPENMP = YES...
Biwise-OR of all HIP backends.
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...
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...
T * Write(MemoryClass mc, int size)
Get write-only access to the memory with the given MemoryClass.
void Print(std::ostream &out=mfem::out)
Print the configuration of the MFEM virtual device object.
[device] RAJA CUDA backend. Enabled when MFEM_USE_RAJA = YES and MFEM_USE_CUDA = YES.
static bool IsEnabled()
Return true if any backend other than Backend::CPU is enabled.
static bool IsDisabled()
The opposite of IsEnabled().
void Configure(const std::string &device, const int dev=0)
Configure the Device backends.
Device()
Default constructor. Unless Configure() is called later, the default Backend::CPU will be used...
Id
In the documentation below, we use square brackets to indicate the type of the backend: host or devic...
[host] OCCA CPU backend: sequential execution on each MPI rank. Enabled when MFEM_USE_OCCA = YES...
The memory manager class.
Number of backends: from (1 << 0) to (1 << (NUM_BACKENDS-1)).
static MemoryClass GetDeviceMemoryClass()
Get the current Device MemoryClass. This is the MemoryClass used by most MFEM device kernels to acces...
static MemoryType GetDeviceMemoryType()
Get the current Device MemoryType. This is the MemoryType used by most MFEM classes when allocating m...
static MemoryType GetMemoryType()
(DEPRECATED) Equivalent to GetDeviceMemoryType().
Biwise-OR of all OpenMP backends.
[host] RAJA CPU backend: sequential execution on each MPI rank. Enabled when MFEM_USE_RAJA = YES...
[device] Debug backend: host memory is READ/WRITE protected while a device is in use. It allows to test the "device" code-path (using separate host/device memory pools and host <-> device transfers) without any GPU hardware.
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...
[host] Default CPU backend: sequential execution on each MPI rank.
Biwise-OR of all CUDA backends.
Biwise-OR of all CPU backends.
T * HostWrite(Memory< T > &mem, int size)
Shortcut to Write(const Memory<T> &mem, int size, false)
static void SetGPUAwareMPI(const bool force=true)
static MemoryType GetHostMemoryType()
Get the current Host MemoryType. This is the MemoryType used by most MFEM classes when allocating mem...
MemoryType
Memory types supported by MFEM.
[host] CEED CPU backend. GPU backends can still be used, but with expensive memory transfers...
[host] OpenMP backend. Enabled when MFEM_USE_OPENMP = YES.
static bool GetGPUAwareMPI()
static bool Allows(unsigned long b_mask)
Return true if any of the backends in the backend mask, b_mask, are allowed.
const T * HostRead(const Memory< T > &mem, int size)
Shortcut to Read(const Memory<T> &mem, int size, false)
MemoryClass GetMemoryClass(const Memory< T > &mem, bool on_dev)
Return the memory class to be used by the functions Read(), Write(), and ReadWrite(), while setting the device use flag in mem, if on_dev is true.
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, if on_dev = true, or the mfem::Device's HostMemoryClass, otherwise.
Host memory; using new[] and delete[].
T * ReadWrite(MemoryClass mc, int size)
Get read-write access to the memory with the given MemoryClass.
Biwise-OR of all OCCA backends.
Class used by MFEM to store pointers to host and/or device memory.
Biwise-OR of all RAJA backends.
bool UseDevice() const
Read the internal device flag.
Biwise-OR of all device backends.
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as ...
Bitwise-OR of all CEED backends.
[device] HIP backend. Enabled when MFEM_USE_HIP = YES.
T * HostReadWrite(Memory< T > &mem, int size)
Shortcut to ReadWrite(Memory<T> &mem, int size, false)
const T * Read(MemoryClass mc, int size) const
Get read-only access to the memory with the given MemoryClass.
[device] CUDA backend. Enabled when MFEM_USE_CUDA = YES.
MemoryClass
Memory classes identify sets of memory types.