Ë
    :�Djì  ã                   ó°  — d Z ddlZddlZddlZddlZddlmZmZ ddlm	Z	m
Z
mZmZ ddlZddlmZ ddlmZmZmZmZmZmZ  ej0                  d«      Zd	e	d
dfd„Zdd„Zd
efd„Zd
efd„Zd
efd„Zde	d
dfd„Z d
e!fd„Z"deded
efd„Z#dejH                  d
efd„Z%e G d„ de«      «       Z&dejN                  de&d
ejN                  fd„Z(dd„Z) G d„ d«      Z*y) z-XGBoost collective communication related API.é    N)ÚIntEnumÚunique)ÚAnyÚDictÚListÚOptionalé   )Ú_T)Ú_LIBÚ_check_callÚ
build_infoÚc_strÚmake_jcargsÚpy_strz[xgboost.collective]ÚargsÚreturnc            	      óR   — t        t        j                  t        di | ¤Ž«      «       y)aã  Initialize the collective library with arguments.

    Parameters
    ----------
    args :
        Keyword arguments representing the parameters and their values.

        Accepted parameters:
          - dmlc_communicator: The type of the communicator.
            * rabit: Use Rabit. This is the default if the type is unspecified.
            * federated: Use the gRPC interface for Federated Learning.

        Only applicable to the Rabit communicator:
          - dmlc_tracker_uri: Hostname of the tracker.
          - dmlc_tracker_port: Port number of the tracker.
          - dmlc_task_id: ID of the current task, can be used to obtain deterministic
          - dmlc_retry: The number of retry when handling network errors.
          - dmlc_timeout: Timeout in seconds.
          - dmlc_nccl_path: Path to load (dlopen) nccl for GPU-based communication.

        Only applicable to the Federated communicator (use upper case for environment
        variables, use lower case for runtime configuration):

          - federated_server_address: Address of the federated server.
          - federated_world_size: Number of federated workers.
          - federated_rank: Rank of the current worker.
          - federated_server_cert: Server certificate file path. Only needed for the SSL
            mode.
          - federated_client_key: Client key file path. Only needed for the SSL mode.
          - federated_client_cert: Client certificate file path. Only needed for the SSL
            mode.
    N© )r   r   ÚXGCommunicatorInitr   )r   s    úVC:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\xgboost/collective.pyÚinitr      s    € ôB ”×'Ñ'¬Ñ(;°dÑ(;Ó<Õ=ó    c                  ó>   — t        t        j                  «       «       y)zFinalize the communicator.N)r   r   ÚXGCommunicatorFinalizer   r   r   Úfinalizer   6   s   € ä”×+Ñ+Ó-Õ.r   c                  ó.   — t        j                  «       } | S )zjGet rank of current process.

    Returns
    -------
    rank : int
        Rank of current process.
    )r   ÚXGCommunicatorGetRank©Úrets    r   Úget_rankr    ;   s   € ô ×
$Ñ
$Ó
&€CØ€Jr   c                  ó.   — t        j                  «       } | S )zdGet total number workers.

    Returns
    -------
    n : int
        Total number of process.
    )r   ÚXGCommunicatorGetWorldSizer   s    r   Úget_world_sizer#   G   s   € ô ×
)Ñ
)Ó
+€CØ€Jr   c                  ó.   — t        j                  «       } | S )z.If the collective communicator is distributed.)r   ÚXGCommunicatorIsDistributed)Úis_dists    r   Úis_distributedr'   S   s   € ä×.Ñ.Ó0€GØ€Nr   Úmsgc                 ó  — t        | t        «      st        | «      } t        j                  «       }|dk7  r6t	        t        j
                  t        | j                  «       «      «      «       yt        | j                  «       d¬«       y)zòPrint message to the communicator.

    This function can be used to communicate the information of
    the progress to the communicator.

    Parameters
    ----------
    msg : str
        The message to be printed to the communicator.
    r   T)ÚflushN)	Ú
