mindspore.ops.communication.isend

查看源文件
mindspore.ops.communication.isend(tensor, dst=0, group=None, tag=0)[源代码]

异步将张量发送到指定的目标rank。

说明

当前仅支持PyNative模式,不支持Graph模式。

参数:
  • tensor (Tensor) - 要发送的张量。

  • dst (int, 可选) - 标识目标rank(全局rank)的整数。默认值: 0

  • group (str,可选) - 通信组名称。默认值: None ,即Ascend平台表示为 "hccl_world_group"

  • tag (int, 可选) - 标识发送/接收消息标签的整数。消息将被具有相同 tag 的Receive操作接收。默认值: 0。当前为预留参数。

返回:

CommHandle,它是一个异步工作句柄。

异常:
  • TypeError - tensor 不是Tensor,dst 不是int或 group 不是str。

  • ValueError - 如果 dst 进程rank id与当前进程相同。

支持平台:

Ascend

样例:

说明

运行以下样例之前,需要配置好通信环境变量。

针对Ascend设备,推荐使用msrun启动方式,无第三方以及配置文件依赖。详见 msrun启动

该样例需要在2卡环境下运行。

>>> 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.]]