MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
mfem::Device Class Reference

The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as CUDA, OCCA, RAJA and OpenMP. More...

#include <device.hpp>

Public Member Functions

 Device ()
 Default constructor. Unless Configure() is called later, the default Backend::CPU will be used.
 
 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.
 
 ~Device ()
 Destructor.
 
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 Public Member Functions

static void SetMemoryTypes (MemoryType h_mt, MemoryType d_mt)
 Set the default host and device MemoryTypes, h_mt and d_mt.
 
static bool IsConfigured ()
 Return true if Configure() has been called previously.
 
static bool IsAvailable ()
 Return true if an actual device (e.g. GPU) has been configured.
 
static bool IsEnabled ()
 Return true if any backend other than Backend::CPU is enabled.
 
static bool IsDisabled ()
 The opposite of IsEnabled().
 
static int GetId ()
 Get the device id of the configured device.
 
static bool Allows (unsigned long b_mask)
 Return true if any of the backends in the backend mask, b_mask, are allowed.
 
static MemoryType GetHostMemoryType ()
 Get the current Host MemoryType. This is the MemoryType used by most MFEM classes when allocating memory used on the host.
 
static MemoryClass GetHostMemoryClass ()
 Get the current Host MemoryClass. This is the MemoryClass used by most MFEM host Memory objects.
 
static MemoryType GetDeviceMemoryType ()
 Get the current Device MemoryType. This is the MemoryType used by most MFEM classes when allocating memory to be used with device kernels.
 
static MemoryType GetMemoryType ()
 (DEPRECATED) Equivalent to GetDeviceMemoryType().
 
static MemoryClass GetDeviceMemoryClass ()
 Get the current Device MemoryClass. This is the MemoryClass used by most MFEM device kernels to access Memory objects.
 
static MemoryClass GetMemoryClass ()
 (DEPRECATED) Equivalent to GetDeviceMemoryClass().
 
static void SetGPUAwareMPI (const bool force=true)
 
static bool GetGPUAwareMPI ()
 

Friends

class MemoryManager
 

Detailed Description

The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as CUDA, OCCA, RAJA and OpenMP.

This class represents a "virtual device" with the following properties:

  • At most one object of this class can be constructed and that object is controlled by its static methods.
  • If no Device object is constructed, the static methods will use a default global object which is never configured and always uses Backend::CPU.
  • Once configured, the object cannot be re-configured during the program lifetime.
  • MFEM classes use this object to determine where (host or device) to perform an operation and which backend implementation to use.
  • Multiple backends can be configured at the same time; currently, a fixed priority order is used to select a specific backend from the list of configured backends. See the Backend class and the Configure() method in this class for details.

Definition at line 122 of file device.hpp.

Constructor & Destructor Documentation

◆ Device() [1/2]

mfem::Device::Device ( )

Default constructor. Unless Configure() is called later, the default Backend::CPU will be used.

Note
At most one Device object can be constructed during the lifetime of a program.
This object should be destroyed after all other MFEM objects that use the Device are destroyed.

Definition at line 73 of file device.cpp.

◆ Device() [2/2]

mfem::Device::Device ( const std::string & device,
const int dev = 0 )
inline

Construct a Device and configure it based on the device string. See Configure() for more details.

Note
At most one Device object can be constructed during the lifetime of a program.
This object should be destroyed after all other MFEM objects that use the Device are destroyed.

Definition at line 186 of file device.hpp.

◆ ~Device()

mfem::Device::~Device ( )

Destructor.

Definition at line 151 of file device.cpp.

Member Function Documentation

◆ Allows()

static bool mfem::Device::Allows ( unsigned long b_mask)
inlinestatic

Return true if any of the backends in the backend mask, b_mask, are allowed.

This method can be used with any of the Backend::Id constants, the Backend::*_MASK, or combinations of those.

Definition at line 259 of file device.hpp.

◆ Configure()

void mfem::Device::Configure ( const std::string & device,
const int dev = 0 )

Configure the Device backends.

