数据容器

group Data Containers
class device_buffer
#include <device_buffer.hpp>

用于设备内存分配的 RAII 构造。

此类别使用 device_async_resource_ref 分配无类型且未初始化的设备内存。如果未明确指定,则使用从 get_current_device_resource_ref() 返回的内存资源。

示例

//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);

注意

std::vectorthrust::device_vector 不同,device_buffer 分配的设备内存是未初始化的。因此,在首次初始化之前读取 data() 的内容是未定义行为。

公共函数

inline device_buffer()

默认构造函数创建一个空的 device_buffer

inline explicit device_buffer(std::size_t size, cuda_stream_view stream, device_async_resource_ref mr = mr::get_current_device_resource_ref())

构造一个大小为 size 字节的未初始化设备缓冲区。

抛出:

rmm::bad_alloc – 如果分配失败。

参数:
  • size – 要在设备内存中分配的字节大小。

  • stream – 如果内存资源支持流,则可以在其上分配内存的 CUDA 流。

  • mr – 用于设备内存分配的内存资源。

inline device_buffer(void const *source_data, std::size_t size, cuda_stream_view stream, device_async_resource_ref mr = mr::get_current_device_resource_ref())

通过从现有主机或设备内存分配的原始指针复制来构造新的设备缓冲区。

注意

此函数不会同步 streamsource_datastream 上复制,因此调用方负责进行正确的同步,以确保复制发生时 source_data 有效。这包括在此函数调用后按流顺序销毁 source_data,或者在此函数返回后根据需要同步或等待 stream

抛出:
参数:
  • source_data – 指向要从中复制的主机或设备内存的指针。

  • size – 要复制的字节大小。

  • stream – 如果内存资源支持流,则可以在其上分配内存的 CUDA 流。

  • mr – 用于设备内存分配的内存资源

inline device_buffer(device_buffer const &other, cuda_stream_view stream, device_async_resource_ref mr = mr::get_current_device_resource_ref())

通过深拷贝另一个 device_buffer 的内容来构造新的 device_buffer,可选择使用指定的流和内存资源。

注意

仅从 other 复制 other.size() 字节,即如果 other.size() != other.capacity(),则新构造的 device_buffer 的大小和容量将等于 other.size()

注意

此函数不会同步 streamotherstream 上复制,因此调用方负责进行正确的同步,以确保复制发生时 other 有效。这包括在此函数调用后按流顺序销毁 other,或者在此函数返回后根据需要同步或等待 stream

抛出:
参数:
  • other – 其内容将被复制的 device_buffer

  • stream – 用于分配和复制的流

  • mr – 用于分配新 device_buffer 的资源

inline device_buffer(device_buffer &&other) noexcept

通过将另一个 device_buffer 的内容移动到新构造的缓冲区中来构造新的 device_buffer

device_buffer 构造完成后,other 被修改为一个有效的空 device_buffer,即 data() 返回 nullptr,且 size()capacity() 为零。

参数:

other – 其内容将被移动到新构造的缓冲区中的 device_buffer

inline device_buffer &operator=(device_buffer &&other) noexcept

移动赋值运算符移动 other 中的内容。

device_buffer 当前的设备内存分配将在 stream() 上被释放。

如果需要不同的流,请在赋值前在此实例上调用 set_stream()。赋值后,此实例的流将被 other.stream() 替换。

参数:

other – 其内容将被移动的 device_buffer

返回:

对此 device_buffer 的引用

inline ~device_buffer() noexcept

销毁设备缓冲区对象。

注意

如果内存资源支持流,此析构函数将使用最近传递给此设备缓冲区任何方法的流进行释放。

inline void reserve(std::size_t new_capacity, cuda_stream_view stream)

增加设备内存分配的容量。

如果请求的 new_capacity 小于或等于 capacity(),则不执行任何操作。

如果 new_capacity 大于 capacity(),则在 stream 上进行新的分配以满足 new_capacity,并且在 stream 上将旧分配的内容复制到新分配中。然后释放旧分配。从 [size(), new_capacity) 的字节是未初始化的。

抛出:
参数:
  • new_capacity – 请求的新容量,以字节为单位

  • stream – 用于分配和复制的流

