12 #ifndef MFEM_DEVICE_HPP
13 #define MFEM_DEVICE_HPP
30 enum Id:
unsigned long
122 enum MODES {SEQUENTIAL, ACCELERATED};
124 static bool device_env, mem_host_env, mem_device_env;
125 static Device device_singleton;
130 unsigned long backends;
141 char *device_option = NULL;
143 void operator=(
Device const&);
144 static Device& Get() {
return device_singleton; }
147 void Setup(
const int dev = 0);
151 void UpdateMemoryTypeAndClass();
162 static void Enable();
179 Device(
const std::string &device,
const int dev = 0)
180 : mode(
Device::SEQUENTIAL),
183 mpi_gpu_aware(false),
225 void Configure(
const std::string &device,
const int dev = 0);
237 static inline bool IsEnabled() {
return Get().mode == ACCELERATED; }
246 static inline bool Allows(
unsigned long b_mask)
247 {
return Get().backends & b_mask; }
276 { Get().mpi_gpu_aware = force; }
288 template <
typename T>
306 template <
typename T>
313 template <
typename T>
323 template <
typename T>
330 template <
typename T>
340 template <
typename T>
347 template <
typename T>
355 #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...
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...
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.
[device] CEED HIP backend working together with the HIP backend. Enabled when MFEM_USE_CEED = YES and...
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.
[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. As 'DEBUG' is sometimes used as a macro, _DEVICE has been added to avoid conflicts.