
    &`i                         d dl mZmZ d dlmZmZmZmZmZ d dl	Z	d dl
mZ d dlmZ erd dlZeee         dgdf         Ze G d d	e                      ZdS )
    )ABCabstractmethod)TYPE_CHECKINGCallableListOptionalTupleN)ReduceOp)DeveloperAPItorch.dtypetorch.Tensorc                   N   e Zd ZdZededdfd            Zeded         fd            Zede	j
        j        defd	            Zedee         fd
            ZdefdZedddeddfd            Ze	 d dee         dddedee         ddf
d            Zeed                         Zeed                         Ze	 	 	 	 	 	 d!d            Zedddddeddfd            Zedddddeddfd            Zed"d            Zedefd            Zeedefd                        ZdS )#Communicatorz
    Communicator for a group of Compiled Graph actors on NVIDIA GPU.

    The Compiled Graph execution leverages this internally to support communication
    between actors in the group.
    rankreturnNc                     t           )a  
        Initialize the communicator from the actor.

        This is called once by Compiled Graph on each actor to initialize the
        communicator,before any other methods.

        Args:
            rank: The rank of this actor in the group.
        NotImplementedError)selfr   s     y/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/experimental/channel/communicator.py
initializezCommunicator.initialize   s
     "!    zray.actor.ActorHandlec                     t           )zH
        Get handles of all actors for this communicator group.
        r   r   s    r   get_actor_handleszCommunicator.get_actor_handles'   
    
 "!r   actorc                     t           )z|
        Return the given actor's rank in the group.

        Args:
            actor: The actor handle to look up.
        r   )r   r   s     r   get_rankzCommunicator.get_rank.   
     "!r   c                     t           )z+
        Return this actor's rank.
        r   r   s    r   get_self_rankzCommunicator.get_self_rank8   r   r   c                     t           )z:
        Return the number of ranks in the group.
        r   r   s    r   get_world_sizezCommunicator.get_world_size?   s
     "!r   valuer   	peer_rankc                     t           )a  
        Send a torch.Tensor to a peer.

        This returns when the send kernel has been queued, but the kernel may
        not have completed. Therefore, the caller should ensure that there are
        no concurrent writes to the sent `value` until the send has finished.

        Args:
            value: The torch.Tensor to send. It should already be on this
                actor's default device.
            peer_rank: The rank of the actor to send to.
        r   )r   r%   r&   s      r   sendzCommunicator.sendE   
     "!r   shapedtyper   	allocatorc                     t           )a+  
        Receive a torch.Tensor from a peer and synchronize.

        After this call returns, the receive buffer is safe to read from from
        any stream. An RayChannelError will be raised if an error occurred (e.g.,
        remote actor died), and the buffer is not safe to read.

        Args:
            shape: The shape of the tensor to receive.
            dtype: The dtype of the tensor to receive.
            peer_rank: The rank of the actor to receive from.
            allocator: A function to allocate the tensor to receive into.
        r   )r   r*   r+   r&   r,   s        r   recvzCommunicator.recvU   s
    * "!r   c                     t           )zM
        Return the torch stream context used for receiving tensors.
        r   r   s    r   recv_streamzCommunicator.recv_streaml   
     "!r   c                     t           )zK
        Return the torch stream context used for sending tensors.
        r   r   s    r   send_streamzCommunicator.send_streamt   r1   r   send_bufrecv_bufc                     t           )a!  
        Collectively allgather the tensor across the group.

        Args:
            send_buf: The input torch.tensor to allgather. It should already be
                on this actor's default device.
            recv_buf: The output torch.tensor to store the allgather result.
        r   )r   r4   r5   s      r   	allgatherzCommunicator.allgather|   r)   r   opc                     t           )aG  
        Collectively allreduce the tensor across the group.

        Args:
            send_buf: The input torch.tensor to allreduce. It should already be
                on this actor's default device.
            recv_buf: The output torch.tensor to store the allreduce result.
            op: The reduce operation.
        r   r   r4   r5   r8   s       r   	allreducezCommunicator.allreduce   
      "!r   c                     t           )aS  
        Collectively reducescatter the tensor across the group.

        Args:
            send_buf: The input torch.tensor to reducescatter. It should already be
                on this actor's default device.
            recv_buf: The output torch.tensor to store the reducescatter result.
            op: The reduce operation.
        r   r:   s       r   reducescatterzCommunicator.reducescatter   r<   r   c                     t           )z
        Destroy the GPU communicator.

        Any destruction and cleanup for the GPU communicator should be
        done here. Implement as a noop is nothing is needed.
        r   r   s    r   destroyzCommunicator.destroy   r    r   c                     t           )zC
        Return the type of the communicator (gpu or cpu).
        r   r   s    r   get_transport_namezCommunicator.get_transport_name   r   r   c                     t           )z;
        Return the unique id of the communicator.
        r   )clss    r   generate_communicator_idz%Communicator.generate_communicator_id   r1   r   )N)r4   r   r5   r   r   N)r   N) __name__
__module____qualname____doc__r   intr   r   r   rayr   ActorHandler   r   r"   r$   r(   r	   TorchTensorAllocatorr.   propertyr0   r3   r7   r
   r;   r>   r@   strrB   classmethodrE    r   r   r   r      s         
"s 
"t 
" 
" 
" ^
" "4(?#@ " " " ^" "ci3 " " " " ^" "x} " " " ^"" " " " " ". "S "T " " " ^"  59" "Sz" " 	"
 01" 
" " " ^", " " ^ X" " " ^ X" " " !" 
	" " " ^" " " !" 	"
 
" " " ^"" " " !" 	"
 
" " " ^"" " " " ^" "C " " " ^" " " " " ^ [" " "r   r   )abcr   r   typingr   r   r   r   r	   rK   ray.experimental.util.typesr
   ray.util.annotationsr   torchrJ   rM   r   rQ   r   r   <module>rW      s    # # # # # # # # A A A A A A A A A A A A A A 



 0 0 0 0 0 0 - - - - - - LLL
  s] ;^ KL  u" u" u" u" u"3 u" u" u" u" u"r   