Advanced Multi-Physics (AMP)
On-Line Documentation
Memory.h
Go to the documentation of this file.
1#ifndef included_AMP_MEMORY
2#define included_AMP_MEMORY
3
4#include "AMP/AMP_TPLs.h"
5#include "AMP/utils/UtilityMacros.h"
6
7#ifdef AMP_USE_CUDA
8 #include "AMP/utils/cuda/CudaAllocator.h"
9#endif
10#ifdef AMP_USE_HIP
11 #include "AMP/utils/hip/HipAllocator.h"
12#endif
13
14#include <string_view>
15#include <type_traits>
16
17
18namespace AMP::Utilities {
19
21enum class MemoryType : int8_t { none = -1, unregistered = 0, host = 1, managed = 2, device = 3 };
22
24MemoryType getMemoryType( const void *ptr );
25
27std::string_view getString( MemoryType );
28
30MemoryType memoryLocationFromString( std::string_view name );
31
33void memcpy( void *dest, const void *src, std::size_t count );
34
36void memset( void *dest, int ch, std::size_t count );
37
39void zero( void *dest, std::size_t count );
40
42template<class T1, class T2>
43void copy( size_t N, const T1 *src, T2 *dst );
44
45} // namespace AMP::Utilities
46
47
48namespace AMP {
49// managed allocators
50#ifdef AMP_USE_CUDA
51template<typename TYPE>
52using ManagedAllocator = AMP::CudaManagedAllocator<TYPE>;
53#elif defined( AMP_USE_HIP )
54template<typename TYPE>
55using ManagedAllocator = AMP::HipManagedAllocator<TYPE>;
56#endif
57
58// device allocators
59#ifdef AMP_USE_CUDA
60template<typename TYPE>
61using DeviceAllocator = AMP::CudaDevAllocator<TYPE>;
62#elif defined( AMP_USE_HIP )
63template<typename TYPE>
64using DeviceAllocator = AMP::HipDevAllocator<TYPE>;
65#endif
66
67// host allocator
68template<typename TYPE>
69using HostAllocator = std::allocator<TYPE>;
70
71} // namespace AMP
72
73
74namespace AMP::Utilities {
75template<typename ALLOC>
77{
78 using intAllocator = typename std::allocator_traits<ALLOC>::template rebind_alloc<int>;
79 if ( std::is_same_v<intAllocator, std::allocator<int>> ) {
81#ifdef AMP_USE_CUDA
82 } else if ( std::is_same_v<intAllocator, AMP::CudaManagedAllocator<int>> ) {
84 } else if ( std::is_same_v<intAllocator, AMP::CudaDevAllocator<int>> ) {
86#endif
87#ifdef AMP_USE_HIP
88 } else if ( std::is_same_v<intAllocator, AMP::HipManagedAllocator<int>> ) {
90 } else if ( std::is_same_v<intAllocator, AMP::HipDevAllocator<int>> ) {
92#endif
93 } else {
94 AMP_ERROR( "Unknown Allocator" );
95 }
96}
97
98} // namespace AMP::Utilities
99
100#endif
Allocator based on cudaMalloc.
Allocator based on cudaMallocManaged.
Allocator based on hipMalloc.
Allocator based on hipMallocManaged.
#define AMP_ERROR(MSG)
Throw error.
void memcpy(void *dest, const void *src, std::size_t count)
Perform memory-memory copy (pointer may be in any memory space)
constexpr AMP::Utilities::MemoryType getAllocatorMemoryType()
Definition Memory.h:76
void copy(size_t N, const T1 *src, T2 *dst)
Perform copy with conversion if necessary.
MemoryType getMemoryType(const void *ptr)
Return the pointer type.
std::string_view getString(const ExecutionSpace exec_space)
void zero(void *dest, std::size_t count)
Perform memory zero (pointer may be in any memory space)
MemoryType memoryLocationFromString(std::string_view name)
Return the memory type from a string.
void memset(void *dest, int ch, std::size_t count)
Perform memory set (pointer may be in any memory space)
MemoryType
Enum to store pointer type.
Definition Memory.h:21
std::allocator< TYPE > HostAllocator
Definition Memory.h:69



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:41.
Comments on this page