inline void resize(std::size_t new_size, cuda_stream_view stream)

调整设备内存分配的大小。

如果请求的 new_size 小于或等于 capacity(),则除了更新 size() 返回的值外,不执行任何操作。具体来说,不分配或复制任何内存。capacity() 的值仍是设备内存分配的实际大小。

如果 new_size 大于 capacity(),则在 stream 上进行新的分配以满足 new_size,并在 stream 上将旧分配的内容复制到新分配中。然后释放旧分配。从 [old_size, new_size) 的字节是未初始化的。

不变式 size() <= capacity() 成立。

注意

shrink_to_fit() 可用于强制释放未使用的 capacity()

抛出:
参数:
  • new_size – 请求的新大小,以字节为单位

  • stream – 用于分配和复制的流

inline void shrink_to_fit(cuda_stream_view stream)

强制释放未使用的内存。

在流 stream 上重新分配并复制设备内存分配的内容,将 capacity() 减小到 size()

如果 size() == capacity(),则不进行分配或复制。

抛出:
参数:

stream – 执行分配和复制的流

inline void const *data() const noexcept

指向设备内存分配的 const 指针。

返回:

指向设备内存分配的 const 指针

inline void *data() noexcept

指向设备内存分配的指针。

返回:

指向设备内存分配的指针

inline std::size_t size() const noexcept

字节数。

返回:

字节数

inline std::int64_t ssize() const noexcept

带符号的字节数。

返回:

带符号的字节数

inline bool is_empty() const noexcept

缓冲区当前是否包含任何数据。

如果 is_empty() == true,如果 capacity() > 0,则 device_buffer 可能仍然持有分配。

返回:

缓冲区当前是否包含任何数据

inline std::size_t capacity() const noexcept

返回设备内存分配的实际字节大小。

不变式 size() <= capacity() 成立。

返回:

设备内存分配的实际字节大小

inline cuda_stream_view stream() const noexcept

最近指定用于分配/释放的流。

返回:

最近指定用于分配/释放的流

inline void set_stream(cuda_stream_view stream) noexcept

设置用于释放的流。

在此调用后,如果没有其他分配内存的 rmm::device_buffer 方法使用不同的流参数被调用,则 stream 将在 rmm::device_uvector 析构函数中用于释放。但是,如果在之后调用了 resize()shrink_to_fit(),则后一个流参数将被存储并在析构函数中使用。

参数:

stream – 用于释放的流

inline rmm::device_async_resource_ref memory_resource() const noexcept

用于分配和释放的资源。

返回:

用于分配和释放的资源

template<typename T>
class device_scalar
#include <device_scalar.hpp>

设备内存中类型为 T 的单个对象的容器。

T 必须是可平凡复制 (trivially copyable) 的。

模板参数:

T – 对象的类型

公共类型

using value_type = typename device_uvector<T>::value_type

T;标量元素的类型。

using size_type = typename device_uvector<T>::size_type

用于大小的类型。

using reference = typename device_uvector<T>::reference

value_type&

using const_reference = typename device_uvector<T>::const_reference

const value_type&

using pointer = typename device_uvector<T>::pointer

data() 返回的指针类型

using const_pointer = typename device_uvector<T>::const_pointer

data() const 返回的 const 指针类型。

公共函数

device_scalar(device_scalar&&) noexcept = default

默认移动构造函数。

device_scalar &operator=(device_scalar&&) noexcept = default

默认移动赋值运算符。

返回:

device_scalar& 对被赋值对象的引用

device_scalar(device_scalar const&) = delete

复制构造函数被删除,因为它不允许流参数。

device_scalar &operator=(device_scalar const&) = delete

复制赋值运算符被删除,因为它不允许流参数。

device_scalar() = delete

默认构造函数被删除,因为它不允许流参数。

inline explicit device_scalar(cuda_stream_view stream, device_async_resource_ref mr = mr::get_current_device_resource_ref())

构造一个新的未初始化的 device_scalar

不同步流。

注意

device_scalar 仅在指定的 CUDA 流上的内核和复制中安全访问,或者仅在强制建立依赖关系(例如使用 cudaStreamWaitEvent())时才在其他流上安全访问。

抛出:

