Extended CUDA Library (ecuda)
2.0
|
Allocator for device memory. More...
#include <allocators.hpp>
Public Types | |
typedef T | value_type |
element type More... | |
typedef 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_allocator () throw () |
Constructs a device allocator object. More... | |
__HOST__ __DEVICE__ | device_allocator (const device_allocator &alloc) throw () |
Constructs a device allocator object from another device allocator object. More... | |
template<typename U > | |
__HOST__ __DEVICE__ | device_allocator (const device_allocator< U > &alloc) throw () |
Constructs a device allocator object from another device allocator object with a different element type. More... | |
__HOST__ __DEVICE__ | ~device_allocator () throw () |
Destructs the device 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 n, 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... | |
Allocator for device memory.
Implementation follows the specification of an STL allocator. The main difference is that the CUDA API functions cudaMalloc 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_allocator cannot be used as a replacement allocator for the standard STL containers (e.g. vector).
Definition at line 227 of file allocators.hpp.
typedef make_const<pointer>::type ecuda::device_allocator< T >::const_pointer |
pointer to constant element
Definition at line 234 of file allocators.hpp.
typedef ecuda::add_lvalue_reference<const T>::type ecuda::device_allocator< T >::const_reference |
reference to constant element
Definition at line 235 of file allocators.hpp.
typedef std::ptrdiff_t ecuda::device_allocator< T >::difference_type |
difference between two pointers
Definition at line 237 of file allocators.hpp.
typedef ecuda::add_pointer<T>::type ecuda::device_allocator< T >::pointer |
pointer to element
Definition at line 232 of file allocators.hpp.
typedef ecuda::add_lvalue_reference<T>::type ecuda::device_allocator< T >::reference |
reference to element
Definition at line 233 of file allocators.hpp.
typedef std::size_t ecuda::device_allocator< T >::size_type |
quantities of elements
Definition at line 236 of file allocators.hpp.
typedef T ecuda::device_allocator< T >::value_type |
element type
Definition at line 231 of file allocators.hpp.
|
inline |
Constructs a device allocator object.
Definition at line 246 of file allocators.hpp.
|
inline |
Constructs a device allocator object from another device allocator object.
alloc | Allocator object. |
Definition at line 252 of file allocators.hpp.
|
inline |
Constructs a device allocator object from another device allocator object with a different element type.
alloc | Allocator object. |
Definition at line 259 of file allocators.hpp.
|
inline |
Destructs the device allocator object.
Definition at line 264 of file allocators.hpp.
|
inline |
Returns the address of x.
This effectively means returning &x.
x | Reference to object. |
Definition at line 274 of file allocators.hpp.
|
inline |
Returns the address of x.
This effectively means returning &x.
x | Reference to object. |
Definition at line 284 of file allocators.hpp.
|
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 cudaMalloc and throws std::bad_alloc if it cannot allocate the total amount of storage requested.
n | Number of elements (each of size sizeof(value_type)) to be allocated. |
hint | Either 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 memory allocator cannot take advantage of it. |
Definition at line 306 of file allocators.hpp.
|
inline |
Constructs an element object on the location pointed by ptr.
ptr | Pointer 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_allocator<T>). |
val | Value to initialize the constructed element to. const_reference is a member type (defined as an alias of T& in ecuda::device_allocator<T>). |
|
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).
ptr | Pointer to a block of storage previously allocated with allocate. pointer is a member type (defined as an alias of T* in ecuda::device_allocator<T>). |
Definition at line 325 of file allocators.hpp.
|
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).
ptr | Pointer to the object to be destroyed. |
|
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.
Definition at line 339 of file allocators.hpp.