Extended CUDA Library (ecuda)  2.0
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
Classes | Public Types | Public Member Functions | List of all members
ecuda::device_pitch_allocator< T > Class Template Reference

Allocator for hardware aligned device memory. More...

#include <allocators.hpp>

Public Types

typedef T value_type
 element type More...
 
typedef padded_ptr< T,
typename ecuda::add_pointer< T >
::type > 
pointer
 pointer to element More...
 
typedef
ecuda::add_lvalue_reference< T >
::type 
reference
 reference to element More...
 
typedef make_const< pointer >::type const_pointer
 pointer to constant element More...
 
typedef
ecuda::add_lvalue_reference
< const T >::type 
const_reference
 reference to constant element More...
 
typedef std::size_t size_type
 quantities of elements More...
 
typedef std::ptrdiff_t difference_type
 

Public Member Functions

__HOST__ __DEVICE__ device_pitch_allocator () throw ()
 Constructs a device pitched memory allocator object. More...
 
__HOST__ __DEVICE__ device_pitch_allocator (const device_pitch_allocator &alloc) throw ()
 Constructs a device pitched memory allocator object from another host allocator object. More...
 
template<typename U >
__HOST__ __DEVICE__ device_pitch_allocator (const device_pitch_allocator< U > &alloc) throw ()
 Constructs a device pitched memory allocator object from another device pitched memory allocator object with a different element type. More...
 
__HOST__ __DEVICE__ ~device_pitch_allocator () throw ()
 Destructs the device pitched memory allocator object. More...
 
__HOST__ __DEVICE__ pointer address (reference x)
 Returns the address of x. More...
 
__HOST__ __DEVICE__ const_pointer address (const_reference x) const
 Returns the address of x. More...
 
__HOST__ pointer allocate (size_type w, size_type h, std::allocator< void >::const_pointer hint=0)
 Allocate block of storage. More...
 
__HOST__ void deallocate (pointer ptr, size_type)
 Releases a block of storage previously allocated with member allocate and not yet released. More...
 