rmm::bad_alloc – 如果分配设备内存失败。

参数:
  • stream – 执行异步分配的流。

  • mr – 可选,用于分配的资源。

inline explicit device_scalar(value_type const &initial_value, cuda_stream_view stream, device_async_resource_ref mr = mr::get_current_device_resource_ref())

构造一个带有初始值的新 device_scalar

不同步流。

注意

device_scalar 仅在指定的 CUDA 流上的内核和复制中安全访问,或者仅在强制建立依赖关系(例如使用 cudaStreamWaitEvent())时才在其他流上安全访问。

抛出:
  • rmm::bad_alloc – 如果为 initial_value 分配设备内存失败。

  • rmm::cuda_error – 如果将 initial_value 复制到设备内存失败。

参数:
  • initial_value – 设备内存中对象的初始值。

  • stream – 可选,执行分配和复制的流。

  • mr – 可选,用于分配的资源。

inline device_scalar(device_scalar const &other, cuda_stream_view stream, device_async_resource_ref mr = mr::get_current_device_resource_ref())

使用指定的流和内存资源,通过深拷贝另一个 device_scalar 的内容来构造新的 device_scalar

抛出:
参数:
  • other – 其内容将被复制的 device_scalar

  • stream – 用于分配和复制的流

  • mr – 用于分配新 device_scalar 的资源

inline value_type value(cuda_stream_view stream) const

将值从设备复制到主机,同步并返回值。

将数据从设备复制到主机后同步 stream

注意

如果此函数指定的流与构造函数指定的流不同,则在此函数调用之前必须在流之间插入适当的依赖关系(例如使用 cudaStreamWaitEvent()cudaStreamSynchronize()),否则可能存在竞态条件。

抛出:
参数:

stream – 执行复制和同步的 CUDA 流。

返回:

T 标量的值。

inline void set_value_async(value_type const &value, cuda_stream_view stream)

device_scalar 的值设置为 v 的值。

此对基本类型的特殊化经过优化,当 v 为零时使用 cudaMemsetAsync

此函数返回前不会同步 stream。因此,在 stream 同步之前,不应销毁或修改由 v 引用的对象。否则,行为未定义。

示例

rmm::device_scalar<int32_t> s;

int v{42};

// Copies 42 to device storage on `stream`. Does _not_ synchronize
vec.set_value_async(v, stream);
...
cudaStreamSynchronize(stream);
// Synchronization is required before `v` can be modified
v = 13;

注意

如果此函数指定的流与构造函数指定的流不同,则在此函数调用前后必须在流之间插入适当的依赖关系(例如使用 cudaStreamWaitEvent()cudaStreamSynchronize()),否则可能存在竞态条件。

注意

: 此函数会发生主机到设备的 memcpy 或设备 memset,应谨慎使用。

抛出:

rmm::cuda_error – 如果将 value 复制到设备内存失败。

参数:
  • value – 将被复制到设备的主机值

  • stream – 执行复制的 CUDA 流

inline void set_value_to_zero_async(cuda_stream_view stream)

在指定的流上将 device_scalar 的值设置为零。

此函数返回前不会同步 stream

注意

如果此函数指定的流与构造函数指定的流不同,则在此函数调用前后必须在流之间插入适当的依赖关系(例如使用 cudaStreamWaitEvent()cudaStreamSynchronize()),否则可能存在竞态条件。

注意

: 此函数会发生设备 memset,应谨慎使用。

参数:

stream – 执行复制的 CUDA 流

inline pointer data() noexcept

返回指向设备内存中对象的指针。

注意

如果在与构造函数指定的流不同的 CUDA 流上使用返回的设备指针,则必须在流之间插入适当的依赖关系(例如使用 cudaStreamWaitEvent()cudaStreamSynchronize()),否则可能存在竞态条件。

返回:

指向底层设备内存的指针

inline const_pointer data() const noexcept

返回指向设备内存中对象的 const 指针。

注意

如果在与构造函数指定的流不同的 CUDA 流上使用返回的设备指针,则必须在流之间插入适当的依赖关系(例如使用 cudaStreamWaitEvent()cudaStreamSynchronize()),否则可能存在竞态条件。

返回:

指向底层设备内存的 const 指针

