thrust
Functions
Allocation Functions

Functions

thrust::device_ptr< void > thrust::device_malloc (const std::size_t n)
 
template<typename T >
device_ptr< T > thrust::device_new (device_ptr< void > p, const size_t n=1)
 
template<typename T >
device_ptr< T > thrust::device_new (device_ptr< void > p, const T &exemplar, const size_t n=1)
 
template<typename T >
device_ptr< T > thrust::device_new (const size_t n=1)
 
template<typename DerivedPolicy >
__host__ __device__ pointer
< void, DerivedPolicy > 
thrust::malloc (const thrust::detail::execution_policy_base< DerivedPolicy > &system, std::size_t n)
 
template<typename T , typename DerivedPolicy >
__host__ __device__ pointer< T,
DerivedPolicy > 
thrust::malloc (const thrust::detail::execution_policy_base< DerivedPolicy > &system, std::size_t n)
 
template<typename T , typename DerivedPolicy >
__host__ __device__
thrust::pair< thrust::pointer
< T, DerivedPolicy >, typename
thrust::pointer< T,
DerivedPolicy >
::difference_type > 
thrust::get_temporary_buffer (const thrust::detail::execution_policy_base< DerivedPolicy > &system, typename thrust::pointer< T, DerivedPolicy >::difference_type n)
 

Detailed Description

Function Documentation

device_ptr< T > thrust::device_malloc ( const std::size_t  n)
inline

This version of device_malloc allocates sequential device storage for bytes.

Parameters
nThe number of bytes to allocate sequentially in device memory.
Returns
A device_ptr to the newly allocated memory.

The following code snippet demonstrates how to use device_malloc to allocate a range of device memory.

...
// allocate some memory with device_malloc
const int N = 100;
// manipulate memory
...
// deallocate with device_free
thrust::device_free(void_ptr);
See Also
device_ptr
device_free

This version of device_malloc allocates sequential device storage for new objects of the given type.

Parameters
nThe number of objects of type T to allocate sequentially in device memory.
Returns
A device_ptr to the newly allocated memory.

The following code snippet demonstrates how to use device_malloc to allocate a range of device memory.

...
// allocate some integers with device_malloc
const int N = 100;
thrust::device_ptr<int> int_array = thrust::device_malloc<int>(N);
// manipulate integers
...
// deallocate with device_free
thrust::device_free(int_array);
See Also
device_ptr
device_free
template<typename T >
device_ptr<T> thrust::device_new ( device_ptr< void >  p,
const size_t  n = 1 
)

device_new implements the placement new operator for types resident in device memory. device_new calls T's null constructor on a array of objects in device memory. No memory is allocated by this function.

Parameters
pA device_ptr to a region of device memory into which to construct one or many Ts.
nThe number of objects to construct at p.
Returns
p, casted to T's type.
See Also
device_ptr
template<typename T >
device_ptr<T> thrust::device_new ( device_ptr< void >  p,
const T &  exemplar,
const size_t  n = 1 
)

device_new implements the placement new operator for types resident in device memory. device_new calls T's copy constructor on a array of objects in device memory. No memory is allocated by this function.

Parameters
pA device_ptr to a region of device memory into which to construct one or many Ts.
exemplarThe value from which to copy.
nThe number of objects to construct at p.
Returns
p, casted to T's type.
See Also
device_ptr
fill
template<typename T >
device_ptr<T> thrust::device_new ( const size_t  n = 1)

device_new implements the new operator for types resident in device memory. It allocates device memory large enough to hold n new objects of type T.

Parameters
nThe number of objects to allocate. Defaults to 1.
Returns
A device_ptr to the newly allocated region of device memory.
template<typename T , typename DerivedPolicy >
__host__ __device__ thrust::pair<thrust::pointer<T,DerivedPolicy>, typename thrust::pointer<T,DerivedPolicy>::difference_type> thrust::get_temporary_buffer ( const thrust::detail::execution_policy_base< DerivedPolicy > &  system,
typename thrust::pointer< T, DerivedPolicy >::difference_type  n 
)

