def stream(stream):
"""Context-manager that selects a given stream.
All CUDA kernels queued within its context will be enqueued on a selected
stream.
Arguments:
stream (Stream): selected stream. This manager is a no-op if it's
``None``.
"""
if stream is None:
yield
return
prev_stream = current_stream()
torch._C._cuda_setStream(stream._cdata)
try:
yield
finally:
torch._C._cuda_setStream(prev_stream._cdata)
评论列表
文章目录