def METHOD_NAME(source: AbstractStream, target: AbstractStream) -> None:
    """:meth:`torch.cuda.Stream.wait_stream` for either CPU or CUDA stream. It
    makes the source stream wait until the target stream completes work queued.
    """
    if is_cuda(target):
        if is_cuda(source):
            # A CUDA stream waits another CUDA stream.
            as_cuda(source).METHOD_NAME(as_cuda(target))
        else:
            # CPU waits a CUDA stream.
            as_cuda(target).synchronize()
    # If the target is CPU, synchronization is not required.