CUDA 流
- group CUDA 流
函数
-
inline bool operator==(cuda_stream_view lhs, cuda_stream_view rhs)
流的相等比较运算符。
- 参数:
lhs – 第一个要比较的流视图
rhs – 第二个要比较的流视图
- 返回:
如果相等则为 true,如果不等则为 false
-
inline bool operator!=(cuda_stream_view lhs, cuda_stream_view rhs)
流的不等比较运算符。
- 参数:
lhs – 第一个要比较的流视图
rhs – 第二个要比较的流视图
- 返回:
如果不等则为 true,如果相等则为 false
-
inline std::ostream &operator<<(std::ostream &os, cuda_stream_view stream)
用于打印/日志记录流的输出流运算符。
- 参数:
os – 输出 ostream
stream – 要输出的 cuda_stream_view
- 返回:
std::ostream& 输出 ostream
变量
-
static constexpr cuda_stream_view cuda_stream_default = {}
默认流(流 0)的静态 cuda_stream_view,方便使用。
-
static const cuda_stream_view cuda_stream_legacy{cudaStreamLegacy}
cudaStreamLegacy 的静态 cuda_stream_view,方便使用。
-
static const cuda_stream_view cuda_stream_per_thread{cudaStreamPerThread}
cudaStreamPerThread 的静态 cuda_stream_view,方便使用。
-
class cuda_stream
- #include <cuda_stream.hpp>
CUDA 流的拥有者包装器。
为 CUDA 流提供 RAII 生命周期语义。
公共函数
-
cuda_stream(cuda_stream&&) = default
移动构造函数(默认)
被移动走的 cuda_stream 无效,并且调用访问所拥有流的方法是未定义行为。
-
cuda_stream &operator=(cuda_stream&&) = default
移动赋值运算符(默认)
被移动走的 cuda_stream 无效,并且调用访问所拥有流的方法是未定义行为。
- 返回:
对此 cuda_stream 的引用
-
inline cuda_stream()
构造一个新的 cuda 流对象。
- 抛出:
rmm::cuda_error – 如果流创建失败
-
inline bool is_valid() const
如果拥有的流非空,则返回 true。
- 返回:
true 如果拥有的流尚未被显式移动,因此非空。
- 返回:
false 如果拥有的流已被显式移动,因此为空。
-
inline cudaStream_t value() const
获取包装的 CUDA 流的值。
- 返回:
cudaStream_t 包装的 CUDA 流。
-
inline explicit operator cudaStream_t() const noexcept
显式转换为 cudaStream_t。
-
inline cuda_stream_view view() const
创建包装的 CUDA 流的不可变、非拥有视图。
- 返回:
rmm::cuda_stream_view CUDA 流的视图
-
inline operator cuda_stream_view() const
隐式转换为 cuda_stream_view。
- 返回:
所拥有流的视图
-
inline void synchronize() const
同步所拥有的 CUDA 流。
调用
cudaStreamSynchronize()
。- 抛出:
rmm::cuda_error – 如果流同步失败
-
inline void synchronize_no_throw() const noexcept
同步所拥有的 CUDA 流。如果发生错误,不抛出异常。
调用
cudaStreamSynchronize()
并在发生错误时断言。
-
cuda_stream(cuda_stream&&) = default
-
class cuda_stream_pool
- #include <cuda_stream_pool.hpp>
一个 CUDA 流池。
提供对 CUDA 流对象集合的高效访问。
连续调用可能会返回相同流的
cuda_stream_view
。例如,一种可能的实现是维护一个cuda_stream
对象的循环缓冲区。公共函数
-
inline explicit cuda_stream_pool(std::size_t pool_size = default_size)
构造一个给定非零大小的新 cuda 流池对象。
- 抛出:
logic_error – 如果
pool_size
为零- 参数:
pool_size – 池中的流数量
-
inline rmm::cuda_stream_view get_stream() const noexcept
获取池中某个流的
cuda_stream_view
。此函数对于对同一函数的其他调用是线程安全的。
-
inline rmm::cuda_stream_view get_stream(std::size_t stream_id) const
获取与
stream_id
关联的流的cuda_stream_view
。stream_id
的等效值会返回指向同一底层流的 stream_view。此函数对于对同一函数的其他调用是线程安全的。
- 参数:
stream_id – 所需流的唯一标识符
- 返回:
-
inline std::size_t get_pool_size() const noexcept
获取池中的流数量。
此函数对于对同一函数的其他调用是线程安全的。
- 返回:
池中的流数量
公共静态属性
-
static constexpr std::size_t default_size = {16}
默认流池大小。
-
inline explicit cuda_stream_pool(std::size_t pool_size = default_size)
-
class cuda_stream_view
- #include <cuda_stream_view.hpp>
具有默认构造函数的强类型非拥有 CUDA 流包装器。
此包装器仅是一个“视图”:它不拥有所包装流的生命周期。
公共函数
-
constexpr cuda_stream_view(cuda_stream_view const&) = default
默认拷贝构造函数。
-
constexpr cuda_stream_view(cuda_stream_view&&) = default
默认移动构造函数。
-
constexpr cuda_stream_view &operator=(cuda_stream_view const&) = default
默认拷贝赋值运算符。
- 返回:
cuda_stream_view& 对赋值对象的引用
-
constexpr cuda_stream_view &operator=(cuda_stream_view&&) = default
默认移动赋值运算符。
- 返回:
cuda_stream_view& 对赋值对象的引用
-
inline constexpr cuda_stream_view(cudaStream_t stream) noexcept
从 cudaStream_t 构造的构造函数。
- 参数:
stream – 此视图的底层流
-
inline constexpr cuda_stream_view(cuda::stream_ref stream) noexcept
从 stream_ref 隐式转换。
- 参数:
stream – 此视图的底层流
-
inline constexpr cudaStream_t value() const noexcept
获取包装的流。
- 返回:
cudaStream_t 此 cuda_stream_view 引用的底层流
-
inline constexpr operator cudaStream_t() const noexcept
隐式转换为 cudaStream_t。
- 返回:
cudaStream_t 此 cuda_stream_view 引用的底层流
-
inline constexpr operator cuda::stream_ref() const noexcept
隐式转换为 stream_ref。
- 返回:
stream_ref 此 cuda_stream_view 引用的底层流
-
inline bool is_per_thread_default() const noexcept
如果包装的流是 CUDA 每线程默认流,则为 true
- 返回:
如果包装的流是 CUDA 每线程默认流,则为 true
-
inline bool is_default() const noexcept
如果包装的流显式是 CUDA 遗留默认流,则为 true
- 返回:
如果包装的流显式是 CUDA 遗留默认流,则为 true
-
inline void synchronize() const
同步视图化的 CUDA 流。
调用
cudaStreamSynchronize()
。- 抛出:
rmm::cuda_error – 如果流同步失败
-
inline void synchronize_no_throw() const noexcept
同步视图化的 CUDA 流。如果发生错误,不抛出异常。
调用
cudaStreamSynchronize()
并在发生错误时断言。
-
constexpr cuda_stream_view(cuda_stream_view const&) = default
-
inline bool operator==(cuda_stream_view lhs, cuda_stream_view rhs)