inline constexpr size_type size() const noexcept

标量的大小:始终为 1。

返回:

标量的大小:始终为 1

inline cuda_stream_view stream() const noexcept

与设备内存分配关联的流。

返回:

与设备内存分配关联的流

inline void set_stream(cuda_stream_view stream) noexcept

设置用于释放的流。

参数:

stream – 用于释放的流

template<typename T>
class device_uvector
#include <device_uvector.hpp>

设备内存中未初始化的元素向量。

类似于 thrust::device_vectordevice_uvector 是一个随机访问容器,其元素连续存储在设备内存中。然而,与 thrust::device_vector 不同,device_uvector 默认初始化向量元素。

如果需要初始化,必须由调用方显式完成,例如使用 thrust::uninitialized_fill

示例

auto mr = new my_custom_resource();
rmm::cuda_stream_view s{};

// Allocates *uninitialized* device memory on stream `s` sufficient for 100 ints using the
// supplied resource `mr`
rmm::device_uvector<int> uv(100, s, mr);

// Initializes all elements to 0 on stream `s`
thrust::uninitialized_fill(thrust::cuda::par.on(s), uv.begin(), uv.end(), 0);

避免默认初始化通过消除默认初始化元素所需的内核启动来提高性能。这种初始化通常是不必要的,例如在创建向量来保存某个操作的输出时。

然而,这限制了元素类型 T 只能是可平凡复制 (trivially copyable) 的类型。简而言之,可平凡复制的类型可以使用 memcpy 安全地复制。更多信息请参见 https://cppreference.cn/w/cpp/types/is_trivially_copyable

thrust::device_vector 的另一个关键区别在于,所有调用分配、内核或内存复制的操作都接受一个 CUDA 流参数,以指示将在哪个流上执行操作。

模板参数:

T – 可平凡复制的元素类型

公共类型

using value_type = T

T;存储的值类型。

using size_type = std::size_t

用于向量大小的类型。

using reference = value_type&

value_type&;由 operator[](size_type) 返回的引用类型

using const_reference = value_type const&

value_type const&;由 operator[](size_type) const 返回的常量引用类型

using pointer = value_type*

data() 返回的指针类型

using const_pointer = value_type const*

data() const 返回的指针类型。

using iterator = pointer

begin() 返回的迭代器类型

using const_iterator = const_pointer

cbegin() 返回的常量迭代器类型。

公共函数

device_uvector(device_uvector&&) noexcept = default

默认移动构造函数。

device_uvector &operator=(device_uvector&&) noexcept = default

默认移动赋值运算符。

返回:

device_uvector& 对被赋值对象的引用

device_uvector(device_uvector const&) = delete

复制构造函数被删除,因为它不允许流参数。

device_uvector &operator=(device_uvector const&) = delete

复制赋值运算符被删除,因为它不允许流参数。

device_uvector() = delete

默认构造函数被删除,因为它不允许流参数。

inline explicit device_uvector(std::size_t size, cuda_stream_view stream, device_async_resource_ref mr = mr::get_current_device_resource_ref())

构造一个新的 device_uvector,为其 size 个元素分配足够的未初始化存储空间。

元素未初始化。在初始化之前读取元素会导致未定义行为。

参数:
  • size – 要分配存储空间的元素数量

  • stream – 用于执行分配的流

  • mr – 用于分配设备存储空间的资源

inline explicit device_uvector(device_uvector const &other, cuda_stream_view stream, device_async_resource_ref mr = mr::get_current_device_resource_ref())

通过深度复制另一个 device_uvector 的内容来构造一个新的 device_uvector

元素的复制方式类似于 memcpy,即不调用 T 的复制构造函数。

参数:
  • other – 要复制的向量

  • stream – 用于执行复制的流

  • mr – 用于为新向量分配设备内存的资源

inline pointer element_ptr(std::size_t element_index) noexcept

返回指向指定元素的指针。

如果 element_index >= size(),则行为未定义。

参数:

element_index – 指定元素的索引。

返回:

T* 指向所需元素的指针

inline const_pointer element_ptr(std::size_t element_index) const noexcept

返回指向指定元素的指针。

如果 element_index >= size(),则行为未定义。

