Function thrust::device_malloc

Function Documentation

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

This version of device_malloc allocates sequential device storage for bytes.

The following code snippet demonstrates how to use

device_malloc to allocate a range of device memory.
Return

A device_ptr to the newly allocated memory.

Parameters
  • n: The number of bytes to allocate sequentially in device memory.

#include <thrust/device_malloc.h>
#include <thrust/device_free.h>
...
// allocate some memory with device_malloc
const int N = 100;
thrust::device_ptr<void> void_ptr = thrust::device_malloc(N);

// manipulate memory
...

// deallocate with device_free
thrust::device_free(void_ptr);

This version of

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

device_ptr

See

device_free

The following code snippet demonstrates how to use

device_malloc to allocate a range of device memory.
Return

A device_ptr to the newly allocated memory.

Parameters
  • n: The number of objects of type T to allocate sequentially in device memory.

#include <thrust/device_malloc.h>
#include <thrust/device_free.h>
...
// 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

device_ptr

See

device_free