MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
mfem::Memory< T > Class Template Reference

Class used by MFEM to store pointers to host and/or device memory. More...

#include <mem_manager.hpp>

Public Member Functions

 Memory ()
 
 Memory (const Memory &orig)=default
 Copy constructor: default.
 
 Memory (Memory &&orig)
 
Memoryoperator= (const Memory &orig)=default
 Copy-assignment operator: default.
 
Memoryoperator= (Memory &&orig)
 
 Memory (int size)
 Allocate host memory for size entries.
 
 Memory (int size, MemoryType mt)
 Allocate memory for size entries with the given MemoryType mt.
 
 Memory (int size, MemoryType h_mt, MemoryType d_mt)
 Allocate memory for size entries with the given host MemoryType h_mt and device MemoryType d_mt.
 
 Memory (T *ptr, int size, bool own)
 Wrap an externally allocated host pointer, ptr with the current host memory type returned by MemoryManager::GetHostMemoryType().
 
 Memory (T *ptr, int size, MemoryType mt, bool own)
 Wrap an externally allocated pointer, ptr, of the given MemoryType.
 
 Memory (const Memory &base, int offset, int size)
 Alias constructor. Create a Memory object that points inside the Memory object base.
 
 ~Memory ()=default
 Destructor: default.
 
bool OwnsHostPtr () const
 Return true if the host pointer is owned. Ownership indicates whether the pointer will be deleted by the method Delete().
 
void SetHostPtrOwner (bool own) const
 Set/clear the ownership flag for the host pointer. Ownership indicates whether the pointer will be deleted by the method Delete().
 
bool OwnsDevicePtr () const
 Return true if the device pointer is owned. Ownership indicates whether the pointer will be deleted by the method Delete().
 
void SetDevicePtrOwner (bool own) const
 Set/clear the ownership flag for the device pointer. Ownership indicates whether the pointer will be deleted by the method Delete().
 
void ClearOwnerFlags () const
 Clear the ownership flags for the host and device pointers, as well as any internal data allocated by the Memory object.
 
bool UseDevice () const
 Read the internal device flag.
 
void UseDevice (bool use_dev) const
 Set the internal device flag.
 
int Capacity () const
 Return the size of the allocated memory.
 
void Reset ()
 Reset the memory to be empty, ensuring that Delete() will be a no-op.
 
void Reset (MemoryType host_mt)
 Reset the memory and set the host memory type.
 
bool Empty () const
 Return true if the Memory object is empty, see Reset().
 
void New (int size)
 Allocate host memory for size entries with the current host memory type returned by MemoryManager::GetHostMemoryType().
 
void New (int size, MemoryType mt)
 Allocate memory for size entries with the given MemoryType.
 
void New (int size, MemoryType h_mt, MemoryType d_mt)
 Allocate memory for size entries with the given host MemoryType h_mt and device MemoryType d_mt.
 
void Wrap (T *ptr, int size, bool own)
 Wrap an externally allocated host pointer, ptr with the current host memory type returned by MemoryManager::GetHostMemoryType().
 
void Wrap (T *ptr, int size, MemoryType mt, bool own)
 Wrap an externally allocated pointer, ptr, of the given MemoryType.
 
void Wrap (T *h_ptr, T *d_ptr, int size, MemoryType h_mt, bool own, bool valid_host=false, bool valid_device=true)
 
void MakeAlias (const Memory &base, int offset, int size)
 Create a memory object that points inside the memory object base.
 
void SetDeviceMemoryType (MemoryType d_mt)
 Set the device MemoryType to be used by the Memory object.
 
void Delete ()
 Delete the owned pointers and reset the Memory object.
 
void DeleteDevice (bool copy_to_host=true)
 Delete the device pointer, if owned. If copy_to_host is true and the data is valid only on device, move it to host before deleting. Invalidates the device memory.
 
T & operator[] (int idx)
 Array subscript operator for host memory.
 
const T & operator[] (int idx) const
 Array subscript operator for host memory, const version.
 
 operator T* ()
 Direct access to the host memory as T* (implicit conversion).
 
 operator const T * () const
 Direct access to the host memory as const T* (implicit conversion).
 
template<typename U >
 operator U* ()
 Direct access to the host memory via explicit typecast.
 
template<typename U >
 operator const U * () const
 Direct access to the host memory via explicit typecast, const version.
 