get_temporary_buffer returns a pointer to storage associated with a given Thrust system sufficient to store up to n objects of type T. If not enough storage is available to accomodate n objects, an implementation may return a smaller buffer. The number of objects the returned buffer can accomodate is also returned.

Thrust uses get_temporary_buffer internally when allocating temporary storage required by algorithm implementations.

The storage allocated with get_temporary_buffer must be returned to the system with return_temporary_buffer.

Parameters
systemThe Thrust system with which to associate the storage.
nThe requested number of objects of type T the storage should accomodate.
Returns
A pair p such that p.first is a pointer to the allocated storage and p.second is the number of contiguous objects of type T that the storage can accomodate. If no storage can be allocated, p.first if no storage can be obtained. The storage must be returned to the system using return_temporary_buffer.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
Precondition
DerivedPolicy must be publically derived from thrust::execution_policy<DerivedPolicy>.

The following code snippet demonstrates how to use get_temporary_buffer to allocate a range of memory to accomodate integers associated with Thrust's device system.

#include <thrust/memory.h>
...
// allocate storage for 100 ints with thrust::get_temporary_buffer
const int N = 100;
typedef thrust::pair<
thrust::pointer<int,thrust::device_system_tag>,
std::ptrdiff_t
> ptr_and_size_t;
thrust::device_system_tag device_sys;
ptr_and_size_t ptr_and_size = thrust::get_temporary_buffer<int>(device_sys, N);
// manipulate up to 100 ints
for(int i = 0; i < ptr_and_size.second; ++i)
{
*ptr_and_size.first = i;
}
// deallocate storage with thrust::return_temporary_buffer
thrust::return_temporary_buffer(device_sys, ptr_and_size.first);
See Also
malloc
return_temporary_buffer
template<typename DerivedPolicy >
__host__ __device__ pointer<void,DerivedPolicy> thrust::malloc ( const thrust::detail::execution_policy_base< DerivedPolicy > &  system,
std::size_t  n 
)

This version of malloc allocates untyped uninitialized storage associated with a given system.

Parameters
systemThe Thrust system with which to associate the storage.
nThe number of bytes of storage to allocate.
Returns
If allocation succeeds, a pointer to the allocated storage; a null pointer otherwise. The pointer must be deallocated with thrust::free.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
Precondition
DerivedPolicy must be publically derived from thrust::execution_policy<DerivedPolicy>.

The following code snippet demonstrates how to use malloc to allocate a range of memory associated with Thrust's device system.

#include <thrust/memory.h>
...
// allocate some memory with thrust::malloc
const int N = 100;
thrust::device_system_tag device_sys;
// manipulate memory
...
// deallocate void_ptr with thrust::free
thrust::free(device_sys, void_ptr);
See Also
free
device_malloc
template<typename T , typename DerivedPolicy >
__host__ __device__ pointer<T,DerivedPolicy> thrust::malloc ( const thrust::detail::execution_policy_base< DerivedPolicy > &  system,
std::size_t  n 
)

This version of malloc allocates typed uninitialized storage associated with a given system.

Parameters
systemThe Thrust system with which to associate the storage.
nThe number of elements of type T which the storage should accomodate.
Returns
If allocation succeeds, a pointer to an allocation large enough to accomodate n elements of type T; a null pointer otherwise. The pointer must be deallocated with thrust::free.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
Precondition
DerivedPolicy must be publically derived from thrust::execution_policy<DerivedPolicy>.

The following code snippet demonstrates how to use malloc to allocate a range of memory to accomodate integers associated with Thrust's device system.

#include <thrust/memory.h>
...
// allocate storage for 100 ints with thrust::malloc
const int N = 100;
thrust::device_system_tag device_sys;
thrust::pointer<int,thrust::device_system_tag> ptr = thrust::malloc<int>(device_sys, N);
// manipulate memory
...
// deallocate ptr with thrust::free
thrust::free(device_sys, ptr);
See Also
free
device_malloc