isinstanceÚstrr   r%   r   ÚXGCommunicatorPrintr   ÚstripÚprint)r(   r&   s     r   Úcommunicator_printr0   Y   sZ   € ô �cœ3ÔÜ�#‹hˆÜ×.Ñ.Ó0€GØ�!‚|Ü”D×,Ñ,¬U°3·9±9³;Ó-?Ó@ÕAäˆc�i‰i‹k Ö&r   c                  óÂ   — t        j                  «       } t        t        j                  t        j
                  | «      «      «       | j                  }|sJ ‚t        |«      S )zhGet the processor name.

    Returns
    -------
    name : str
        the name of processor(host)
    )ÚctypesÚc_char_pr   r   ÚXGCommunicatorGetProcessorNameÚbyrefÚvaluer   )Úname_strr6   s     r   Úget_processor_namer8   m   sD   € ô �‰Ó €HÜ”×3Ñ3´F·L±LÀÓ4JÓKÔLØ�N‰N€EÙ�LÜ�%‹=Ðr   ÚdataÚrootc           	      óX  — t        «       }t        j                  «       }||k(  r>| €J d«       ‚t        j                  | t        j
                  ¬«      }t        |«      |_        t        t        j                  t        j                  |«      t        j                  t        j                  «      |«      «       ||k7  r�t        j                  |j                  z  «       }t        t        j                  t        j                  |t        j                  «      |j                  |«      «       t        j                   |j"                  «      } ~| S t        t        j                  t        j                  t        j$                  «      t        j                  «      |j                  |«      «       ~| S )aS  Broadcast object from one node to all other nodes.

    Parameters
    ----------
    data : any type that can be pickled
        Input data, if current rank does not equal root, this can be None
    root : int
        Rank of the node to broadcast data from.

    Returns
    -------
    object : int
        the result of broadcast.
    z&need to pass in data when broadcasting)Úprotocol)r    r2   Úc_ulongÚpickleÚdumpsÚHIGHEST_PROTOCOLÚlenr6   r   r   ÚXGCommunicatorBroadcastr5   ÚsizeofÚc_charÚcastÚc_void_pÚloadsÚrawr3   )r9   r:   ÚrankÚlengthÚsÚdptrs         r   Ú	broadcastrM   |   s3  € ô ‹:€DÜ�^‰^Ó€FØˆt‚|ØÐÐIÐ!IÔIÜ�L‰L˜¬×(?Ñ(?Ô@ˆÜ˜1“vˆŒäÜ×$Ñ$Ü�L‰L˜Ó ¤&§-¡-´·±Ó"?Àó	
ôð
 ˆt‚|Ü—‘ §¡Ñ,Ó/ˆäÜ×(Ñ(Ü—‘˜D¤&§/¡/Ó2°F·L±LÀ$óô	
ô
 �|‰|˜DŸH™HÓ%ˆØð €Kô 	Ü×(Ñ(Ü—‘œFŸO™O¨AÓ.´·±Ó@À&Ç,Á,ÐPTóô	
ð
 Ø€Kr   Údtypec                 óp  — t        j                  d«      dt        j                  d«      dt        j                  d«      dt        j                  d«      dt        j                  d	«      d
t        j                  d«      dt        j                  d«      dt        j                  d«      dt        j                  d«      dt        j                  d«      dt        j                  d«      di}	 |j                  t        j                  d«      di«       | |vrt        d| › d�«      ‚||    S # t        $ r Y Œ#w xY w)NÚfloat16r   Úfloat32r	   Úfloat64é   Úint8é   Úint16é   Úint32é   Úint64é   Úuint8é   Úuint16é	   Úuint32é
   Úuint64é   Úfloat128é   z
data type z* is not supported on the current platform.)ÚnprN   ÚupdateÚ	TypeError)rN   Ú	dtype_maps     r   Ú
_map_dtyperj   ¬   s  € ä
�‰�Ó˜QÜ
�‰�Ó˜QÜ
�‰�Ó˜QÜ
�‰�Ó˜!Ü
�‰�Ó˜1Ü
�‰�Ó˜1Ü
�‰�Ó˜1Ü
�‰�Ó˜1Ü
�‰�Ó˜AÜ
�‰�Ó˜BÜ
�‰�Ó˜Bð€IðØ×Ñœ"Ÿ(™( :Ó.°Ð2Ô3ð �IÑÜ˜* U GÐ+UÐVÓWÐWà�UÑÐøô ò Ùðús   Ã+&D) Ä)	D5Ä4D5c                   ó(   — e Zd ZdZdZdZdZdZdZdZ	y)	ÚOpz#Supported operations for allreduce.r   r	   rS   re   rU   rW   N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚMAXÚMINÚSUMÚBITWISE_ANDÚ
BITWISE_ORÚBITWISE_XORr   r   r   rl   rl   Å   s#   „ á-à
€CØ
€CØ
€CØ€KØ€JØ�Kr   rl   Úopc           
      óh  — t        | t        j                  «      st        d«      ‚| j	                  «       j                  «       }t        t        j                  |j                  j                  t        j                  «      |j                  t        |j                  «      t        |«      «      «       |S )a'  Perform allreduce, return the result.

    Parameters
    ----------
    data :
        Input data.
    op :
        Reduction operator.

    Returns
    -------
    result :
        The result of allreduce, have same shape as data

    Notes
    -----
    This function is not thread-safe.
    z%allreduce only takes in numpy.ndarray)r+   rf   Úndarrayrh   ÚravelÚcopyr   r   ÚXGCommunicatorAllreducer2   Údata_asrF   Úsizerj   rN   Úint)r9   rw   Úbufs      r   Ú	allreducer�   Ñ   s   € ô& �dœBŸJ™JÔ'ÜÐ?Ó@Ð@Ø