T * ReadWrite (MemoryClass mc, int size)
 Get read-write access to the memory with the given MemoryClass.
 
const T * Read (MemoryClass mc, int size) const
 Get read-only access to the memory with the given MemoryClass.
 
T * Write (MemoryClass mc, int size)
 Get write-only access to the memory with the given MemoryClass.
 
void Sync (const Memory &other) const
 Copy the host/device pointer validity flags from other to *this.
 
void SyncAlias (const Memory &base, int alias_size) const
 Update the alias Memory *this to match the memory location (all valid locations) of its base Memory, base.
 
MemoryType GetMemoryType () const
 Return a MemoryType that is currently valid. If both the host and the device pointers are currently valid, then the device memory type is returned.
 
MemoryType GetHostMemoryType () const
 Return the host MemoryType of the Memory object.
 
MemoryType GetDeviceMemoryType () const
 Return the device MemoryType of the Memory object. If the device MemoryType is not set, return MemoryType::DEFAULT.
 
bool HostIsValid () const
 Return true if host pointer is valid.
 
bool DeviceIsValid () const
 Return true if device pointer is valid.
 
void CopyFrom (const Memory &src, int size)
 Copy size entries from src to *this.
 
void CopyFromHost (const T *src, int size)
 Copy size entries from the host pointer src to *this.
 
void CopyTo (Memory &dest, int size) const
 Copy size entries from *this to dest.
 
void CopyToHost (T *dest, int size) const
 Copy size entries from *this to the host pointer dest.
 
void PrintFlags () const
 Print the internal flags.
 
int CompareHostAndDevice (int size) const
 If both the host and the device data are valid, compare their contents.
 

Protected Types

enum  FlagMask : unsigned {
  REGISTERED = 1 << 0 , Registered = 1 << 0 , OWNS_HOST = 1 << 1 , OWNS_DEVICE = 1 << 2 ,
  OWNS_INTERNAL = 1 << 3 , VALID_HOST = 1 << 4 , VALID_DEVICE = 1 << 5 , USE_DEVICE = 1 << 6 ,
  ALIAS = 1 << 7
}
 

Protected Attributes

T * h_ptr
 Pointer to host memory. Not owned.
 
int capacity
 Size of the allocated memory.
 
MemoryType h_mt
 Host memory type.
 
unsigned flags
 Bit flags defined from the FlagMask enum.
 

Friends

class MemoryManager
 
void MemoryPrintFlags (unsigned flags)
 Print the state of a Memory object based on its internal flags. Useful in a debugger. See also Memory<T>::PrintFlags().
 

Detailed Description

template<typename T>
class mfem::Memory< T >

Class used by MFEM to store pointers to host and/or device memory.

The template class parameter, T, must be a plain-old-data (POD) type.

In many respects this class behaves like a pointer:

  • When destroyed, a Memory object does NOT automatically delete any allocated memory.
  • Only the method Delete() will deallocate a Memory object.
  • Other methods that modify the object (e.g. New(), Wrap(), etc) will simply overwrite the old contents. In other aspects this class differs from a pointer:
  • Pointer arithmetic is not supported, MakeAlias() should be used instead.
  • Const Memory object does not allow modification of the content (unlike e.g. a const pointer).
  • Move constructor and assignment will transfer ownership flags, and Reset() the moved Memory object.
  • Copy constructor and assignment copy flags. This may result in two Memory objects owning the data which is an invalid state. This invalid state MUST be resolved by users manually using SetHostPtrOwner(), SetDevicePtrOwner(), or ClearOwnerFlags(). It is also possible to call Delete() on only one of the two Memory objects, however this is discouraged because it bypasses the internal ownership flags.
  • When moving or copying (between host and device) alias Memory objects and/or their base Memory objects, the consistency of memory flags have to be manually taken care of using either Sync() or SyncAlias(). Failure to do so will result in silent misuse of unsynchronized data.

A Memory object stores up to two different pointers: one host pointer (with MemoryType from MemoryClass::HOST) and one device pointer (currently one of MemoryType: DEVICE, DEVICE_DEBUG, DEVICE_UMPIRE or MANAGED).

A Memory object can hold (wrap) an externally allocated pointer with any given MemoryType.

