12#ifndef MFEM_MEM_MANAGER_HPP
13#define MFEM_MEM_MANAGER_HPP
25#include <HYPRE_utilities.h>
26#if (21400 <= MFEM_HYPRE_VERSION) && (MFEM_HYPRE_VERSION < 21900)
27#include <_hypre_utilities.h>
232 if (
this == &other) {
return *
this; }
262 explicit Memory(T *ptr,
int size,
bool own) {
Wrap(ptr, size, own); }
273 {
Wrap(ptr, size, mt, own); }
343 inline void New(
int size);
373 inline void Wrap(T *ptr,
int size,
bool own);
410 bool valid_host =
false,
bool valid_device =
true);
460 inline operator T*();
467 inline operator const T*()
const;
482 template <
typename U>
483 inline explicit operator U*();
493 template <
typename U>
494 inline explicit operator const U*()
const;
580 static constexpr std::size_t def_align_bytes_()
583 return alignof(max_align_t);
585 static constexpr std::size_t def_align_bytes = def_align_bytes_();
586 static constexpr std::size_t new_align_bytes =
587 alignof(T) > def_align_bytes ?
alignof(T) : def_align_bytes;
589 template <std::
size_t align_
bytes,
bool dummy = true>
struct Alloc
591#if __cplusplus < 201703L
592 static inline T *New(std::size_t)
595 MFEM_ASSERT(
false,
"overaligned type cannot use MemoryType::HOST");
599 static inline T *New(std::size_t size) {
return new T[size]; }
603#if __cplusplus < 201703L
604 template<
bool dummy>
struct Alloc<def_align_bytes,dummy>
606 static inline T *New(std::size_t size) {
return new T[size]; }
611 static inline T *NewHOST(std::size_t size)
613 return Alloc<new_align_bytes>::New(size);
621template <
typename ViewedType>
629 std::remove_reference_t<
decltype((std::remove_cv_t<ViewedType> {})[0])>;
631 std::conditional_t<is_const_view, const Memory<T>,
Memory<T>>;
633 std::conditional_t<is_const_view, const int, int>;
635 std::remove_cv_t<ViewedType>
view;
676 inline operator ViewedType &() {
return view; }
705 template <
typename T>
friend class Memory;
708 MFEM_ENZYME_INACTIVE
static MemoryType host_mem_type;
711 MFEM_ENZYME_INACTIVE
static MemoryType device_mem_type;
714 MFEM_ENZYME_INACTIVE
static bool exists;
717 static bool Exists() {
return exists; }
728 MFEM_ENZYME_INACTIVE
static bool configured;
731#ifdef MFEM_USE_UMPIRE
732 static const char * h_umpire_name;
733 static const char * d_umpire_name;
734 static const char * d_umpire_2_name;
742 static void *New_(
void *h_tmp,
size_t bytes,
MemoryType mt,
unsigned &flags);
744 static void *New_(
void *h_tmp,
size_t bytes,
MemoryType h_mt,
745 MemoryType d_mt,
unsigned valid_flags,
unsigned &flags);
749 MFEM_ENZYME_INACTIVE
static void *Register_(
void *ptr,
void *h_ptr,
751 bool own,
bool alias,
unsigned &flags);
754 static void Register2_(
void *h_ptr,
void *d_ptr,
size_t bytes,
756 bool own,
bool alias,
unsigned &flags,
757 unsigned valid_flags);
760 static void Alias_(
void *base_h_ptr,
size_t offset,
size_t bytes,
761 unsigned base_flags,
unsigned &flags);
763 static void SetDeviceMemoryType_(
void *h_ptr,
unsigned flags,
767 MFEM_ENZYME_FN_LIKE_FREE
static void Delete_(
void *h_ptr,
MemoryType mt,
771 static void DeleteDevice_(
void *h_ptr,
unsigned & flags);
774 static bool MemoryClassCheck_(
MemoryClass mc,
void *h_ptr,
775 MemoryType h_mt,
size_t bytes,
unsigned flags);
779 MFEM_ENZYME_FN_LIKE_DYNCAST
static void *ReadWrite_(
void *h_ptr,
781 size_t bytes,
unsigned &flags);
783 MFEM_ENZYME_FN_LIKE_DYNCAST
static const void *Read_(
void *h_ptr,
785 size_t bytes,
unsigned &flags);
787 MFEM_ENZYME_FN_LIKE_DYNCAST
static void *Write_(
void *h_ptr,
MemoryType h_mt,
789 size_t bytes,
unsigned &flags);
791 static void SyncAlias_(
const void *base_h_ptr,
void *alias_h_ptr,
792 size_t alias_bytes,
unsigned base_flags,
793 unsigned &alias_flags);
797 MFEM_ENZYME_INACTIVE
static MemoryType GetDeviceMemoryType_(
void *h_ptr,
801 MFEM_ENZYME_INACTIVE
static MemoryType GetHostMemoryType_(
void *h_ptr);
804 static void CheckHostMemoryType_(
MemoryType h_mt,
void *h_ptr,
bool alias);
808 static void Copy_(
void *dest_h_ptr,
const void *src_h_ptr,
size_t bytes,
809 unsigned src_flags,
unsigned &dest_flags);
813 static void CopyToHost_(
void *dest_h_ptr,
const void *src_h_ptr,
814 size_t bytes,
unsigned src_flags);
818 static void CopyFromHost_(
void *dest_h_ptr,
const void *src_h_ptr,
819 size_t bytes,
unsigned &dest_flags);
822 static bool IsKnown_(
const void *h_ptr);
826 static bool IsAlias_(
const void *h_ptr);
829 static int CompareHostAndDevice_(
void *h_ptr,
size_t size,
unsigned flags);
838 void InsertDevice(
void *d_ptr,
void *h_ptr,
size_t bytes,
842 void InsertAlias(
const void *base_ptr,
void *alias_ptr,
843 const size_t bytes,
const bool base_is_alias);
846 void Erase(
void *h_ptr,
bool free_dev_ptr =
true);
849 void EraseDevice(
void *h_ptr);
852 void EraseAlias(
void *alias_ptr);
856 void *GetDevicePtr(
const void *h_ptr,
size_t bytes,
bool copy_data);
860 void *GetAliasDevicePtr(
const void *alias_ptr,
size_t bytes,
bool copy_data);
864 void *GetHostPtr(
const void *d_ptr,
size_t bytes,
bool copy_data);
868 void *GetAliasHostPtr(
const void *alias_ptr,
size_t bytes,
bool copy_data);
897 {
return dual_map[(int)mt]; }
916#ifdef MFEM_USE_UMPIRE
936 bool IsKnown(
const void *h_ptr) {
return IsKnown_(h_ptr); }
939 bool IsAlias(
const void *h_ptr) {
return IsAlias_(h_ptr); }
942 void RegisterCheck(
void *h_ptr);
946 int PrintPtrs(std::ostream &out =
mfem::out);
950 int PrintAliases(std::ostream &out =
mfem::out);
955#ifdef MFEM_USE_ENZYME
958 MemoryManager::Delete_(mem, MT, flags);
961 inline static void* __enzyme_allocation_like1[4] = {(
void*)
static_cast<void*(*)(
void*,
size_t,
MemoryType,
unsigned&)
>(MemoryManager::New_),
962 (
void*)1, (
void*)
"-1,2,3", (
void*)myfree
965 inline static void* __enzyme_allocation_like2[4] = {(
void*)
static_cast<void*(*)(
void*,
size_t,
MemoryType,
MemoryType,
unsigned,
unsigned&)
>(MemoryManager::New_),
966 (
void*)1, (
void*)
"-1,2,4", (
void*)MemoryManager::Delete_
974#if MFEM_HYPRE_VERSION < 21400
975#define HYPRE_MEMORY_DEVICE (0)
976#define HYPRE_MEMORY_HOST (1)
978#if MFEM_HYPRE_VERSION < 21900
985#if !defined(HYPRE_USING_GPU)
986 return HYPRE_MEMORY_HOST;
987#elif MFEM_HYPRE_VERSION < 23100
988 return HYPRE_MEMORY_DEVICE;
990 if (!HYPRE_Initialized()) {
return HYPRE_MEMORY_HOST; }
992 HYPRE_GetMemoryLocation(&loc);
1000#if !defined(HYPRE_USING_GPU)
1002#elif MFEM_HYPRE_VERSION < 23100
1014template <
typename T>
1023template <
typename T>
1032template <
typename T>
1036 flags = OWNS_HOST | VALID_HOST;
1039 (T*)MemoryManager::New_(
nullptr, size*
sizeof(T), h_mt, flags);
1042template <
typename T>
1046 const size_t bytes = size*
sizeof(T);
1048 if (mt_host) { flags = OWNS_HOST | VALID_HOST; }
1051 h_ptr = (mt_host) ? h_tmp : (T*)MemoryManager::New_(h_tmp, bytes, mt, flags);
1054template <
typename T>
1058 const size_t bytes = size*
sizeof(T);
1059 this->h_mt = host_mt;
1061 h_ptr = (T*)MemoryManager::New_(h_tmp, bytes, host_mt, device_mt,
1065template <
typename T>
1070 flags = (own ? OWNS_HOST : 0) | VALID_HOST;
1073 if (own && MemoryManager::Exists())
1075 MemoryType h_ptr_mt = MemoryManager::GetHostMemoryType_(h_ptr);
1076 MFEM_VERIFY(h_mt == h_ptr_mt,
1077 "h_mt = " << (
int)h_mt <<
", h_ptr_mt = " << (
int)h_ptr_mt);
1082 const size_t bytes = size*
sizeof(T);
1083 MemoryManager::Register_(ptr, ptr, bytes, h_mt, own,
false, flags);
1087template <
typename T>
1098 flags = (own ? OWNS_HOST : 0) | VALID_HOST;
1108 h_ptr = (T*)MemoryManager::Register_(ptr, h_ptr, size*
sizeof(T), mt,
1112template <
typename T>
1114 bool own,
bool valid_host,
bool valid_device)
1121 MFEM_ASSERT(valid_host || valid_device,
"");
1122 const size_t bytes = size*
sizeof(T);
1124 MemoryManager::Register2_(h_ptr, d_ptr, bytes, h_mt, d_mt,
1126 valid_host*VALID_HOST|valid_device*VALID_DEVICE);
1129template <
typename T>
1132 MFEM_ASSERT(0 <= offset,
"invalid offset = " << offset);
1133 MFEM_ASSERT(0 <= size,
"invalid size = " << size);
1134 MFEM_ASSERT(offset + size <= base.
capacity,
1135 "invalid offset + size = " << offset + size
1136 <<
" > base capacity = " << base.
capacity);
1139 h_ptr = base.
h_ptr + offset;
1140 if (!(base.
flags & Registered))
1143#
if !defined(HYPRE_USING_GPU)
1147#elif MFEM_HYPRE_VERSION < 23100
1150 MemoryManager::Exists()
1158 MemoryManager::Register_(base.
h_ptr,
nullptr, base.
capacity*
sizeof(T),
1166 flags = (base.
flags | ALIAS) & ~(OWNS_HOST | OWNS_DEVICE);
1170 const size_t s_bytes = size*
sizeof(T);
1171 const size_t o_bytes = offset*
sizeof(T);
1172 MemoryManager::Alias_(base.
h_ptr, o_bytes, s_bytes, base.
flags, flags);
1175template <
typename T>
1179 h_ptr =
reinterpret_cast<T*
>(base.
h_ptr);
1185template <
typename T>
1189 if (!(flags & Registered))
1191 MemoryManager::Register_(h_ptr,
nullptr, capacity*
sizeof(T), h_mt,
1192 flags & OWNS_HOST, flags & ALIAS, flags);
1194 MemoryManager::SetDeviceMemoryType_(h_ptr, flags, d_mt);
1197template <
typename T>
1200 const bool registered = flags & Registered;
1202 const bool std_delete = !registered && mt_host;
1206 MemoryManager::Delete_((
void*)h_ptr, h_mt, flags);
1211 if (flags & OWNS_HOST) {
delete [] h_ptr; }
1216template <
typename T>
1219 if (flags & Registered)
1222 MemoryManager::DeleteDevice_((
void*)h_ptr, flags);
1226template <
typename T>
1229 MFEM_ASSERT((flags & VALID_HOST) && !(flags & VALID_DEVICE),
1230 "invalid host pointer access");
1234template <
typename T>
1237 MFEM_ASSERT((flags & VALID_HOST),
"invalid host pointer access");
1241template <
typename T>
1244 MFEM_ASSERT(Empty() ||
1245 ((flags & VALID_HOST) &&
1246 (std::is_const<T>::value || !(flags & VALID_DEVICE))),
1247 "invalid host pointer access");
1251template <
typename T>
1254 MFEM_ASSERT(Empty() || (flags & VALID_HOST),
"invalid host pointer access");
1258template <
typename T>
template <
typename U>
1261 MFEM_ASSERT(Empty() ||
1262 ((flags & VALID_HOST) &&
1263 (std::is_const<U>::value || !(flags & VALID_DEVICE))),
1264 "invalid host pointer access");
1265 return reinterpret_cast<U*
>(h_ptr);
1268template <
typename T>
template <
typename U>
1271 MFEM_ASSERT(Empty() || (flags & VALID_HOST),
"invalid host pointer access");
1272 return reinterpret_cast<U*
>(h_ptr);
1275template <
typename T>
1278 const size_t bytes = size *
sizeof(T);
1279 if (!(flags & Registered))
1282 MemoryManager::Register_(h_ptr,
nullptr, capacity*
sizeof(T), h_mt,
1283 flags & OWNS_HOST, flags & ALIAS, flags);
1285 return (T*)MemoryManager::ReadWrite_(h_ptr, h_mt, mc, bytes, flags);
1288template <
typename T>
1291 const size_t bytes = size *
sizeof(T);
1292 if (!(flags & Registered))
1295 MemoryManager::Register_(h_ptr,
nullptr, capacity*
sizeof(T), h_mt,
1296 flags & OWNS_HOST, flags & ALIAS, flags);
1298 return (
const T*)MemoryManager::Read_(h_ptr, h_mt, mc, bytes, flags);
1301template <
typename T>
1304 const size_t bytes = size *
sizeof(T);
1305 if (!(flags & Registered))
1308 MemoryManager::Register_(h_ptr,
nullptr, capacity*
sizeof(T), h_mt,
1309 flags & OWNS_HOST, flags & ALIAS, flags);
1311 return (T*)MemoryManager::Write_(h_ptr, h_mt, mc, bytes, flags);
1314template <
typename T>
1317 if (!(flags & Registered) && (other.
flags & Registered))
1319 MFEM_ASSERT(h_ptr == other.
h_ptr &&
1320 (flags & ALIAS) == (other.
flags & ALIAS),
1322 flags = (flags | Registered) & ~(OWNS_DEVICE | OWNS_INTERNAL);
1324 flags = (flags & ~(VALID_HOST | VALID_DEVICE)) |
1325 (other.
flags & (VALID_HOST | VALID_DEVICE));
1328template <
typename T>
1332 MFEM_ASSERT(!(flags & Registered) || (base.
flags & Registered),
1333 "invalid base state");
1334 if (!(base.
flags & Registered)) {
return; }
1335 MemoryManager::SyncAlias_(base.
h_ptr, h_ptr, alias_size*
sizeof(T),
1339template <
typename T>
1342 if (h_ptr ==
nullptr || !(flags & VALID_DEVICE)) {
return h_mt; }
1343 return MemoryManager::GetDeviceMemoryType_(h_ptr, flags & ALIAS);
1346template <
typename T>
1350 return MemoryManager::GetDeviceMemoryType_(h_ptr, flags & ALIAS);
1353template <
typename T>
1356 return flags & VALID_HOST ? true :
false;
1359template <
typename T>
1362 return flags & VALID_DEVICE ? true :
false;
1365template <
typename T>
1368 MFEM_VERIFY(src.
capacity>=size && capacity>=size,
"Incorrect size");
1369 if (size <= 0) {
return; }
1370 if (!(flags & Registered) && !(src.
flags & Registered))
1372 if (h_ptr != src.
h_ptr)
1374 MFEM_ASSERT(h_ptr + size <= src.
h_ptr || src.
h_ptr + size <= h_ptr,
1376 std::memcpy(h_ptr, src, size*
sizeof(T));
1382 MemoryManager::Copy_(h_ptr, src.
h_ptr, size*
sizeof(T), src.
flags, flags);
1386template <
typename T>
1389 MFEM_VERIFY(capacity>=size,
"Incorrect size");
1390 if (size <= 0) {
return; }
1391 if (!(flags & Registered))
1395 MFEM_ASSERT(h_ptr + size <= src || src + size <= h_ptr,
1397 std::memcpy(h_ptr, src, size*
sizeof(T));
1403 MemoryManager::CopyFromHost_(h_ptr, src, size*
sizeof(T), flags);
1407template <
typename T>
1413template <
typename T>
1416 MFEM_VERIFY(capacity>=size,
"Incorrect size");
1417 if (size <= 0) {
return; }
1418 if (!(flags & Registered))
1422 MFEM_ASSERT(h_ptr + size <= dest || dest + size <= h_ptr,
1424 std::memcpy(dest, h_ptr, size*
sizeof(T));
1429 MemoryManager::CopyToHost_(dest, h_ptr, size*
sizeof(T), flags);
1439template <
typename T>
1445template <
typename T>
1448 if (!(flags & VALID_HOST) || !(flags & VALID_DEVICE)) {
return 0; }
1449 return MemoryManager::CompareHostAndDevice_(h_ptr, size*
sizeof(T), flags);
A class to initialize the size of a Tensor.
bool IsKnown(const void *h_ptr)
Return true if the pointer is known by the memory manager.
static void SetUmpireDeviceAllocatorName(const char *d_name)
Set the device Umpire allocator name used with MemoryType::DEVICE_UMPIRE.
static void myfree(void *mem, MemoryType MT, unsigned &flags)
static const char * GetUmpireHostAllocatorName()
Get the host Umpire allocator name used with MemoryType::HOST_UMPIRE.
static void SetUmpireHostAllocatorName(const char *h_name)
Set the host Umpire allocator name used with MemoryType::HOST_UMPIRE.
static MemoryType GetHostMemoryType()
bool IsAlias(const void *h_ptr)
Return true if the pointer is known by the memory manager as an alias.
static const char * GetUmpireDevice2AllocatorName()
Get the device Umpire allocator name used with MemoryType::DEVICE_UMPIRE_2.
static void SetUmpireDevice2AllocatorName(const char *d_name)
Set the device Umpire allocator name used with MemoryType::DEVICE_UMPIRE_2.
static MemoryType GetDeviceMemoryType()
static MemoryType GetDualMemoryType(MemoryType mt)
Return the dual MemoryType of the given one, mt.
__attribute__((used)) inline static void *__enzyme_allocation_like2[4]
static const char * GetUmpireDeviceAllocatorName()
Get the device Umpire allocator name used with MemoryType::DEVICE_UMPIRE.
__attribute__((used)) inline static void *__enzyme_allocation_like1[4]
Type that enables viewing Vector objects as Array<real_t> objects and vice versa. Currently,...
MemoryView(const MemoryView &)=delete
MemoryView(MemoryView &&)=delete
std::conditional_t< is_const_view, const int, int > SizeType
std::remove_reference_t< decltype((std::remove_cv_t< ViewedType > {})[0])> T
std::conditional_t< is_const_view, const Memory< T >, Memory< T > > MemoryType
MemoryView & operator=(const MemoryView &)=delete
static constexpr bool is_const_view
std::remove_cv_t< ViewedType > view
ViewedType & operator*()
Return the view object by reference, ViewedType &.
MemoryView & operator=(MemoryView &&)=delete
MemoryView(MemoryType &mem, SizeType &size)
Class used by MFEM to store pointers to host and/or device memory.
void SetHostPtrOwner(bool own) const
Set/clear the ownership flag for the host pointer. Ownership indicates whether the pointer will be de...
void New(int size, MemoryType mt)
Allocate memory for size entries with the given MemoryType.
bool OwnsDevicePtr() const
Return true if the device pointer is owned. Ownership indicates whether the pointer will be deleted b...
T * Write(MemoryClass mc, int size)
Get write-only access to the memory with the given MemoryClass.
Memory(int size, MemoryType mt)
Allocate memory for size entries with the given MemoryType mt.
void Wrap(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.
MemoryType GetHostMemoryType() const
Return the host MemoryType of the Memory object.
bool DeviceIsValid() const
Return true if device pointer is valid.
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.
void SetDeviceMemoryType(MemoryType d_mt)
Set the device MemoryType to be used by the Memory object.
void SetDevicePtrOwner(bool own) const
Set/clear the ownership flag for the device pointer. Ownership indicates whether the pointer will be ...
Memory(const Memory &)=default
Copy constructor: default.
int Capacity() const
Return the size of the allocated memory.
void CopyFromHost(const T *src, int size)
Copy size entries from the host pointer src to *this.
T & operator[](int idx)
Array subscript operator for host memory.
void Swap(Memory &other)
Swap without using move assignment, avoiding Reset() calls.
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.
@ OWNS_INTERNAL
Ownership flag for internal Memory data.
@ VALID_HOST
Host pointer is valid.
@ OWNS_HOST
The host pointer will be deleted by Delete()
@ VALID_DEVICE
Device pointer is valid
@ ALIAS
Pointer is an alias.
MemoryType GetDeviceMemoryType() const
Return the device MemoryType of the Memory object. If the device MemoryType is not set,...
T * ReadWrite(MemoryClass mc, int size)
Get read-write access to the memory with the given MemoryClass.
MemoryType h_mt
Host memory type.
void Reset(MemoryType host_mt)
Reset the memory and set the host memory type.
void MakeAlias(const Memory &base, int offset, int size)
Create a memory object that points inside the memory object base.
bool HostIsValid() const
Return true if host pointer is valid.
~Memory()=default
Destructor: default.
Memory & operator=(Memory &&other)
bool UseDevice() const
Read the internal device flag.
void CopyToHost(T *dest, int size) const
Copy size entries from *this to the host pointer dest.
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,...
bool OwnsHostPtr() const
Return true if the host pointer is owned. Ownership indicates whether the pointer will be deleted by ...
friend void MemoryPrintFlags(unsigned flags)
Print the state of a Memory object based on its internal flags. Useful in a debugger....
MemoryType GetMemoryType() const
Return a MemoryType that is currently valid. If both the host and the device pointers are currently v...
bool Empty() const
Return true if the Memory object is empty, see Reset().
T * h_ptr
Pointer to host memory. Not owned.
void Sync(const Memory &other) const
Copy the host/device pointer validity flags from other to *this.
void CopyConvertPtr(const Memory< U > &base)
void PrintFlags() const
Print the internal flags.
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,...
unsigned flags
Bit flags defined from the FlagMask enum.
const T * Read(MemoryClass mc, int size) const
Get read-only access to the memory with the given MemoryClass.
void UseDevice(bool use_dev) const
Set the internal device flag.
int CompareHostAndDevice(int size) const
If both the host and the device data are valid, compare their contents.
void CopyFrom(const Memory &src, int size)
Copy size entries from src to *this.
void Reset()
Reset the memory to be empty, ensuring that Delete() will be a no-op.
Memory(int size)
Allocate host memory for size entries.
void Wrap(T *ptr, int size, bool own)
Wrap an externally allocated host pointer, ptr with the current host memory type returned by MemoryMa...
void Delete()
Delete the owned pointers and reset the Memory object.
Memory(T *ptr, int size, MemoryType mt, bool own)
Wrap an externally allocated pointer, ptr, of the given MemoryType.
void CopyTo(Memory &dest, int size) const
Copy size entries from *this to dest.
void ClearOwnerFlags() const
Clear the ownership flags for the host and device pointers, as well as any internal data allocated by...
const T & operator[](int idx) const
Array subscript operator for host memory, const version.
Memory(MemoryType mt)
Creates a new empty Memory object with host MemoryType mt.
void Wrap(T *h_ptr, T *d_ptr, int size, MemoryType h_mt, bool own, bool valid_host=false, bool valid_device=true)
int capacity
Size of the allocated memory.
void New(int size)
Allocate host memory for size entries with the current host memory type returned by MemoryManager::Ge...
Memory & operator=(const Memory &)=default
Copy-assignment operator: default.
Memory(T *ptr, int size, bool own)
Wrap an externally allocated host pointer, ptr with the current host memory type returned by MemoryMa...
bool IsDeviceMemory(MemoryType mt)
Return true if the given memory type is in MemoryClass::DEVICE.
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,...
constexpr int DeviceMemoryType
void swap(Array< T > &a, Array< T > &b)
Swap of Array<T> objects for use with standard library algorithms. Also, used by mfem::Swap().
MemoryClass operator*(MemoryClass mc1, MemoryClass mc2)
Return a suitable MemoryClass from a pair of MemoryClasses.
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
MemoryClass
Memory classes identify sets of memory types.
constexpr int MemoryTypeSize
Static casts to 'int' and sizes of some useful memory types.
MemoryManager mm
The (single) global memory manager object.
MemoryType GetMemoryType(MemoryClass mc)
Return a suitable MemoryType for a given MemoryClass.
constexpr int HostMemoryTypeSize
bool IsHostMemory(MemoryType mt)
Return true if the given memory type is in MemoryClass::HOST.
const char * MemoryTypeName[MemoryTypeSize]
Memory type names, used during Device:: configuration.
constexpr int HostMemoryType
bool HypreUsingGPU()
Return true if HYPRE is configured to use GPU.
constexpr int DeviceMemoryTypeSize
MemoryType
Memory types supported by MFEM.
@ HOST_32
Host memory; aligned at 32 bytes.
@ SIZE
Number of host and device memory types.
@ HOST_64
Host memory; aligned at 64 bytes.
@ HOST
Host memory; using new[] and delete[].
@ HOST_PINNED
Host memory: pinned (page-locked)
@ HOST_DEBUG
Host memory; allocated from a "host-debug" pool.
@ DEVICE
Device memory; using CUDA or HIP *Malloc and *Free.
HYPRE_MemoryLocation GetHypreMemoryLocation()
Return the configured HYPRE_MemoryLocation.
void MemoryPrintFlags(unsigned flags)
Print the state of a Memory object based on its internal flags. Useful in a debugger....
bool MemoryClassContainsType(MemoryClass mc, MemoryType mt)
Return true iff the MemoryType mt is contained in the MemoryClass mc.