mindspore.mint.distributed.P2POp

查看源文件
class mindspore.mint.distributed.P2POp(op, tensor, peer, group=None, tag=0)[源代码]

用于存放与 'isend''irecv' 相关的信息,并作为 batch_isend_irecv 接口的入参。

说明

  • op'irecv' 时,tensor 会被接收结果原地修改。

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

参数:
  • op (Union[str, function]) - 对于字符串类型,只允许 'isend''irecv'。对于函数类型,只允许 distributed.isenddistributed.irecv 函数。

  • tensor (Tensor) - 用于发送或接收的张量。

  • peer (int) - 发送或接收的远程设备的全局编号。

  • group (str,可选) - 工作的通信组,默认值: None (即Ascend平台为 "hccl_world_group")。

  • tag (int,可选) - 当前暂不支持。默认值: 0

返回:

P2POp 对象。

异常:
  • TypeError - 当 op 不是与 'isend''irecv' 相关的字符串或函数。

  • TypeError - 当 tensor 不是张量, peer 不是int。

  • NotImplementedError - 当 tag 入参不为0。

样例:

说明

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

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

支持平台:

Ascend

样例:

>>> import numpy as np
>>> import mindspore
>>> from mindspore.mint.distributed import P2POp, isend, irecv
>>> from mindspore import Tensor
>>> # Launch 2 processes.
>>> send_tensor = Tensor(1.)
>>> send_op = P2POp('isend', send_tensor, 1)
>>> send_op = P2POp(isend, send_tensor, 1)
>>> recv_tensor = Tensor(0.)
>>> recv_op = P2POp('irecv', recv_tensor, 0)
>>> recv_op = P2POp(irecv, recv_tensor, 0)