Access to the content of the Memory object can be requested with any given MemoryClass through the methods ReadWrite(), Read(), and Write(). Requesting such access may result in additional (internally handled) memory allocation and/or memory copy.

  • When ReadWrite() is called, the returned pointer becomes the only valid pointer.
  • When Read() is called, the returned pointer becomes valid, however the other pointer (host or device) may remain valid as well.
  • When Write() is called, the returned pointer becomes the only valid pointer, however, unlike ReadWrite(), no memory copy will be performed.

The host memory (pointer from MemoryClass::HOST) can be accessed through the inline methods: operator[](), operator*(), the implicit conversion functions operator T*(), operator const T*(), and the explicit conversion template functions operator U*(), operator const U*() (with any suitable type U). In certain cases, using these methods may have undefined behavior, e.g. if the host pointer is not currently valid.

Definition at line 167 of file mem_manager.hpp.

Member Enumeration Documentation

◆ FlagMask

template<typename T >
enum mfem::Memory::FlagMask : unsigned
protected
Enumerator
REGISTERED 

The host pointer is registered with the MemoryManager

Registered 

The host pointer is registered with the MemoryManager

OWNS_HOST 

The host pointer will be deleted by Delete()

OWNS_DEVICE 

The device pointer will be deleted by Delete()

OWNS_INTERNAL 

Ownership flag for internal Memory data.

VALID_HOST 

Host pointer is valid.

VALID_DEVICE 

Device pointer is valid

USE_DEVICE 

Internal device flag, see e.g. Vector::UseDevice()

ALIAS 

Pointer is an alias.

Definition at line 173 of file mem_manager.hpp.

Constructor & Destructor Documentation

◆ Memory() [1/9]

template<typename T >
mfem::Memory< T >::Memory ( )
inline

Default constructor, sets the host pointer to nullptr and the metadata to meaningful default values.

Definition at line 209 of file mem_manager.hpp.

◆ Memory() [2/9]

template<typename T >
mfem::Memory< T >::Memory ( const Memory< T > & orig)
default

Copy constructor: default.

◆ Memory() [3/9]

template<typename T >
mfem::Memory< T >::Memory ( Memory< T > && orig)
inline

Move constructor. Sets the pointers and associated ownership of validity flags of *this to those of other. Resets other.

Definition at line 216 of file mem_manager.hpp.

◆ Memory() [4/9]

template<typename T >
mfem::Memory< T >::Memory ( int size)
inlineexplicit

Allocate host memory for size entries.

The allocation uses the current host memory type returned by MemoryManager::GetHostMemoryType().

Definition at line 239 of file mem_manager.hpp.

◆ Memory() [5/9]

template<typename T >
mfem::Memory< T >::Memory ( int size,
MemoryType mt )
inline

Allocate memory for size entries with the given MemoryType mt.

The newly allocated memory is not initialized, however the given MemoryType is still set as valid.

Definition at line 245 of file mem_manager.hpp.

◆ Memory() [6/9]

template<typename T >
mfem::Memory< T >::Memory ( int size,
MemoryType h_mt,
MemoryType d_mt )
inline

Allocate memory for size entries with the given host MemoryType h_mt and device MemoryType d_mt.

The newly allocated memory is not initialized. The host pointer is set as valid.

Definition at line 251 of file mem_manager.hpp.

◆ Memory() [7/9]

template<typename T >
mfem::Memory< T >::Memory ( T * ptr,
int size,
bool own )
inlineexplicit

Wrap an externally allocated host pointer, ptr with the current host memory type returned by MemoryManager::GetHostMemoryType().

The parameter own determines whether ptr will be deleted when the method Delete() is called.

Definition at line 257 of file mem_manager.hpp.

◆ Memory() [8/9]

template<typename T >
mfem::Memory< T >::Memory ( T * ptr,
int size,
MemoryType mt,
bool own )
inline

Wrap an externally allocated pointer, ptr, of the given MemoryType.

The new memory object will have the given MemoryType set as valid.

The given ptr must be allocated appropriately for the given MemoryType.

The parameter own determines whether ptr will be deleted when the method Delete() is called.

Definition at line 267 of file mem_manager.hpp.

◆ Memory() [9/9]

template<typename T >
mfem::Memory< T >::Memory ( const Memory< T > & base,
int offset,
int size )
inline

Alias constructor. Create a Memory object that points inside the Memory object base.

