在 CUDA 中,是否保证默认流等于 nullptr?

In CUDA, is it guaranteed that the default stream equals nullptr?

在 CUDA 的 driver_types.h 中我们有:

typedef __device_builtin__ struct CUstream_st *cudaStream_t;

并且在 cuda_runtime.h 中,我们在许多地方都有默认初始化的流参数。例如:

template<class T>
    static __inline__ __host__ cudaError_t cudaLaunchKernel(
    const T *func,
    dim3 gridDim,
    dim3 blockDim,
    void **args,
    size_t sharedMem = 0,
    cudaStream_t stream = 0
)

假定默认流是 (cudaStream) nullptr 有多安全?

在多个地方都记录了这种情况:

  1. Programming guide:

Kernel launches and host <-> device memory copies that do not specify any stream parameter, or equivalently that set the stream parameter to zero, are issued to the default stream.

  1. For example, cudaMemcpyAsync:

The copy can optionally be associated to a stream by passing a non-zero stream argument.

假设默认流等同于 (cudaStream_t) 0

似乎很安全