17 #ifndef MALLOC_ALLOCATOR_H
18 #define MALLOC_ALLOCATOR_H
22 #ifdef USE_PINNED_MEMORY
34 typedef value_type* pointer;
35 typedef const value_type* const_pointer;
36 typedef value_type& reference;
37 typedef const value_type& const_reference;
38 typedef std::size_t size_type;
39 typedef std::ptrdiff_t difference_type;
61 pointer address(reference x)
const
66 void construct(pointer p,
const value_type& x)
71 void destroy(pointer p)
76 const_pointer address(const_reference x)
const
81 pointer allocate(size_type n, const_pointer = 0)
85 #ifdef USE_PINNED_MEMORY
87 DEBUG_TEXT_LEVEL1(
"Pinned memory allocation ******\n")
89 err = cudaHostAlloc((
void **)&p, n * sizeof(T), cudaHostAllocPortable);
94 std::cerr<<
"*** Error Malloc: "<< cudaGetErrorString(err)<<
"\n";
95 throw std::bad_alloc();
98 p = std::malloc(n *
sizeof(T));
103 std::cerr<<
"*** Error Malloc **************\n";
104 throw std::bad_alloc();
106 return static_cast<pointer
>(p);
109 void deallocate(pointer p, size_type)
111 #ifdef USE_PINNED_MEMORY
113 err = cudaFreeHost(p);
116 std::cerr<<
"*** Error De-Alloc: "<< cudaGetErrorString(err) <<
"\n";
117 throw std::bad_alloc();
121 DEBUG_TEXT_LEVEL1(
"Pinned memory de-allocation Successful ******\n")
128 size_type max_size()
const
130 return static_cast<size_type
>(-1) /
sizeof(value_type);
153 typedef void value_type;
154 typedef void* pointer;
155 typedef const void* const_pointer;
Defines a few macros that includes macros to output text when debugging. The macros use std::cerr...
A custom memory allocator used with std::vector.