__HOST__ __DEVICE__ size_type max_size () const throw ()
 Returns the maximum number of elements, each of member type value_type (an alias of allocator's template parameter) that could potentially be allocated by a call to member allocate. More...
 
__DEVICE__ void construct (pointer ptr, const_reference val)
 Constructs an element object on the location pointed by ptr. More...
 
__DEVICE__ void destroy (pointer ptr)
 Destroys in-place the object pointed by ptr. Notice that this does not deallocate the storage for the element (see member deallocate to release storage space). More...
 
__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. More...
 
__HOST__ __DEVICE__ pointer address (pointer ptr, size_type x, size_type y)
 Returns the address of a given coordinate. More...
 

Detailed Description

template<typename T>
class ecuda::device_pitch_allocator< T >

Allocator for hardware aligned device memory.

Implementation follows the specification of an STL allocator. The main difference is that the CUDA API functions cudaMallocPitch and cudaFree are used internally to allocate/deallocate memory.

Unlike the standard std::allocator or ecuda::host_allocator, the allocator allocates device memory which is only accessible through device code. Therefore, ecuda::device_pitch_allocator cannot be used as a replacement allocator for the standard STL containers (e.g. vector).

This allocator is NOT strictly compatible with STL specification because the allocated memory is 2D and has padding to align the allocation in hardware memory. The allocator requires both a width and height to specify size, instead of a single length. The allocator uses the ecuda::padded_ptr pointer specialization to store details on the padding of the allocated memory.

Definition at line 379 of file allocators.hpp.

Member Typedef Documentation

template<typename T>
typedef make_const<pointer>::type ecuda::device_pitch_allocator< T >::const_pointer

pointer to constant element

Definition at line 386 of file allocators.hpp.

template<typename T>
typedef ecuda::add_lvalue_reference<const T>::type ecuda::device_pitch_allocator< T >::const_reference

reference to constant element

Definition at line 387 of file allocators.hpp.

template<typename T>
typedef std::ptrdiff_t ecuda::device_pitch_allocator< T >::difference_type

difference between two pointers

Definition at line 389 of file allocators.hpp.

template<typename T>
typedef padded_ptr<T,typename ecuda::add_pointer<T>::type> ecuda::device_pitch_allocator< T >::pointer

pointer to element

Definition at line 384 of file allocators.hpp.

template<typename T>
typedef ecuda::add_lvalue_reference<T>::type ecuda::device_pitch_allocator< T >::reference

reference to element

Definition at line 385 of file allocators.hpp.

template<typename T>
typedef std::size_t ecuda::device_pitch_allocator< T >::size_type

quantities of elements

Definition at line 388 of file allocators.hpp.

template<typename T>
typedef T ecuda::device_pitch_allocator< T >::value_type

element type

Definition at line 383 of file allocators.hpp.

Constructor & Destructor Documentation

template<typename T>
__HOST__ __DEVICE__ ecuda::device_pitch_allocator< T >::device_pitch_allocator ( )
throw (
)
inline

Constructs a device pitched memory allocator object.

Definition at line 403 of file allocators.hpp.

template<typename T>
__HOST__ __DEVICE__ ecuda::device_pitch_allocator< T >::device_pitch_allocator ( const device_pitch_allocator< T > &  alloc)
throw (
)
inline

Constructs a device pitched memory allocator object from another host allocator object.

Parameters
allocAllocator object.

Definition at line 409 of file allocators.hpp.

template<typename T>
template<typename U >
__HOST__ __DEVICE__ ecuda::device_pitch_allocator< T >::device_pitch_allocator ( const device_pitch_allocator< U > &  alloc)
throw (
)
inline

Constructs a device pitched memory allocator object from another device pitched memory allocator object with a different element type.

Parameters
allocAllocator object.

Definition at line 416 of file allocators.hpp.

template<typename T>
__HOST__ __DEVICE__ ecuda::device_pitch_allocator< T >::~device_pitch_allocator ( )
throw (
)
inline

Destructs the device pitched memory allocator object.

Definition at line 421 of file allocators.hpp.

Member Function Documentation

template<typename T>
__HOST__ __DEVICE__ pointer ecuda::device_pitch_allocator< T >::address ( reference  x)
inline

Returns the address of x.

This effectively means returning &x.

Parameters
xReference to object.
Returns
A pointer to the object.

Definition at line 431 of file allocators.hpp.

template<typename T>
__HOST__ __DEVICE__ const_pointer ecuda::device_pitch_allocator< T >::address ( const_reference  x) const
inline

Returns the address of x.

This effectively means returning &x.

Parameters
xReference to object.
Returns
A pointer to the object.

Definition at line 441 of file allocators.hpp.

template<typename T>
__HOST__ __DEVICE__ const_pointer ecuda::device_pitch_allocator< T >::address ( const_pointer  ptr,
size_type  x,
size_type  y,
size_type  pitch 
) const
inline

Returns the address of a given coordinate.

Since pitched memory has padding at each row, the location of (x,y) is not necessarily offset by width*x+y.

Parameters
ptr
x
y
pitch
Returns
A pointer to the location.

Definition at line 528 of file allocators.hpp.

template<typename T>
__HOST__ __DEVICE__ pointer ecuda::device_pitch_allocator< T >::address ( pointer  ptr,
size_type  x,
size_type  y 
)
inline

Returns the address of a given coordinate.

Since pitched memory has padding at each row, the location of (x,y) is not necessarily offset by width*x+y.

Parameters
ptr
x
y
Returns
A pointer to the location.

Definition at line 544 of file allocators.hpp.

template<typename T>
__HOST__ pointer ecuda::device_pitch_allocator< T >::allocate ( size_type  w,
size_type  h,
std::allocator< void >::const_pointer  hint = 0 
)
inline

Allocate block of storage.

Attempts to allocate a block of storage with a size large enough to contain n elements of member type value_type, and returns a pointer to the first element.

The storage is aligned appropriately for object of type value_type, but they are not constructed.

The block of storage is allocated using cudaMallocPitch and throws std::bad_alloc if it cannot allocate the total amount of storage requested.

Parameters
wWidth of the matrix (each of size sizeof(value_type)) to be allocated.
hHeight of the matrix to be allocated.
hintEither 0 or a value previously obtained by another call to allocate and not yet freed with deallocate. For standard memory allocation, a non-zero value may used as a hint to improve performance by allocating the new block near the one specified. The address of an adjacent element is often a good choice. In this case, hint is always ignored since the CUDA device pitched memory memory allocator cannot take advantage of it.
Returns
A pointer to the initial element in the block of storage.

Definition at line 464 of file allocators.hpp.

template<typename T>
__DEVICE__ void ecuda::device_pitch_allocator< T >::construct ( pointer  ptr,
const_reference  val 
)
inline

Constructs an element object on the location pointed by ptr.

Parameters
ptrPointer to a location with enough storage space to contain an element of type value_type. pointer is a member type (defined as an alias of T* in ecuda::device_pitch_allocator<T>).
valValue to initialize the constructed element to. const_reference is a member type (defined as an alias of T& in ecuda::device_pitch_allocator<T>).
template<typename T>
__HOST__ void ecuda::device_pitch_allocator< T >::deallocate ( pointer  ptr,
size_type   
)
inline

Releases a block of storage previously allocated with member allocate and not yet released.

The elements in the array are not destroyed by a call to this member function.

In the default allocator, the block of storage is at some point deallocated using ::operator delete (either during the function call, or later).

Parameters
ptrPointer to a block of storage previously allocated with allocate. pointer is a member type (defined as an alias of T* in ecuda::device_pitch_allocator<T>).

Definition at line 484 of file allocators.hpp.

template<typename T>
__DEVICE__ void ecuda::device_pitch_allocator< T >::destroy ( pointer  ptr)
inline

Destroys in-place the object pointed by ptr. Notice that this does not deallocate the storage for the element (see member deallocate to release storage space).

Parameters
ptrPointer to the object to be destroyed.
template<typename T>
__HOST__ __DEVICE__ size_type ecuda::device_pitch_allocator< T >::max_size ( ) const
throw (
)
inline

Returns the maximum number of elements, each of member type value_type (an alias of allocator's template parameter) that could potentially be allocated by a call to member allocate.

A call to member allocate with the value returned by this function can still fail to allocate the requested storage.

Returns
The nubmer of elements that might be allcoated as maximum by a call to member allocate.

Definition at line 498 of file allocators.hpp.


The documentation for this class was generated from the following file: