Classes
device_buffer.hpp File Reference

RAII construct for device memory allocation. More...

#include <rmm/cuda_stream_view.hpp>
#include <rmm/detail/error.hpp>
#include <rmm/mr/device/device_memory_resource.hpp>
#include <rmm/mr/device/per_device_resource.hpp>
#include <cuda_runtime_api.h>
#include <cassert>
#include <cstddef>
#include <stdexcept>
#include <utility>
Include dependency graph for device_buffer.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  rmm::device_buffer
 

Detailed Description

RAII construct for device memory allocation.

This class allocates untyped and uninitialized device memory using a device_memory_resource. If not explicitly specified, the memory resource returned from get_current_device_resource() is used.

Note
Unlike std::vector or thrust::device_vector, the device memory allocated by a device_buffer is uninitialized. Therefore, it is undefined behavior to read the contents of data() before first initializing it.

Examples:

//Allocates at least 100 bytes of device memory using the default memory
//resource and default stream.
device_buffer buff(100);
// allocates at least 100 bytes using the custom memory resource and
// specified stream
custom_memory_resource mr;
cuda_stream_view stream = cuda_stream_view{};
device_buffer custom_buff(100, stream, &mr);
// deep copies `buff` into a new device buffer using the specified stream
device_buffer buff_copy(buff, stream);
// moves the memory in `from_buff` to `to_buff`. Deallocates previously allocated
// to_buff memory on `to_buff.stream()`.
device_buffer to_buff(std::move(from_buff));
// deep copies `buff` into a new device buffer using the specified stream
device_buffer buff_copy(buff, stream);
// shallow copies `buff` into a new device_buffer, `buff` is now empty
device_buffer buff_move(std::move(buff));
// Default construction. Buffer is empty
device_buffer buff_default{};
// If the requested size is larger than the current size, resizes allocation to the new size and
// deep copies any previous contents. Otherwise, simply updates the value of `size()` to the
// newly requested size without any allocations or copies. Uses the specified stream.
buff_default.resize(100, stream);