mindspore.ops.Receive
- class mindspore.ops.Receive(sr_tag, src_rank, shape, dtype, group=GlobalComm.WORLD_COMM_GROUP, group_back=GlobalComm.WORLD_COMM_GROUP)[source]
Receive tensors from src_rank.
Note
Send and Receive must be used in combination and have same sr_tag.
- Parameters
sr_tag (int) – A required integer identifying the send/recv message tag. The message will will be send by the Send op with the same "sr_tag".
src_rank (int) – A required integer identifying the source rank.
shape (list[int]) – A required list identifying the shape of the tensor to be received.
dtype (Type) – A required Type identifying the type of the tensor to be received. The supported types: int8/int16/int32/float16/float32.
group (str, optional) – The communication group to work on. Default:
GlobalComm.WORLD_COMM_GROUP
.group_back (str, optional) – The communication group for backpropagation. Default:
GlobalComm.WORLD_COMM_GROUP
.
- Outputs:
Tensor, output has the same shape as the Tensor sent by Send operation.
- Raises
TypeError – If group is not a str.
RuntimeError – If device target is invalid, or backend is invalid, or distributed initialization fails.
ValueError – If the local rank id of the calling process in the group is larger than the group's rank size.
- Supported Platforms:
Ascend
GPU
Examples
Note
Before running the following examples, you need to configure the communication environment variables.
For Ascend/GPU/CPU devices, it is recommended to use the msrun startup method without any third-party or configuration file dependencies. Please see the msrun start up for more details.
This example should be run with 2 devices.
>>> import numpy as np >>> import mindspore.nn as nn >>> from mindspore.communication import init >>> from mindspore import Tensor >>> from mindspore import ops >>> >>> init() >>> class ReceiveNet(nn.Cell): >>> def __init__(self): >>> super(ReceiveNet, self).__init__() >>> self.recv = ops.Receive(sr_tag=0, src_rank=0, shape=[2, 8], dtype=ms.float32, >>> group="hccl_world_group") >>> >>> def construct(self): >>> out = self.recv() >>> return out >>> >>> net = Net() >>> output = net()
- Tutorial Examples: