39 #ifndef ECUDA_ALLOCATORS_HPP
40 #define ECUDA_ALLOCATORS_HPP
81 template<
typename T,
unsigned Flags=cudaHostAllocDefault>
87 typedef typename ecuda::add_pointer<T>::type
pointer;
88 typedef typename ecuda::add_lvalue_reference<T>::type
reference;
164 const cudaError_t result = cudaHostAlloc( reinterpret_cast<void**>(&ptr), n*
sizeof(T), Flags );
165 if( result != cudaSuccess )
throw std::bad_alloc();
182 typedef typename ecuda::add_pointer<value_type>::type raw_pointer_type;
232 typedef typename ecuda::add_pointer<T>::type
pointer;
233 typedef typename ecuda::add_lvalue_reference<T>::type
reference;
309 const cudaError_t result = cudaMalloc( reinterpret_cast<void**>(&ptr), n*
sizeof(T) );
310 if( result != cudaSuccess )
throw std::bad_alloc();
327 typedef typename ecuda::add_pointer<value_type>::type raw_pointer_type;
385 typedef typename ecuda::add_lvalue_reference<T>::type
reference;
395 template<
typename U>
struct char_cast;
396 template<
typename U>
struct char_cast<U*> {
char* type; };
397 template<
typename U>
struct char_cast<const U*> {
const char* type; };
466 typename ecuda::add_pointer<value_type>::type ptr = NULL;
468 const cudaError_t result = cudaMallocPitch( reinterpret_cast<void**>(&ptr), &pitch, w*
sizeof(
value_type), h );
469 if( result != cudaSuccess )
throw std::bad_alloc();
486 typedef typename ecuda::add_pointer<value_type>::type raw_pointer_type;
547 typedef typename ecuda::add_pointer<value_type>::type raw_pointer;
548 raw_pointer p = naked_cast<raw_pointer>(ptr);
549 typedef typename char_cast<raw_pointer>::type char_pointer;
550 char_pointer p2 =
reinterpret_cast<char_pointer
>(p);
std::ptrdiff_t difference_type
ecuda::add_lvalue_reference< const T >::type const_reference
reference to constant element
void construct(pointer ptr, const_reference val)
Constructs an element object on the location pointed by ptr.
ecuda::add_pointer< T >::type pointer
pointer to element
__HOST__ pointer allocate(size_type n, std::allocator< void >::const_pointer hint=0)
Allocate block of storage.
__HOST__ __DEVICE__ device_allocator(const device_allocator< U > &alloc)
Constructs a device allocator object from another device allocator object with a different element ty...
pointer address(reference x)
Returns the address of x.
The default destruction policy used by smart pointers to device memory.
padded_ptr< T, typename ecuda::add_pointer< T >::type > pointer
pointer to element
std::ptrdiff_t difference_type
__HOST__ __DEVICE__ device_allocator(const device_allocator &alloc)
Constructs a device allocator object from another device allocator object.
void deallocate(pointer ptr, size_type)
Releases a block of storage previously allocated with member allocate and not yet released...
ecuda::add_pointer< T >::type pointer
pointer to element
host_allocator()
Constructs a host allocator object.
__HOST__ __DEVICE__ device_pitch_allocator()
Constructs a device pitched memory allocator object.
The default destruction policy used by smart pointers to page-locked host memory. ...
__HOST__ __DEVICE__ ~device_pitch_allocator()
Destructs the device pitched memory allocator object.
pointer allocate(size_type n, std::allocator< void >::const_pointer hint=0)
Allocate block of storage.
std::size_t size_type
quantities of elements
~host_allocator()
Destructs the host allocator object.
__HOST__ __DEVICE__ size_type max_size() const
Returns the maximum number of elements, each of member type value_type (an alias of allocator's templ...
__HOST__ __DEVICE__ pointer address(pointer ptr, size_type x, size_type y)
Returns the address of a given coordinate.
__DEVICE__ void construct(pointer ptr, const_reference val)
Constructs an element object on the location pointed by ptr.
void destroy(pointer ptr)
Destroys in-place the object pointed by ptr. Notice that this does not deallocate the storage for the...
__HOST__ __DEVICE__ const_pointer address(const_reference x) const
Returns the address of x.
__HOST__ void deallocate(pointer ptr, size_type)
Releases a block of storage previously allocated with member allocate and not yet released...
__HOST__ pointer allocate(size_type w, size_type h, std::allocator< void >::const_pointer hint=0)
Allocate block of storage.
__HOST__ __DEVICE__ const_pointer address(const_pointer ptr, size_type x, size_type y, size_type pitch) const
Returns the address of a given coordinate.
A specialized pointer to padded memory.
ecuda::add_lvalue_reference< const T >::type const_reference
reference to constant element
Allocator for hardware aligned device memory.
__DEVICE__ void destroy(pointer ptr)
Destroys in-place the object pointed by ptr. Notice that this does not deallocate the storage for the...
ecuda::add_lvalue_reference< T >::type reference
reference to element
size_type max_size() const
Returns the maximum number of elements, each of member type value_type (an alias of allocator's templ...
__HOST__ void deallocate(pointer ptr, size_type)
Releases a block of storage previously allocated with member allocate and not yet released...
std::ptrdiff_t difference_type
Allocator for device memory.
std::size_t size_type
quantities of elements
const_pointer address(const_reference x) const
Returns the address of x.
ecuda::add_lvalue_reference< T >::type reference
reference to element
Allocator for page-locked host memory.
make_const< pointer >::type const_pointer
pointer to constant element
host_allocator(const host_allocator< U > &alloc)
Constructs a host allocator object from another host allocator object with a different element type...
__HOST__ __DEVICE__ device_allocator()
Constructs a device allocator object.
ecuda::add_lvalue_reference< T >::type reference
reference to element
__HOST__ __DEVICE__ device_pitch_allocator(const device_pitch_allocator &alloc)
Constructs a device pitched memory allocator object from another host allocator object.
__HOST__ __DEVICE__ size_type get_pitch() const
__DEVICE__ void destroy(pointer ptr)
Destroys in-place the object pointed by ptr. Notice that this does not deallocate the storage for the...
__HOST__ __DEVICE__ const_pointer address(const_reference x) const
Returns the address of x.
__HOST__ __DEVICE__ device_pitch_allocator(const device_pitch_allocator< U > &alloc)
Constructs a device pitched memory allocator object from another device pitched memory allocator obje...
make_const< pointer >::type const_pointer
pointer to constant element
__HOST__ __DEVICE__ pointer address(reference x)
Returns the address of x.
ecuda::add_lvalue_reference< const T >::type const_reference
reference to constant element
__DEVICE__ void construct(pointer ptr, const_reference val)
Constructs an element object on the location pointed by ptr.
std::size_t size_type
quantities of elements
__HOST__ __DEVICE__ ~device_allocator()
Destructs the device allocator object.
__HOST__ __DEVICE__ const T & max(const T &a, const T &b)
host_allocator(const host_allocator &alloc)
Constructs a host allocator object from another host allocator object.
__HOST__ __DEVICE__ size_type max_size() const
Returns the maximum number of elements, each of member type value_type (an alias of allocator's templ...
__HOST__ __DEVICE__ pointer address(reference x)
Returns the address of x.
make_const< pointer >::type const_pointer
pointer to constant element