The new Memory object uses the same MemoryType(s) as base.

Definition at line 273 of file mem_manager.hpp.

◆ ~Memory()

template<typename T >
mfem::Memory< T >::~Memory ( )
default

Destructor: default.

Note
The destructor will NOT delete the current memory.

Member Function Documentation

◆ Capacity()

template<typename T >
int mfem::Memory< T >::Capacity ( ) const
inline

Return the size of the allocated memory.

Definition at line 311 of file mem_manager.hpp.

◆ ClearOwnerFlags()

template<typename T >
void mfem::Memory< T >::ClearOwnerFlags ( ) const
inline

Clear the ownership flags for the host and device pointers, as well as any internal data allocated by the Memory object.

Definition at line 300 of file mem_manager.hpp.

◆ CompareHostAndDevice()

template<typename T >
int mfem::Memory< T >::CompareHostAndDevice ( int size) const
inline

If both the host and the device data are valid, compare their contents.

This method can be useful for debugging. It is explicitly instantiated for Memory<T> with T = int and T = real_t.

Definition at line 1340 of file mem_manager.hpp.

◆ CopyFrom()

template<typename T >
void mfem::Memory< T >::CopyFrom ( const Memory< T > & src,
int size )
inline

Copy size entries from src to *this.

The given size should not exceed the Capacity() of the source src and the destination, *this.

Definition at line 1260 of file mem_manager.hpp.

◆ CopyFromHost()

template<typename T >
void mfem::Memory< T >::CopyFromHost ( const T * src,
int size )
inline

Copy size entries from the host pointer src to *this.

The given size should not exceed the Capacity() of *this.

Definition at line 1281 of file mem_manager.hpp.

◆ CopyTo()

template<typename T >
void mfem::Memory< T >::CopyTo ( Memory< T > & dest,
int size ) const
inline

Copy size entries from *this to dest.

The given size should not exceed the Capacity() of *this and the destination, dest.

Definition at line 1302 of file mem_manager.hpp.

◆ CopyToHost()

template<typename T >
void mfem::Memory< T >::CopyToHost ( T * dest,
int size ) const
inline

Copy size entries from *this to the host pointer dest.

The given size should not exceed the Capacity() of *this.

Definition at line 1308 of file mem_manager.hpp.

◆ Delete()

template<typename T >
void mfem::Memory< T >::Delete ( )
inline

Delete the owned pointers and reset the Memory object.

Definition at line 1092 of file mem_manager.hpp.

◆ DeleteDevice()

template<typename T >
void mfem::Memory< T >::DeleteDevice ( bool copy_to_host = true)
inline

Delete the device pointer, if owned. If copy_to_host is true and the data is valid only on device, move it to host before deleting. Invalidates the device memory.

Definition at line 1111 of file mem_manager.hpp.

◆ DeviceIsValid()

template<typename T >
bool mfem::Memory< T >::DeviceIsValid ( ) const
inline

Return true if device pointer is valid.

Definition at line 1254 of file mem_manager.hpp.

◆ Empty()

template<typename T >
bool mfem::Memory< T >::Empty ( ) const
inline

Return true if the Memory object is empty, see Reset().

Default-constructed objects are uninitialized, so they are not guaranteed to be empty.

Definition at line 326 of file mem_manager.hpp.

◆ GetDeviceMemoryType()

template<typename T >
MemoryType mfem::Memory< T >::GetDeviceMemoryType ( ) const
inline

Return the device MemoryType of the Memory object. If the device MemoryType is not set, return MemoryType::DEFAULT.

Definition at line 1241 of file mem_manager.hpp.

◆ GetHostMemoryType()

template<typename T >
MemoryType mfem::Memory< T >::GetHostMemoryType ( ) const
inline

Return the host MemoryType of the Memory object.

Definition at line 521 of file mem_manager.hpp.

◆ GetMemoryType()

template<typename T >
MemoryType mfem::Memory< T >::GetMemoryType ( ) const
inline

Return a MemoryType that is currently valid. If both the host and the device pointers are currently valid, then the device memory type is returned.

Definition at line 1234 of file mem_manager.hpp.

◆ HostIsValid()

template<typename T >
bool mfem::Memory< T >::HostIsValid ( ) const
inline

Return true if host pointer is valid.

Definition at line 1248 of file mem_manager.hpp.

◆ MakeAlias()

