mindspore.ops.communication.irecv
- mindspore.ops.communication.irecv(tensor, src=0, group=None, tag=0)[源代码]
异步从src接收张量。
说明
当前仅支持PyNative模式,不支持Graph模式。
- 参数:
tensor (Tensor) - 如果函数以in-place模式运行,则用于填充接收数据的张量。否则,表示用于接收张量的shape和dtype,但输入 tensor 的值不会生效。
src (int, 可选) - 标识源rank(全局rank)的整数。默认值:
0。group (str,可选) - 通信组名称。默认值:
None,即Ascend平台表示为"hccl_world_group"。tag (int, 可选) - 标识发送/接收消息标签的整数。消息将被具有相同 tag 的Send操作接收。默认值:
0。当前为预留参数。
- 返回:
若函数以in-place模式运行,返回CommHandle。
若函数以非in-place模式运行,返回Tuple(Tensor, CommHandle)。第一个元素存储输出结果,第二个元素是CommHandle。
其中,当 async_op 是
True,则CommHandle是一个异步工作句柄;当 async_op 是False,则CommHandle将返回None。- 异常:
TypeError - tensor 的类型不是Tensor,src 不是int或 group 不是str。
ValueError - 如果进程的rank ID大于通信组的rank size。
- 支持平台:
Ascend
样例:
>>> from mindspore.ops.communication import init_process_group >>> from mindspore.ops.communication import isend, irecv, get_rank >>> from mindspore import Tensor >>> import numpy as np >>> # Launch 2 processes, Process 0 sends the array to Process 1. >>> init_process_group() >>> this_rank = get_rank() >>> if this_rank == 0: ... input_ = Tensor(np.ones([2, 8]).astype(np.float32)) ... handle = isend(input_, 1) ... handle.wait() >>> if this_rank == 1: ... x = Tensor(np.zeros([2, 8]).astype(np.float32)) ... handle = irecv(x, src=0) ... handle.wait() ... print(x) rank 1: [[1. 1. 1. 1. 1. 1. 1. 1.] [1. 1. 1. 1. 1. 1. 1. 1.]]