
    Αis                        S SK Jr  S SKJrJr  S SKrS SKJr  S SKJ	r	J
r
  S SKJr  \(       a  S SKJr  S SKJr  S S	KJr     S         SS
 jjrSSS jjr   S       SS jjrg)    )annotations)TYPE_CHECKINGAnyN)stream)_get_global_group_warn_cur_rank_not_in_group)convert_object_to_tensor)Tensor)task)Groupc                .    [         R                  " XX#SS9$ )a  
Send a tensor to the receiver.

Args:
    tensor (Tensor): The Tensor to send. Its data type
        should be float16, float32, float64, int32, int64, int8, uint8, bool or bfloat16.
    dst (int): The destination rank id.
    group (Group, optional): The group instance return by new_group or None for global default group. Default: None.
    sync_op (bool, optional): Whether this op is a sync op. The default value is True.

Returns:
    Return a task object.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env: DISTRIBUTED)
        >>> import paddle
        >>> import paddle.distributed as dist

        >>> dist.init_parallel_env()
        >>> if dist.get_rank() == 0:
        ...     data = paddle.to_tensor([7, 8, 9])
        ...     dist.send(data, dst=1)
        >>> else:
        ...     data = paddle.to_tensor([1, 2, 3])
        ...     dist.recv(data, src=0)
        >>> print(data)
        >>> # [7, 8, 9] (2 GPUs)
F)dstgroupsync_opuse_calc_stream)r   send)tensorr   r   r   s       e/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/distributed/communication/send.pyr   r   #   s    H ;;uu     c                    [        XUSS9$ )a  
Send tensor asynchronously

Args:
    tensor (Tensor): The Tensor to send. Its data type
        should be float16, float32, float64, int32, int64, int8, uint8, bool or bfloat16.
    dst (int): The destination rank.
    group (Group, optional): The group instance return by new_group or None for global default group. Default: None.

Returns:
    Return a task object.

Warning:
    This API only supports the dygraph mode.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env: DISTRIBUTED)
        >>> import paddle
        >>> import paddle.distributed as dist

        >>> dist.init_parallel_env()
        >>> if dist.get_rank() == 0:
        ...     data = paddle.to_tensor([7, 8, 9])
        ...     task = dist.isend(data, dst=1)
        >>> else:
        ...     data = paddle.to_tensor([1, 2, 3])
        ...     task = dist.irecv(data, src=0)
        >>> task.wait()  # type: ignore[union-attr]
        >>> print(data)
        >>> # [7, 8, 9] (2 GPUs)

F)r   )r   )r   r   r   s      r   isendr   L   s    F UE22r   c                   U b  [        U 5      S:X  a  [        S5      eUc
  [        5       OUn[        U5      (       a  gUb   Ub  [        S5      eUR	                  U5      nOUc  SOUn[        U  Vs/ s H  n[        U5      PM     sn6 u  pVU Vs/ s H  owR                  5       PM     nn[        R                  " USS9n	[        XUS9  [        U5      S:X  a  US   n
O[        R                  " U5      n
[        XUS9  gs  snf s  snf )	a  
Send a list of Python objects to the receiver.

Args:
    object_list (list): The list of Python objects to send.
    dst (int, optional): The destination rank id. Default: 0.
    group (Group, optional): The group instance return by new_group or None for global default group. Default: None.
    dst_in_group (int, optional): The destination rank within the group. Cannot be specified together with dst. Default: None.

Returns:
    This function does not return any value.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env: DISTRIBUTED)
        >>> import paddle
        >>> import paddle.distributed as dist

        >>> dist.init_parallel_env()
        >>> if dist.get_rank() == 0:
        ...     data = ["hello", {"key": 100}, [1, 2, 3]]
        ...     dist.send_object_list(data, dst=1)
        >>> else:
        ...     data = [None] * 3  # type: ignore
        ...     dist.recv_object_list(data, src=0)
        >>> print(data)
        >>> # ["hello", {"key": 100}, [1, 2, 3]] (2 GPUs)
Nr   z#object_list cannot be None or emptyz7Cannot specify both 'dst' and 'dst_in_group' arguments.int64)dtype)r   r      )len
ValueErrorr   r   get_global_rankzipr	   itempaddle	to_tensorr   concat)object_listr   r   dst_in_groupobjtensor_list	size_listsizesize_list_valuesobject_sizes_tensorobject_tensors              r   send_object_listr-   r   s   F c+.!3>??#(=eE"5))?I  ##L1;aC !3>	?;C
"3
';	?K 1::				: !**+;7K	U3 ;1#Ak2u- 
@:s   1D D)r   NT)
r   r
   r   intr   Group | Noner   boolreturntask | None)N)r   r
   r   r.   r   r/   r1   r2   )NNN)r$   z	list[Any]r   
int | Noner   r/   r%   r3   )
__future__r   typingr   r   r!    paddle.distributed.communicationr   &paddle.distributed.communication.groupr   r   4paddle.distributed.communication.serialization_utilsr	   r
   paddle.base.corer   r   r   r   r-    r   r   <module>r;      s    # %  3 %<
 	&&	& & 	&
 &R#3P #	B.B.	B. B. 	B.r   