template<typename T >
void mfem::Memory< T >::MakeAlias ( const Memory< T > & base,
int offset,
int size )
inline

Create a memory object that points inside the memory object base.

The new Memory object uses the same MemoryType(s) as base.

Note
The current memory is NOT deleted by this method.

Definition at line 1035 of file mem_manager.hpp.

◆ New() [1/3]

template<typename T >
void mfem::Memory< T >::New ( int size)
inline

Allocate host memory for size entries with the current host memory type returned by MemoryManager::GetHostMemoryType().

Note
The current memory is NOT deleted by this method.

Definition at line 938 of file mem_manager.hpp.

◆ New() [2/3]

template<typename T >
void mfem::Memory< T >::New ( int size,
MemoryType h_mt,
MemoryType d_mt )
inline

Allocate memory for size entries with the given host MemoryType h_mt and device MemoryType d_mt.

The newly allocated memory is not initialized. The host pointer is set as valid.

Note
The current memory is NOT deleted by this method.

Definition at line 960 of file mem_manager.hpp.

◆ New() [3/3]

template<typename T >
void mfem::Memory< T >::New ( int size,
MemoryType mt )
inline

Allocate memory for size entries with the given MemoryType.

The newly allocated memory is not initialized, however the given MemoryType is still set as valid.

When mt is a host type, the device MemoryType will be set later, if requested, using the dual type of mt, see MemoryManager::GetDualMemoryType().

When mt is a device type, the host MemoryType will be set immediately to be the dual of mt, see MemoryManager::GetDualMemoryType().

Note
The current memory is NOT deleted by this method.

Definition at line 948 of file mem_manager.hpp.

◆ operator const T *()

template<typename T >
mfem::Memory< T >::operator const T * ( ) const
inline

Direct access to the host memory as const T* (implicit conversion).

This method can be used only if the host pointer is currently valid (the device pointer may be valid or invalid).

When the Memory is empty, this method can be used and it returns NULL.

Definition at line 1146 of file mem_manager.hpp.

◆ operator const U *()

template<typename T >
template<typename U >
mfem::Memory< T >::operator const U * ( ) const
inlineexplicit

Direct access to the host memory via explicit typecast, const version.

A pointer to type T must be reinterpret_cast-able to a pointer to type const U.

This method can be used only if the host pointer is currently valid (the device pointer may be valid or invalid).

When the Memory is empty, this method can be used and it returns NULL.

Definition at line 1163 of file mem_manager.hpp.

◆ operator T*()

template<typename T >
mfem::Memory< T >::operator T* ( )
inline

Direct access to the host memory as T* (implicit conversion).

When the type T is const-qualified, this method can be used only if the host pointer is currently valid (the device pointer may be valid or invalid).

When the type T is not const-qualified, this method can be used only if the host pointer is the only valid pointer.

When the Memory is empty, this method can be used and it returns NULL.

Definition at line 1136 of file mem_manager.hpp.

◆ operator U*()

template<typename T >
template<typename U >
mfem::Memory< T >::operator U* ( )
inlineexplicit

Direct access to the host memory via explicit typecast.

A pointer to type T must be reinterpret_cast-able to a pointer to type U. In particular, this method cannot be used to cast away const-ness from the base type T.

When the type U is const-qualified, this method can be used only if the host pointer is currently valid (the device pointer may be valid or invalid).

When the type U is not const-qualified, this method can be used only if the host pointer is the only valid pointer.

When the Memory is empty, this method can be used and it returns NULL.

Definition at line 1153 of file mem_manager.hpp.

◆ operator=() [1/2]

template<typename T >
Memory & mfem::Memory< T >::operator= ( const Memory< T > & orig)
default

Copy-assignment operator: default.

◆ operator=() [2/2]

template<typename T >
Memory & mfem::Memory< T >::operator= ( Memory< T > && orig)
inline

Move assignment operator. Sets the pointers and associated ownership of validity flags of *this to those of other. Resets other.

Definition at line 227 of file mem_manager.hpp.

◆ operator[]() [1/2]

template<typename T >
T & mfem::Memory< T >::operator[] ( int idx)
inline

Array subscript operator for host memory.

Definition at line 1121 of file mem_manager.hpp.

◆ operator[]() [2/2]

template<typename T >
const T & mfem::Memory< T >::operator[] ( int idx) const
inline

