Advanced Multi-Physics (AMP)
On-Line Documentation
HipAllocator.h
Go to the documentation of this file.
1#ifndef included_AMP_GPUDevAllocator
2#define included_AMP_GPUDevAllocator
3
4#include "AMP/utils/UtilityMacros.h"
5#include "AMP/utils/hip/Helper_Hip.h"
6
8#include <hip/hip_runtime.h>
10
11namespace AMP {
12
17template<typename T>
19{
20public:
21 using value_type = T;
22
23 T *allocate( size_t n )
24 {
25 T *ptr;
26 auto err = hipMalloc( &ptr, n * sizeof( T ) );
27 checkHipErrors( err );
28 return ptr;
29 }
30
31 void deallocate( T *p, size_t )
32 {
33 auto err = hipFree( p );
34 checkHipErrors( err );
35 }
36};
37
42template<typename T>
44{
45public:
46 using value_type = T;
47
48 T *allocate( size_t n )
49 {
50 T *ptr;
51 auto err = hipMallocManaged( &ptr, n * sizeof( T ), hipMemAttachGlobal );
52 checkHipErrors( err );
53 return ptr;
54 }
55
56 void deallocate( T *p, size_t )
57 {
58 auto err = hipFree( p );
59 checkHipErrors( err );
60 }
61};
62
63} // namespace AMP
64
65#endif
void checkHipErrors(T result, const StackTrace::source_location &source=SOURCE_LOCATION_CURRENT())
Allocator based on hipMalloc.
T * allocate(size_t n)
void deallocate(T *p, size_t)
Allocator based on hipMallocManaged.
void deallocate(T *p, size_t)
#define DISABLE_WARNINGS
Re-enable warnings.
#define ENABLE_WARNINGS
Suppress all warnings.



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