�*‰*‹,×
Ñ
Ó
€CÜÜ×$Ñ$Ø�J‰J×ÑœvŸ™Ó/Ø�H‰HÜ�s—y‘yÓ!Ü�‹Gó		
ôð €Jr   c                  ó>   — t        t        j                  «       «       y)zKill the process.N)r   r   ÚXGCommunicatorSignalErrorr   r   r   Úsignal_errorr„   ò   s   € ä”×.Ñ.Ó0Õ1r   c                   óF   — e Zd ZdZdeddfd„Zdeeef   fd„Zde	ddfd„Z
y)ÚCommunicatorContextzNA context controlling collective communicator initialization and finalization.r   r   Nc                 ó\  — || _         d}|j                  |d «      �y t        «       }|d   sy 	 ddlm} |j
                  �*t        j                  j                  |j
                  «      }nd }|r0t        j                  j                  |d«      }|| j                   |<   y y # t        $ r Y y w xY w)NÚdmlc_nccl_pathÚUSE_DLOPEN_NCCLr   )Úlibzlibnccl.so.2)r   Úgetr   Únvidia.ncclrŠ   Ú__file__ÚosÚpathÚdirnameÚjoinÚImportError)Úselfr   ÚkeyÚbinforŠ   r�   r�   s          r   Ú__init__zCommunicatorContext.__init__ú   s¡   € ØˆŒ	ØˆØ�8‰8�C˜ÓÐ*Øä“ˆØÐ&Ò'Øð	å'ð
 �|‰|Ð'Ü)+¯©¯©¸¿¹Ó)F‘à�áÜ—w‘w—|‘| G¨^Ó<�Ø!%�—	‘	˜#’ð øô ò 	Ùð	ús   ®A/B Â	B+Â*B+c                 ó†   — t        di | j                  ¤Ž t        «       sJ ‚t        j	                  d«       | j                  S )Nz8-------------- communicator say hello ------------------r   )r   r   r'   ÚLOGGERÚdebug)r“   s    r   Ú	__enter__zCommunicatorContext.__enter__  s1   € ÜÑˆt�y‰yÒÜÔÑÜ�‰ÐOÔPØ�y‰yÐr   c                 óB   — t        «        t        j                  d«       y )Nz7--------------- communicator say bye ------------------)r   r˜   r™   )r“   r   s     r   Ú__exit__zCommunicatorContext.__exit__  s   € ÜŒ
Ü�‰ÐNÕOr   )rm   rn   ro   rp   r   r–   r   r,   rš   r   rœ   r   r   r   r†   r†   ÷   sB   „ ÙXð˜sð  tó ð8˜4  S ™>ó ðP˜dð P tô Pr   r†   )r   N)+rp   r2   ÚloggingrŽ   r>   Úenumr   r   Útypingr   r   r   r   Únumpyrf   Ú_typingr
   Úcorer   r   r   r   r   r   Ú	getLoggerr˜   r   r   r   r    r#   r'   r0   r,   r8   rM   rN   rj   rl   ry   r�   r„   r†   r   r   r   ú<module>r¤      s  ðÙ 3ã Û Û 	Û ß  ß ,Ó ,ã å ß K× Kà	ˆ×	Ñ	Ð1Ó	2€ð!>�ð !>˜ó !>óH/ð
	�#ó 	ð	˜ó 	ð˜ó ð'˜Cð ' Dó 'ð(˜Có ð,�Bð ,˜cð , bó ,ð`�b—h‘hð  3ó ð2 ôˆó ó ðð�B—J‘Jð  Bð ¨2¯:©:ó óB2÷
'Pò 'Pr   