Array subscript operator for host memory, const version.

Definition at line 1129 of file mem_manager.hpp.

◆ OwnsDevicePtr()

template<typename T >
bool mfem::Memory< T >::OwnsDevicePtr ( ) const
inline

Return true if the device pointer is owned. Ownership indicates whether the pointer will be deleted by the method Delete().

Definition at line 291 of file mem_manager.hpp.

◆ OwnsHostPtr()

template<typename T >
bool mfem::Memory< T >::OwnsHostPtr ( ) const
inline

Return true if the host pointer is owned. Ownership indicates whether the pointer will be deleted by the method Delete().

Definition at line 282 of file mem_manager.hpp.

◆ PrintFlags()

template<typename T >
void mfem::Memory< T >::PrintFlags ( ) const
inline

Print the internal flags.

This method can be useful for debugging. It is explicitly instantiated for Memory<T> with T = int and T = real_t.

Definition at line 1334 of file mem_manager.hpp.

◆ Read()

template<typename T >
const T * mfem::Memory< T >::Read ( MemoryClass mc,
int size ) const
inline

Get read-only access to the memory with the given MemoryClass.

The parameter size must not exceed the Capacity().

Definition at line 1183 of file mem_manager.hpp.

◆ ReadWrite()

template<typename T >
T * mfem::Memory< T >::ReadWrite ( MemoryClass mc,
int size )
inline

Get read-write access to the memory with the given MemoryClass.

If only read or only write access is needed, then the methods Read() or Write() should be used instead of this method.

The parameter size must not exceed the Capacity().

Definition at line 1170 of file mem_manager.hpp.

◆ Reset() [1/2]

template<typename T >
void mfem::Memory< T >::Reset ( )
inline

Reset the memory to be empty, ensuring that Delete() will be a no-op.

This is the Memory class equivalent to setting a pointer to NULL, see Empty().

Note
The current memory is NOT deleted by this method.

Definition at line 920 of file mem_manager.hpp.

◆ Reset() [2/2]

template<typename T >
void mfem::Memory< T >::Reset ( MemoryType host_mt)
inline

Reset the memory and set the host memory type.

Definition at line 929 of file mem_manager.hpp.

◆ SetDeviceMemoryType()

template<typename T >
void mfem::Memory< T >::SetDeviceMemoryType ( MemoryType d_mt)
inline

Set the device MemoryType to be used by the Memory object.

If the specified d_mt is not a device MemoryType, i.e. not one of the types in MemoryClass::DEVICE, then this method will return immediately.

If the device MemoryType has been previously set to a different type and the actual device memory has been allocated, this method will trigger an error. This method will not perform the actual device memory allocation, however, the allocation may already exist if the MemoryType is the same as the current one.

If the Memory is an alias Memory, the device MemoryType of its base will be updated as described above.

Definition at line 1080 of file mem_manager.hpp.

◆ SetDevicePtrOwner()

template<typename T >
void mfem::Memory< T >::SetDevicePtrOwner ( bool own) const
inline

Set/clear the ownership flag for the device pointer. Ownership indicates whether the pointer will be deleted by the method Delete().

Definition at line 295 of file mem_manager.hpp.

◆ SetHostPtrOwner()

template<typename T >
void mfem::Memory< T >::SetHostPtrOwner ( bool own) const
inline

Set/clear the ownership flag for the host pointer. Ownership indicates whether the pointer will be deleted by the method Delete().

Definition at line 286 of file mem_manager.hpp.

◆ Sync()

template<typename T >
void mfem::Memory< T >::Sync ( const Memory< T > & other) const
inline

Copy the host/device pointer validity flags from other to *this.

This method synchronizes the pointer validity flags of two Memory objects that use the same host/device pointers, or when *this is an alias (sub-Memory) of other. Typically, this method should be called after other is manipulated in a way that changes its pointer validity flags (e.g. it was moved from device to host memory).

Definition at line 1209 of file mem_manager.hpp.

◆ SyncAlias()

template<typename T >
void mfem::Memory< T >::SyncAlias ( const Memory< T > & base,
int alias_size ) const
inline

Update the alias Memory *this to match the memory location (all valid locations) of its base Memory, base.

