#include <taskflow/cuda/cuda_memory.hpp>
template<typename T>
cudaDeviceAllocator class
class to create a CUDA device allocator
Template parameters | |
---|---|
T | element type |
A cudaDeviceAllocator enables device-specific allocation for standard library containers. It is typically passed as template parameter when declaring standard library containers (e.g. std::
Public types
-
template<typename U>struct rebind
- its member type
U
is the equivalent allocator type to allocate elements of type U - using value_type = T
- element type
- using pointer = T*
- element pointer type
- using reference = T&
- element reference type
- using const_pointer = const T*
- const element pointer type
- using const_reference = const T&
- constant element reference type
-
using size_type = std::
size_t - size type
-
using difference_type = std::
ptrdiff_t - pointer difference type
Constructors, destructors, conversion operators
- cudaDeviceAllocator() noexcept
- Constructs a device allocator object.
- cudaDeviceAllocator(const cudaDeviceAllocator&) noexcept
- Constructs a device allocator object from another device allocator object.
-
template<typename U>cudaDeviceAllocator(const cudaDeviceAllocator<U>&) noexcept
- Constructs a device allocator object from another device allocator object with a different element type.
- ~cudaDeviceAllocator() noexcept
- Destructs the device allocator object.
Public functions
- auto address(reference x) -> pointer
- Returns the address of x.
-
auto address(const_
reference x) const -> const_ pointer - Returns the address of x.
-
auto allocate(size_
type n, const void* = 0) -> pointer - allocates block of storage.
-
void deallocate(pointer ptr,
size_
type) - Releases a block of storage previously allocated with member allocate and not yet released.
-
auto max_size() const -> size_
type noexcept - returns the maximum number of elements that could potentially be allocated by this allocator
-
void construct(pointer,
const_
reference) - ignored to avoid de-referencing device pointer from the host
- void destroy(pointer)
- ignored to avoid de-referencing device pointer from the host
-
template<typename U>auto operator==(const cudaDeviceAllocator<U>&) const -> bool noexcept
- compares two allocator of different types using
==
-
template<typename U>auto operator!=(const cudaDeviceAllocator<U>&) const -> bool noexcept
- compares two allocator of different types using
!=
Function documentation
template<typename T>
const_ pointer tf:: cudaDeviceAllocator<T>:: address(const_ reference x) const
Returns the address of x.
Parameters | |
---|---|
x | reference to an object |
Returns | a pointer to the object |
This effectively means returning &x.
template<typename T>
pointer tf:: cudaDeviceAllocator<T>:: allocate(size_ type n,
const void* = 0)
allocates block of storage.
Parameters | |
---|---|
n | number of elements (each of size sizeof(value_type)) to be allocated |
Returns | a pointer to the initial element in the 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::
template<typename T>
void tf:: cudaDeviceAllocator<T>:: deallocate(pointer ptr,
size_ type)
Releases a block of storage previously allocated with member allocate and not yet released.
Parameters | |
---|---|
ptr | pointer to a block of storage previously allocated with allocate |
The elements in the array are not destroyed by a call to this member function.
template<typename T>
size_ type tf:: cudaDeviceAllocator<T>:: max_size() const noexcept
returns the maximum number of elements that could potentially be allocated by this allocator
Returns | the number of elements that might be allocated as maximum 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.
template<typename T>
template<typename U>
bool tf:: cudaDeviceAllocator<T>:: operator==(const cudaDeviceAllocator<U>&) const noexcept
compares two allocator of different types using ==
Device allocators of different types are always equal to each other because the storage allocated by the allocator a1
can be deallocated through a2
.
template<typename T>
template<typename U>
bool tf:: cudaDeviceAllocator<T>:: operator!=(const cudaDeviceAllocator<U>&) const noexcept
compares two allocator of different types using !=
Device allocators of different types are always equal to each other because the storage allocated by the allocator a1
can be deallocated through a2
.