12 #ifndef MFEM_DEVICE_HPP
13 #define MFEM_DEVICE_HPP
99 enum MODES {SEQUENTIAL, ACCELERATED};
101 static Device device_singleton;
106 unsigned long backends;
114 void operator=(
Device const&);
115 static Device& Get() {
return device_singleton; }
118 void Setup(
const int dev = 0);
122 void UpdateMemoryTypeAndClass();
133 static void Enable();
143 : mode(
Device::SEQUENTIAL),
156 Device(
const std::string &device,
const int dev = 0)
157 : mode(
Device::SEQUENTIAL),
183 void Configure(
const std::string &device,
const int dev = 0);
195 static inline bool IsEnabled() {
return Get().mode == ACCELERATED; }
204 static inline bool Allows(
unsigned long b_mask)
205 {
return Get().backends & b_mask; }
224 template <
typename T>
239 template <
typename T>
248 template <
typename T>
263 template <
typename T>
272 template <
typename T>
287 template <
typename T>
295 #endif // MFEM_DEVICE_HPP
static MemoryClass GetMemoryClass()
Get the current Device MemoryClass. This is the MemoryClass used by most MFEM device kernels to acces...
static bool IsAvailable()
Return true if an actual device (e.g. GPU) has been configured.
[host] OpenMP backend. Enabled when MFEM_USE_OPENMP = YES.
static bool IsConfigured()
Return true if Configure() has been called previously.
T * Write(Memory< T > &mem, int size, bool on_dev=true)
Get a pointer for write access to mem with the mfem::Device MemoryClass, 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.
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...
[device] OCCA CUDA backend. Enabled when MFEM_USE_OCCA = YES and MFEM_USE_CUDA = YES.
[host] RAJA CPU backend: sequential execution on each MPI rank. Enabled when MFEM_USE_RAJA = YES...
[host] RAJA OpenMP backend. Enabled when MFEM_USE_RAJA = YES and MFEM_USE_OPENMP = YES...
Number of backends: from (1 << 0) to (1 << (NUM_BACKENDS-1)).
static MemoryType GetMemoryType()
Get the current Device MemoryType. This is the MemoryType used by most MFEM classes when allocating m...
Biwise-OR of all OpenMP backends.
[host] OCCA OpenMP backend. Enabled when MFEM_USE_OCCA = YES.
[host] Default CPU backend: sequential execution on each MPI rank.
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 MemoryClass, if on_dev = true...
Biwise-OR of all CUDA backends.
Biwise-OR of all CPU backends.
MemoryType
Memory types supported by MFEM.
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)
T * ReadWrite(Memory< T > &mem, int size, bool on_dev=true)
Get a pointer for read+write access to mem with the mfem::Device MemoryClass, if on_dev = true...
const T * HostReadWrite(const Memory< T > &mem, int size)
Shortcut to ReadWrite(const Memory<T> &mem, int size, false)
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.
Id
In the documentation below, we use square brackets to indicate the type of the backend: host or devic...
Class used by MFEM to store pointers to host and/or device memory.
Biwise-OR of all RAJA backends.
const T * HostWrite(const Memory< T > &mem, int size)
Shortcut to Write(const Memory<T> &mem, int size, false)
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 ...
[device] RAJA CUDA backend. Enabled when MFEM_USE_RAJA = YES and MFEM_USE_CUDA = YES.
const T * Read(MemoryClass mc, int size) const
Get read-only access to the memory with the given MemoryClass.
MemoryClass
Memory classes identify subsets of memory types.
[host] OCCA CPU backend: sequential execution on each MPI rank. Enabled when MFEM_USE_OCCA = YES...
[device] CUDA backend. Enabled when MFEM_USE_CUDA = YES.