This method is useful when alias Memory is moved and manipulated in a different memory space. Such operations render the pointer validity flags of the base incorrect. Calling this method will ensure that base is up-to-date. Note that this is achieved by moving/copying *this (if necessary), and not base.

Definition at line 1223 of file mem_manager.hpp.

◆ UseDevice() [1/2]

template<typename T >
bool mfem::Memory< T >::UseDevice ( ) const
inline

Read the internal device flag.

Definition at line 304 of file mem_manager.hpp.

◆ UseDevice() [2/2]

template<typename T >
void mfem::Memory< T >::UseDevice ( bool use_dev) const
inline

Set the internal device flag.

Definition at line 307 of file mem_manager.hpp.

◆ Wrap() [1/3]

template<typename T >
void mfem::Memory< T >::Wrap ( T * h_ptr,
T * d_ptr,
int size,
MemoryType h_mt,
bool own,
bool valid_host = false,
bool valid_device = true )
inline

Wrap an externally pair of allocated pointers, h_ptr and d_ptr, of the given host MemoryType h_mt. The new memory object will have the device MemoryType set as valid unless specified otherwise by the parameters valid_host and valid_device.

The given h_ptr and d_ptr must be allocated appropriately for the given host MemoryType and its dual device MemoryType as defined by MemoryManager::GetDualMemoryType().

The parameter own determines whether both h_ptr and d_ptr will be deleted when the method Delete() is called.

The parameters valid_host and valid_device determine which pointers, host and/or device, will be marked as valid; at least one of the two parameters must be set to true.

Note
Ownership can also be controlled by using the following methods:
  • ClearOwnerFlags,
  • SetHostPtrOwner,
  • SetDevicePtrOwner.
The current memory is NOT deleted by this method.

Definition at line 1018 of file mem_manager.hpp.

◆ Wrap() [2/3]

template<typename T >
void mfem::Memory< T >::Wrap ( T * ptr,
int size,
bool own )
inline

Wrap an externally allocated host pointer, ptr with the current host memory type returned by MemoryManager::GetHostMemoryType().

The parameter own determines whether ptr will be deleted when the method Delete() is called.

Note
The current memory is NOT deleted by this method.

Definition at line 971 of file mem_manager.hpp.

◆ Wrap() [3/3]

template<typename T >
void mfem::Memory< T >::Wrap ( T * ptr,
int size,
MemoryType mt,
bool own )
inline

Wrap an externally allocated pointer, ptr, of the given MemoryType.

The new memory object will have the given MemoryType set as valid.

The given ptr must be allocated appropriately for the given MemoryType.

The parameter own determines whether ptr will be deleted when the method Delete() is called.

Note
The current memory is NOT deleted by this method.

Definition at line 993 of file mem_manager.hpp.

◆ Write()

template<typename T >
T * mfem::Memory< T >::Write ( MemoryClass mc,
int size )
inline

Get write-only access to the memory with the given MemoryClass.

The parameter size must not exceed the Capacity().

The contents of the returned pointer is undefined, unless it was validated by a previous call to Read() or ReadWrite() with the same MemoryClass.

Definition at line 1196 of file mem_manager.hpp.

Friends And Related Symbol Documentation

◆ MemoryManager

template<typename T >
friend class MemoryManager
friend

Definition at line 170 of file mem_manager.hpp.

◆ MemoryPrintFlags

template<typename T >
void MemoryPrintFlags ( unsigned flags)
friend

Print the state of a Memory object based on its internal flags. Useful in a debugger. See also Memory<T>::PrintFlags().

Definition at line 1688 of file mem_manager.cpp.

Member Data Documentation

◆ capacity

template<typename T >
int mfem::Memory< T >::capacity
protected

Size of the allocated memory.

Definition at line 200 of file mem_manager.hpp.

◆ flags

template<typename T >
unsigned mfem::Memory< T >::flags
mutableprotected

Bit flags defined from the FlagMask enum.

Definition at line 202 of file mem_manager.hpp.

◆ h_mt

template<typename T >
MemoryType mfem::Memory< T >::h_mt
protected

Host memory type.

Definition at line 201 of file mem_manager.hpp.

◆ h_ptr

template<typename T >
T* mfem::Memory< T >::h_ptr
protected

Pointer to host memory. Not owned.

The type of the pointer is given by the field h_mt; it can be any type from MemoryClass::HOST.

Definition at line 199 of file mem_manager.hpp.


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