The string parameter device must be a comma-separated list of backend string names (see below). The dev argument specifies the ID of the actual devices (e.g. GPU) to use. The available backends are described by the Backend class. The string name of a backend is the lowercase version of the Backend::Id enumeration constant with '_' replaced by '-', e.g. the string name of 'RAJA_CPU' is 'raja-cpu'. The string name of the debug backend (Backend::Id 'DEBUG_DEVICE') is exceptionally set to 'debug'. The 'cpu' backend is always enabled with lowest priority. The current backend priority from highest to lowest is: 'ceed-cuda', 'occa-cuda', 'raja-cuda', 'cuda', 'ceed-hip', 'hip', 'debug', 'occa-omp', 'raja-omp', 'omp', 'ceed-cpu', 'occa-cpu', 'raja-cpu', 'cpu'. Multiple backends can be configured at the same time. Only one 'occa-*' backend can be configured at a time. The backend 'occa-cuda' enables the 'cuda' backend unless 'raja-cuda' is already enabled. The backend 'occa-omp' enables the 'omp' backend (if MFEM was built with MFEM_USE_OPENMP=YES) unless 'raja-omp' is already enabled. Only one 'ceed-*' backend can be configured at a time. The backend 'ceed-cpu' delegates to a libCEED CPU backend the setup and evaluation of the operator. The backend 'ceed-cuda' delegates to a libCEED CUDA backend the setup and evaluation of operators and enables the 'cuda' backend to avoid transfers between host and device. The backend 'ceed-hip' delegates to a libCEED HIP backend the setup and evaluation of operators and enables the 'hip' backend to avoid transfers between host and device. The 'debug' backend should not be combined with other device backends.

Definition at line 183 of file device.cpp.

◆ GetDeviceMemoryClass()

static MemoryClass mfem::Device::GetDeviceMemoryClass ( )
inlinestatic

Get the current Device MemoryClass. This is the MemoryClass used by most MFEM device kernels to access Memory objects.

Definition at line 282 of file device.hpp.

◆ GetDeviceMemoryType()

static MemoryType mfem::Device::GetDeviceMemoryType ( )
inlinestatic

Get the current Device MemoryType. This is the MemoryType used by most MFEM classes when allocating memory to be used with device kernels.

Definition at line 274 of file device.hpp.

◆ GetGPUAwareMPI()

static bool mfem::Device::GetGPUAwareMPI ( )
inlinestatic

Definition at line 291 of file device.hpp.

◆ GetHostMemoryClass()

static MemoryClass mfem::Device::GetHostMemoryClass ( )
inlinestatic

Get the current Host MemoryClass. This is the MemoryClass used by most MFEM host Memory objects.

Definition at line 269 of file device.hpp.

◆ GetHostMemoryType()

static MemoryType mfem::Device::GetHostMemoryType ( )
inlinestatic

Get the current Host MemoryType. This is the MemoryType used by most MFEM classes when allocating memory used on the host.

Definition at line 265 of file device.hpp.

◆ GetId()

static int mfem::Device::GetId ( )
inlinestatic

Get the device id of the configured device.

Definition at line 253 of file device.hpp.

◆ GetMemoryClass()

static MemoryClass mfem::Device::GetMemoryClass ( )
inlinestatic

(DEPRECATED) Equivalent to GetDeviceMemoryClass().

Deprecated
Use GetDeviceMemoryClass() instead.

Definition at line 286 of file device.hpp.

◆ GetMemoryType()

static MemoryType mfem::Device::GetMemoryType ( )
inlinestatic

(DEPRECATED) Equivalent to GetDeviceMemoryType().

Deprecated
Use GetDeviceMemoryType() instead.

Definition at line 278 of file device.hpp.

◆ IsAvailable()

static bool mfem::Device::IsAvailable ( )
inlinestatic

Return true if an actual device (e.g. GPU) has been configured.

Definition at line 244 of file device.hpp.

◆ IsConfigured()

static bool mfem::Device::IsConfigured ( )
inlinestatic

Return true if Configure() has been called previously.

Definition at line 241 of file device.hpp.

◆ IsDisabled()

static bool mfem::Device::IsDisabled ( )
inlinestatic

The opposite of IsEnabled().

Definition at line 250 of file device.hpp.

◆ IsEnabled()

static bool mfem::Device::IsEnabled ( )
inlinestatic

Return true if any backend other than Backend::CPU is enabled.

Definition at line 247 of file device.hpp.

◆ Print()

void mfem::Device::Print ( std::ostream & out = mfem::out)

Print the configuration of the MFEM virtual device object.

Definition at line 286 of file device.cpp.

◆ SetGPUAwareMPI()

static void mfem::Device::SetGPUAwareMPI ( const bool force = true)
inlinestatic

Definition at line 288 of file device.hpp.

◆ SetMemoryTypes()

void mfem::Device::SetMemoryTypes ( MemoryType h_mt,
MemoryType d_mt )
static

Set the default host and device MemoryTypes, h_mt and d_mt.

The host and device MemoryTypes are also set to be dual to each other.

These two MemoryTypes are used by most MFEM classes when allocating memory used on host and device, respectively.

This method can only be called before Device construction and configuration, and the specified memory types must be compatible with the subsequent Device configuration.

Definition at line 263 of file device.cpp.

Friends And Related Symbol Documentation

◆ MemoryManager

friend class MemoryManager
friend

Definition at line 125 of file device.hpp.


The documentation for this class was generated from the following files: