
    9j                     R   d dl Z d dlZd dlmZ d dlZg dZd Zd Zd Z	d Z
d Zdej                  eej                     z  d	dfd
ZdeddfdZdd eddfdddeej                     dej                  eej                     z  dz  dededeej                   j"                     dz  deej                     dz  d	dfdZ	 ddeej                     ded	dfdZ	 	 ddeej                     deej                     d	dfdZeddfdeej                     deej                     ded	dfdZy)    N)Sequence)
all_reducereduce	broadcast
all_gatherreduce_scatterc                 4   t        t        j                  d      st        j                  dd       yt               }| D ]W  }|j                  r y|j                         s y|j                  s y|j                         }||v r y|j                  |       Y y)N_nccl_all_reducez)PyTorch is not compiled with NCCL support   
stacklevelFT)hasattrtorch_Cwarningswarnset	is_sparseis_contiguousis_cuda
get_deviceadd)tensorsdevicestensordevices       O/media/conek/DATA/Code/OCR/venv/lib/python3.12/site-packages/torch/cuda/nccl.pyis_availabler      s    588/0AaPeG 
##%~~""$WF
     c                      t         j                  j                         } | dz	  }| dz	  dz  }| dz  }t         j                  j                         j	                  d      }|dk(  r|||fS ||||fS )a  
    Returns the version of the NCCL.


    This function returns a tuple containing the major, minor, and patch version numbers of the NCCL.
    The suffix is also included in the tuple if a version suffix exists.
    Returns:
        tuple: The version information of the NCCL.
           i  zutf-8 )r   r   _nccl_version_nccl_version_suffixdecode)vermajorminorpatchsuffixs        r   versionr,   #   sv     ((
 
 
"C2IEBY%E%KEXX**,33G<F|ue$$ueV,,r   c                  >    t         j                  j                         S N)r   r   _nccl_unique_id r   r   	unique_idr1   8   s    88##%%r   c                 D    t         j                  j                  | ||      S r.   )r   r   _nccl_init_rank)	num_ranksuidranks      r   	init_rankr7   <   s    88##IsD99r   inputsreturnc                     t        | t        j                  j                        rt        | t        j
                        rt        d      y )Nz(Inputs should be a collection of tensors)
isinstancecollectionsabc	Containerr   Tensor	TypeError)r8   s    r   _check_sequence_typerA   @   s9    fkoo778J= BCC=r   c                 ~    t        |        || }t        |       t        j                  j                  | ||||       y r.   )rA   r   r   r
   r8   outputsopstreamscommss        r   r   r   G   s6     !	HHfgr7EBr   )rD   outputrootrE   rF   rD   c                   t        |        |/|t        d      t        j                  dt        d       ||   }nit        |t        j                        sFt        |t        j                  j                        r"t        j                  dt        d       ||   }n	|| |   n|}t        j                  j                  | |||||       y )Nz'output' and 'outputs' can not be both specified. 'outputs' is deprecated in favor of 'output', taking in a single output tensor. The signature of reduce is: reduce(inputs, output=None, root=0, op=SUM, streams=None, comms=None).z`nccl.reduce` with an output tensor list is deprecated. Please specify a single output tensor with argument 'output' instead instead.r   r   z\nccl.reduce with an output tensor list is deprecated. Please specify a single output tensor.)rA   
ValueErrorr   r   FutureWarningr;   r   r?   r<   r=   r   r   _nccl_reduce)r8   rH   rI   rE   rF   rG   rD   _outputs           r   r   r   Q   s      Y  MM`	 dmG-*((3 	5		
 ,"(.&,f	HH&'4WeDr   c                 ^    t        |        t        j                  j                  | |||       y r.   )rA   r   r   _nccl_broadcast)r8   rI   rF   rG   s       r   r   r   |   s$      	HHVT7E:r   c                 t    t        |        t        |       t        j                  j                  | |||       y r.   )rA   r   r   _nccl_all_gather)r8   rD   rF   rG   s       r   r   r      s,      !	HHfgw>r   c                 v    t        |        t        |       t        j                  j                  | ||||       y r.   )rA   r   r   _nccl_reduce_scatterrC   s        r   r   r      s.      !	HH!!&'2wFr   )r   NN)NN)r<   r   collections.abcr   
torch.cudar   __all__SUMr   r,   r1   r7   r?   rA   r   intcudaStreamr   r   r   r   r0   r   r   <module>r\      s     $  P*-*&:D0F!F D4 D  $T C <@26
(E .2(EU\\"(ELL8ELL11D8(E (E 		(E
 ejj''(4/(E ell#d*(E 
(EX HL;U\\";*-;	; 
	?U\\"?ell#?
 
? 
	GU\\"	Gell#	G 		G 
	Gr   