参数:

element_index – 指定元素的索引。

返回:

T* 指向所需元素的指针

inline void set_element_async(std::size_t element_index, value_type const &value, cuda_stream_view stream)

执行将 v 异步复制到设备内存中指定元素的操作。

对于基本类型的此特化进行了优化,以便在 host_value 为零时使用 cudaMemsetAsync

此函数在返回前不会同步流 s。因此,在流 stream 同步之前,不应销毁或修改 v 引用的对象。否则,行为未定义。

示例

rmm::device_uvector<int32_t> vec(100, stream);

int v{42};

// Copies 42 to element 0 on `stream`. Does _not_ synchronize
vec.set_element_async(0, v, stream);
...
cudaStreamSynchronize(stream);
// Synchronization is required before `v` can be modified
v = 13;

注意

此函数会产生一次主机到设备的 memcpy,应谨慎使用。

注意

不允许使用字面量或其他右值引用调用此函数,以防止实现在字面量或其他隐式临时对象被删除或超出作用域后对其进行异步复制。

抛出:

rmm::out_of_range – 如果 element_index >= size() 则抛出异常。

参数:
  • element_index – 目标元素的索引

  • value – 要复制到指定元素的值

  • stream – 用于执行复制的流

inline void set_element_to_zero_async(std::size_t element_index, cuda_stream_view stream)

在设备内存中异步将指定元素设置为零。

此函数在返回前不会同步流 s

示例

rmm::device_uvector<int32_t> vec(100, stream);

int v{42};

// Sets element at index 42 to 0 on `stream`. Does _not_ synchronize
vec.set_element_to_zero_async(42, stream);

注意

此函数会产生一次设备 memset,应谨慎使用。

抛出:

rmm::out_of_range – 如果 element_index >= size() 则抛出异常。

参数:
  • element_index – 目标元素的索引

  • stream – 用于执行复制的流

inline void set_element(std::size_t element_index, T const &value, cuda_stream_view stream)

执行将 v 同步复制到设备内存中指定元素的操作。

因为此函数会同步流 s,所以在函数返回后销毁或修改 v 引用的对象是安全的。

示例

rmm::device_uvector<int32_t> vec(100, stream);

int v{42};

// Copies 42 to element 0 on `stream` and synchronizes the stream
vec.set_element(0, v, stream);

// It is safe to destroy or modify `v`
v = 13;

注意

此函数会产生一次主机到设备的 memcpy,应谨慎使用。

注意

此函数会同步 stream

抛出:

rmm::out_of_range – 如果 element_index >= size() 则抛出异常。

参数:
  • element_index – 目标元素的索引

  • value – 要复制到指定元素的值

  • stream – 用于执行复制的流

inline value_type element(std::size_t element_index, cuda_stream_view stream) const

从设备内存中返回指定元素。

注意

此函数会产生一次设备到主机的 memcpy,应谨慎使用。

注意

此函数会同步 stream

抛出:

rmm::out_of_range – 如果 element_index >= size() 则抛出异常。

参数:
  • element_index – 所需元素的索引

  • stream – 用于执行复制的流

返回:

指定元素的值

inline value_type front_element(cuda_stream_view stream) const

返回第一个元素。

注意

此函数会产生一次设备到主机的 memcpy,应谨慎使用。

注意

此函数会同步 stream

抛出:

rmm::out_of_range – 如果向量为空则抛出异常。

参数:

stream – 用于执行复制的流

返回:

第一个元素的值

inline value_type back_element(cuda_stream_view stream) const

返回最后一个元素。

注意

此函数会产生一次设备到主机的 memcpy,应谨慎使用。

注意

此函数会同步 stream

抛出:

rmm::out_of_range – 如果向量为空则抛出异常。

参数:

stream – 用于执行复制的流

返回:

最后一个元素的值

inline void reserve(std::size_t new_capacity, cuda_stream_view stream)

增加向量的容量至 new_capacity 个元素。

如果 new_capacity <= capacity(),则不采取任何行动。

如果 new_capacity > capacity(),则创建一个大小为 new_capacity 的新分配,并将当前分配中的前 size() 个元素通过 memcpy 的方式复制到新分配中。最后,释放旧分配并替换为新分配。

