
    Αi[                        S SK Jr  S SKJr  S SKJrJr  S SKJr  S SK	J
r
JrJr  S SKJr  S SKJr  \(       a  S SKJr  S S	KJr  S S
K	Jr  S rS r   S           SS jjrg)    )annotations)TYPE_CHECKING)_C_ops	framework)data_feeder)_get_global_group_get_or_throw_group_rank_warn_cur_rank_not_in_group)_to_inplace_op)in_pir_mode)Tensor)task)Groupc                    U(       a  UR                   R                  X5      $ UR                   R                  XU5      nU(       a  UR                  " 5         U$ )N)process_groupbroadcast_on_calc_stream	broadcastwait)tensorsrc_rank_in_groupgroupsync_opuse_calc_streamr   s         q/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/distributed/communication/stream/broadcast.py_broadcast_in_dygraphr   #   sN     "";;
 	
 ((GLD		K    c                j   [         R                  " U S/ SQS5        Sn[        R                  " U40 [	        5       D6nUc  SOUR
                  n[        5       (       a#  [        U5      n[        [        U5      " XX5        g UR                  USU /0SU /0UUS.S9nU(       a  S	UR                  l        g g )
Nr   )float16float32float64int32int64int8uint8boolr   r   xout)rootring_id)typeinputsoutputsattrsdefault)r   check_variable_and_dtyper   LayerHelperlocalsidr   r   getattrr   	append_op	dist_attrexecution_stream)	r   r   r   r   r   op_typehelperr)   ops	            r   _broadcast_in_static_moder:   2   s     ((		
 	  G""77fh7F=aehhG}} ) 2CM			fX!%
	 
 
B (1% r   Nc                   [        U5      (       a  gU(       d  U(       a  [        S5      e[        R                  " 5       (       a'  Uc
  [	        5       OUn[        X5      n[        XX#U5      $ Ub   S5       e[        XX#U5      $ )a  

Broadcast a tensor to all devices.

Args:
    tensor (Tensor): The tensor to broadcast. Support float16, float32, float64, int32, int64, int8, uint8 or bool as its data type.
    src (int, optional): Rank of the source device.
    group (Group|None, optional): Communicate in which group. If none is given, use the global group as default.
    sync_op (bool, optional): Indicate whether the communication is sync or not. If none is given, use true as default.
    use_calc_stream (bool, optional): Indicate whether the communication is done on calculation stream. If none is given, use false as default. This
        option is designed for high performance demand, be careful to turn it on except you are clearly know its meaning.

Returns:
    Return a task object.

Warning:
    This API only supports the dygraph mode now.

Examples:
    .. code-block:: python

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

        >>> dist.init_parallel_env()
        >>> local_rank = dist.get_rank()
        >>> if local_rank == 0:
        ...     data = paddle.to_tensor([[4, 5, 6], [4, 5, 6]])
        >>> else:
        ...     data = paddle.to_tensor([[1, 2, 3], [1, 2, 3]])
        >>> task = dist.stream.broadcast(data, src=1, sync_op=False)
        >>> task.wait()  # type: ignore[union-attr]
        >>> out = data.numpy()
        >>> print(out)
        >>> # [[1, 2, 3], [1, 2, 3]] (2 GPUs)
Nz5use_calc_stream can only be True in sync op behavior.z3Group can not be used in static graph mode for now.)r
   RuntimeErrorr   in_dynamic_moder   r	   r   r:   )r   srcr   r   r   r   s         r   r   r   [   s    X #5))C
 	
   ""',}!#%4S@$u
 	
 } 	
A	
} )
 	
r   )NTF)r   r   r>   intr   zGroup | Noner   r%   r   r%   returnztask | None)
__future__r   typingr   paddler   r   paddle.baser   &paddle.distributed.communication.groupr   r	   r
   'paddle.distributed.communication.reducer   paddle.frameworkr   r   paddle.base.corer   r   r   r:   r    r   r   <module>rJ      s    #   $ # 
 C (%<&2X !A
A
	A
 A
 	A

 A
 A
r   