MFEM  v4.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
Public Member Functions | Static Public Member Functions | List of all members
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. More...
 
 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. More...
 
 ~Device ()
 Destructor. More...
 
void Configure (const std::string &device, const int dev=0)
 Configure the Device backends. More...
 
void Print (std::ostream &out=mfem::out)
 Print the configuration of the MFEM virtual device object. More...
 

Static Public Member Functions

static bool IsConfigured ()
 Return true if Configure() has been called previously. More...
 
static bool IsAvailable ()
 Return true if an actual device (e.g. GPU) has been configured. More...
 
static bool IsEnabled ()
 Return true if any backend other than Backend::CPU is enabled. More...
 
static bool IsDisabled ()
 The opposite of IsEnabled(). More...
 
static bool Allows (unsigned long b_mask)
 Return true if any of the backends in the backend mask, b_mask, are allowed. More...
 
static MemoryType GetMemoryType ()
 Get the current Device MemoryType. This is the MemoryType used by most MFEM classes when allocating memory to be used with device kernels. More...
 
static MemoryClass GetMemoryClass ()
 Get the current Device MemoryClass. This is the MemoryClass used by most MFEM device kernels to access Memory objects. More...
 

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:

Definition at line 96 of file device.hpp.

Constructor & Destructor Documentation

mfem::Device::Device ( )
inline

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 142 of file device.hpp.

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 156 of file device.hpp.

mfem::Device::~Device ( )

Destructor.

Definition at line 54 of file device.cpp.

Member Function Documentation

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 204 of file device.hpp.

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 'cpu' backend is always enabled with lowest priority. The current backend priority from highest to lowest is: 'occa-cuda', 'raja-cuda', 'cuda', 'occa-omp', 'raja-omp', 'omp', '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.

Definition at line 59 of file device.cpp.

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

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

Definition at line 214 of file device.hpp.

static MemoryType mfem::Device::GetMemoryType ( )
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 210 of file device.hpp.

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

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

Definition at line 192 of file device.hpp.

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

Return true if Configure() has been called previously.

Definition at line 189 of file device.hpp.

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

The opposite of IsEnabled().

Definition at line 198 of file device.hpp.

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

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

Definition at line 195 of file device.hpp.

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

Print the configuration of the MFEM virtual device object.

Definition at line 98 of file device.cpp.


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