Advanced Multi-Physics (AMP)
On-Line Documentation
CudaAllocator.h
Go to the documentation of this file.
1#ifndef included_AMP_GPUDevAllocator
2#define included_AMP_GPUDevAllocator
3
4
5#include <cuda.h>
6#include <cuda_runtime.h>
7
8#include "AMP/utils/cuda/Helper_Cuda.h"
9
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 = cudaMalloc( &ptr, n * sizeof( T ) );
27 checkCudaErrors( err );
28 return ptr;
29 }
30
31 void deallocate( T *p, size_t )
32 {
33 auto err = cudaFree( p );
34 checkCudaErrors( err );
35 }
36};
37
38
43template<typename T>
45{
46public:
47 using value_type = T;
48
49 T *allocate( size_t n )
50 {
51 T *ptr;
52 auto err = cudaMallocManaged( &ptr, n * sizeof( T ), cudaMemAttachGlobal );
53 // auto err = cudaMalloc( &ptr, n * sizeof( T ) );
54 checkCudaErrors( err );
55 checkCudaErrors( cudaMemset( ptr, 0, n ) );
56 return ptr;
57 }
58
59 void deallocate( T *p, size_t )
60 {
61 auto err = cudaFree( p );
62 checkCudaErrors( err );
63 }
64};
65
66} // namespace AMP
67
68
69#endif
void checkCudaErrors(T result, const StackTrace::source_location &source=SOURCE_LOCATION_CURRENT())
Allocator based on cudaMalloc.
T * allocate(size_t n)
void deallocate(T *p, size_t)
Allocator based on cudaMallocManaged.
void deallocate(T *p, size_t)



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