34 #include <cugar/basic/types.h> 35 #include <cugar/basic/threads.h> 36 #include <cugar/basic/cuda/arch.h> 37 #include <cub/util_allocator.cuh> 38 #include <thrust/device_ptr.h> 57 typedef char value_type;
58 typedef char* pointer;
59 typedef const char* const_pointer;
60 typedef char& reference;
61 typedef const char& const_reference;
62 typedef size_t size_type;
63 typedef int64 difference_type;
70 #if defined(CUGAR_DEVICE_COMPILATION) 73 if (s_caching_device_allocator == NULL)
77 cuda::check_error( s_caching_device_allocator->DeviceAllocate( &ptr, num_bytes ),
"cugar::caching_device_allocator::allocate()" );
87 #if !defined(CUGAR_DEVICE_COMPILATION) 88 cuda::check_error( s_caching_device_allocator->DeviceFree( ptr ),
"cugar::caching_device_allocator::deallocate()" );
94 static void init(
const size_t max_cached_bytes = 128u*1024u*1024u)
97 if (s_caching_device_allocator == NULL)
98 s_caching_device_allocator =
new cub::CachingDeviceAllocator( 8, 2u, 10u, max_cached_bytes );
102 CUGAR_API
static cub::CachingDeviceAllocator*
volatile s_caching_device_allocator;
103 static Mutex s_mutex;
108 template <
typename T>
136 inline pointer
address(reference r) {
return &r; }
142 inline const_pointer
address(const_reference r) {
return &r; }
151 const_pointer = const_pointer(static_cast<T*>(0)))
153 return pointer( (T*)base_allocator.allocate( cnt *
sizeof(T) ) );
165 base_allocator.deallocate((
char*)p.get(), cnt *
sizeof(T));
Definition: allocator.h:109
thrust::device_ptr< const T > const_pointer
Definition: allocator.h:118
CUGAR_HOST_DEVICE char * allocate(size_type num_bytes)
Definition: allocator.h:68
CUGAR_HOST_DEVICE void deallocate(char *ptr, size_type n)
Definition: allocator.h:85
Definition: allocator.h:54
thrust::device_reference< T > reference
Definition: allocator.h:121
CUGAR_HOST pointer allocate(size_type cnt, const_pointer=const_pointer(static_cast< T *>(0)))
Definition: allocator.h:150
Definition: threads.h:181
std::size_t size_type
Definition: allocator.h:127
thrust::device_ptr< T > pointer
Definition: allocator.h:115
__host__ __device__ const_pointer address(const_reference r)
Definition: allocator.h:142
__host__ __device__ pointer address(reference r)
Definition: allocator.h:136
Definition: threads.h:145
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
CUGAR_HOST void deallocate(pointer p, size_type cnt)
Definition: allocator.h:163
T value_type
Definition: allocator.h:112
pointer::difference_type difference_type
Definition: allocator.h:130
thrust::device_reference< const T > const_reference
Definition: allocator.h:124
static void init(const size_t max_cached_bytes=128u *1024u *1024u)
Definition: allocator.h:94