参数:
  • new_capacity – 所需容量(元素数量)

  • stream – 用于执行分配/复制(如果有)的流

inline void resize(std::size_t new_size, cuda_stream_view stream)

调整向量大小至包含 new_size 个元素。

如果 new_size > size(),则附加元素未初始化。

如果 new_size < capacity(),除了更新 size() 的值外,不采取任何行动。没有分配或复制内存。shrink_to_fit() 可用于强制释放未使用内存。

如果 new_size > capacity(),元素通过 memcpy 的方式复制到新分配中。

不变量 size() <= capacity() 成立。

参数:
  • new_size – 所需元素数量

  • stream – 用于执行分配/复制(如果有)的流

inline void shrink_to_fit(cuda_stream_view stream)

强制释放未使用的设备内存。

如果 capacity() > size(),则重新分配并复制向量内容以消除未使用内存。

参数:

stream – 执行分配和复制的流

inline device_buffer release() noexcept

释放设备内存存储空间的所有权。

返回:

用于存储向量元素的 device_buffer

inline std::size_t capacity() const noexcept

返回当前分配的存储空间可以容纳的元素数量。

返回:

std::size_t 无需新分配即可存储的元素数量。

inline pointer data() noexcept

返回指向底层设备存储空间的指针。

注意

如果 size() == 0,则解引用返回的指针是未定义行为。此外,返回的指针可能等于也可能不等于 nullptr

返回:

指向设备内存中元素存储空间的原始指针。

inline const_pointer data() const noexcept

返回指向底层设备存储空间的常量指针。

注意

如果 size() == 0,则解引用返回的指针是未定义行为。此外,返回的指针可能等于也可能不等于 nullptr

返回:

const_pointer 指向设备内存中元素存储空间的原始常量指针。

inline iterator begin() noexcept

返回指向第一个元素的迭代器。

如果向量为空,则 begin() == end()

返回:

指向第一个元素的迭代器。

inline const_iterator cbegin() const noexcept

返回指向第一个元素的常量迭代器。

如果向量为空,则 cbegin() == cend()

返回:

指向第一个元素的不可变迭代器。

inline const_iterator begin() const noexcept

返回指向第一个元素的常量迭代器。

如果向量为空,则 begin() == end()

返回:

指向第一个元素的不可变迭代器。

inline iterator end() noexcept

返回指向向量最后一个元素之后一个位置的迭代器。

end() 引用的元素是一个占位符,解引用它会导致未定义行为。

返回:

指向最后一个元素后一个位置的迭代器。

inline const_iterator cend() const noexcept

返回指向向量最后一个元素之后一个位置的常量迭代器。

end() 引用的元素是一个占位符,解引用它会导致未定义行为。

返回:

指向最后一个元素后一个位置的不可变迭代器。

inline const_iterator end() const noexcept

返回指向向量最后一个元素之后一个位置的迭代器。

end() 引用的元素是一个占位符,解引用它会导致未定义行为。

返回:

指向最后一个元素后一个位置的不可变迭代器。

inline std::size_t size() const noexcept

向量中的元素数量。

返回:

向量中的元素数量

inline std::int64_t ssize() const noexcept

向量中带符号的元素数量。

返回:

向量中带符号的元素数量

inline bool is_empty() const noexcept

如果向量不包含任何元素,即 size() == 0,则返回 true。

返回:

如果向量不包含任何元素,即 size() == 0,则返回 true。

inline rmm::device_async_resource_ref memory_resource() const noexcept

用于分配和释放设备存储空间的资源。

返回:

用于分配和释放设备存储空间的资源

inline cuda_stream_view stream() const noexcept

最近指定的用于分配/释放的流。

返回:

最近指定的用于分配/释放的流

inline void set_stream(cuda_stream_view stream) noexcept

设置用于释放的流。

如果在调用此方法之后,没有调用其他分配内存的 rmm::device_uvector 方法且使用了不同的流参数,则 stream 将用于 rmm::device_uvector 的析构函数中的释放。然而,如果在此之后调用了 resize()shrink_to_fit() 中的任何一个,则后来的流参数将被存储并在析构函数中使用。

参数:

stream – 用于释放的流