
    
9j<(              
         S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSr/ r/ r0 rS rS rS r\R)                  \" S5      5        \R)                  \" S	5      5        \\S
'   S rS r\R)                  \" S	SSSSS5      5        \R)                  \" SSSSSS5      5        \\S'   S rS rS rS r\S:X  a  \" \	R8                  SS 5        gg)zM
CUDA Library Installer

Installs the latest CUDA library supported by CuPy.
    )annotationsNa  
******************************************************************************

The "cupyx.tools.install_library" tool is deprecated and will be removed in
a future CuPy release. To install NCCL/cuTENSOR libraries, please install them
via package managers (pip/conda) that are used to install CuPy.

You can use the following command to see if NCCL/cuTENSOR is already installed.
If you see the version number displayed for "NCCL Runtime Version" or "cuTENSOR
Version", they are available and enabled in your CuPy installation.

  $ python -c 'import cupy; cupy.show_config(_full=True)'

If you see "None" instead of the version number, and you installed CuPy via pip
or conda, you can get the instructions to install these libraries by running
the following commands:

  $ python -c 'import cupy.cuda.nccl'
  $ python -c 'import cupy.cuda.cutensor'

******************************************************************************
c                    SSU  SU 3-   $ )Nz7https://developer.download.nvidia.com/compute/cutensor/zredist/libcutensor/z-x86_64/ )platformfilenames     U/home/wildlama/miniconda3/lib/python3.13/site-packages/cupyx/tools/install_library.py_make_cutensor_urlr	   5   s"     	B
hZxz:	;<    c                    U UU[        SU5      SR                  U5      SR                  U5      /S.[        SU5      SS/S.S.S	.$ )
Nlinuxzlibcutensor.so.{}zlibcutensorMg.so.{}url	filenameswindowszcutensor.dllzcutensorMg.dll)Linux:x86_64zWindows:x86_64)cudacutensormin_pypi_versionassets)r	   format)cuda_versionpublic_versionr   filename_linuxfilename_windowss        r   __make_cutensor_recordr   <   si     ", *'>B'..~>)00@ *)5EF,.>?
	 r
   c           	     X    U R                  S5      S   n[        U SSSU S3SU S35      $ )	N.r   z2.4.1z2.3.0z%libcutensor-linux-x86_64-2.4.1.4_cudaz-archive.tar.xzz'libcutensor-windows-x86_64-2.4.1.4_cudaz-archive.zip)splitr   )r   
cuda_majors     r   _make_cutensor_recordr    S   sE    
 ##C(+J!gw
/
|?K
1*\J r
   z12.xz13.xr   c                    SSU  SU 3-   $ )Nz:https://developer.download.nvidia.com/compute/redist/nccl/v/r   )r   r   s     r   _make_nccl_urlr$   e   s#     	E
N1XJ'	()r
   c                    U UU[        X$5      SR                  U5      /S.[        X%5      SR                  U5      /S.S.S.$ )Nzlibnccl.so.{}r   )r   zLinux:aarch64)r   ncclr   r   )r$   r   )r   full_versionr   r   filename_linux_x86_64filename_linux_aarch64s         r   _make_nccl_recordr*   l   sb     , &";-44\BC &"<-44\BC
	 r
   z2.27.7z!nccl_2.27.7-1+cuda13.0_x86_64.txzz"nccl_2.27.7-1+cuda13.0_aarch64.txzz2.25.1z2.18.1z!nccl_2.25.1-1+cuda12.8_x86_64.txzz"nccl_2.25.1-1+cuda12.8_aarch64.txzr&   c                   SS0n[         R                  S:  d  U R                  S5      (       a  0 n [        R                  " X40 UD6  g ! [        R
                   ac    [        S5         [        R                  " USS9  [        R                  " SS	U S
U/SS9   g ! [        R                   a    Sn[        U5      ef = ff = f)Nfilterdata)      z.zipz`The archive format is not supported in your Python environment. Falling back to "tar" command...T)exist_oktarxfz-C)checkz2Failed to extract the archive using "tar" command.)sysversion_infoendswithshutilunpack_archive	ReadErrorprintosmakedirs
subprocessrunCalledProcessErrorRuntimeError)r   extract_dirkwargsmsgs       r   _unpack_archiverD      s    F
'!X%6%6v%>%>$h>v> 	$ > 	?	$KKd3NNhk:$H,, 	$FCs##	$	$s   A
 
C*/B"B==Cc                d	   US:X  a  US;   a  OUS:w  a  [        S5      eS n[        nXR    H  nUS   U :X  d  M    O:   [        SR                  [        XR    Vs/ s H  ofS   PM	     sn5      5      5      eUc  [        R
                  R                  S5      n[        XX$U   5      n[        R
                  R                  U5      (       a  [        SR                  U5      5      e[        R                  " 5        S	U 3nUS
   R                  US 5      n	U	c  [        SR                  U5      5      eUS:X  a!  [        S5        [        S5        [        5         O	US:X  a  O e[        SR                  X$U   US   U5      5        U	S   n
[        SR                  U
5      5        [        R                  " 5        n[        [        R
                  R!                  U[        R
                  R#                  U
5      5      S5       n[$        R&                  R)                  U
5       nUR+                  UR-                  5       5        S S S 5        S S S 5        [        S5        [        R
                  R!                  US5      n[/        WR0                  U5        [        R2                  " U5      n[5        U5      S:X  d   eUS   n[        S5        US:X  GaN  Sn[6        R8                  " [        R
                  R!                  UUS5      [        R
                  R!                  US5      5        [        R                  " 5       S:X  aT  [6        R8                  " [        R
                  R!                  UUS5      [        R
                  R!                  US5      5        [6        R8                  " [        R
                  R!                  UUS5      [        R
                  R!                  US5      5        [6        R8                  " [        R
                  R!                  UUU5      U5        O>US:X  a6  [6        R8                  " [        R
                  R!                  UU5      U5        O e[        S5        S S S 5        [        S5        g s  snf ! , (       d  f       GNF= f! , (       d  f       GNP= f! , (       d  f       NC= f)Nr&   )x86_64aarch64rF   zK
Currently this tool only supports x86_64 or aarch64 architecture for NCCL.r   zB
The CUDA version specified is not supported.
Should be one of {}.z~/.cupy/cuda_libzb
The destination directory {} already exists.
Remove the directory first if you want to reinstall.:r   z,
The current platform ({}) is not supported.r   zyBy downloading and using cuTENSOR, you accept the terms and conditions of the NVIDIA cuTENSOR Software License Agreement:z4  https://docs.nvidia.com/cuda/cutensor/license.htmlz#Installing {} {} for CUDA {} to: {}r   zDownloading {}...wbzExtracting...extract   r   zInstalling...LICENSEincludeWindowsbinlibzCleaning up...zDone!)r@   library_recordsr   strr;   path
expandusercalculate_destinationexistsr   systemgetr:   tempfileTemporaryDirectoryopenjoinbasenameurllibrequesturlopenwritereadrD   namelistdirlenr7   move)r   prefixlibraryarchrecordlib_recordsxdestinationtarget_platformassetr   tmpdirfresponseoutdirsubdirdir_namelicenses                     r   install_librw      s   &T%::		 N O 	OF!K&&>T! '  s{7K#L7K!fI7K#LMNP 	P ~##$67'ggOK	ww~~k"" 88>{8KM 	M "*+1TF3O8  $7E} //5vo/FH 	H * O 	PDE	F	u	
/
6
6&.+? @ ,C	

$
$S
)*		$	$	&&"'',,vrww'7'7'<=tD'',( - E 	ofi0'F#6{a!9oj GKKVXy9[)46  I-GGLL59GGLLe46 KKVXu5[%02 KKVXw7FKKVX6D5? 
'@ 
'N $MB -, ED 
'	&sD   Q86AR!> R Q=>RHR!=
RR
R	R!!
R/c                B    [         R                  R                  XX#5      $ )ziCalculates the installation directory.

~/.cupy/cuda_lib/{cuda_version}/{library_name}/{library_version}
)r;   rS   r\   )rg   r   rP   lib_vers       r   rU   rU      s    
 77<<c33r
   c                   [         R                  " 5       nUR                  SSS/SSS9  UR                  S[        SSS	9  UR                  S
SS/S SS9  UR                  S[        S SS9  UR                  SSS/SSS9  UR	                  U 5      nUR
                  cW  [        R                  " 5       R                  R                  5       nUS;   a  SUl        OUS:X  a  SUl        O[        SU 35      eUR                  b.  [        R                  R                  UR                  5      Ul        UR                  S:X  aF  [!        ["        5        [%        UR&                  UR                  UR(                  UR
                  5        g UR                  S:X  a0  [!        [*        R,                  " [.        UR(                     SS95        g  e)Nz	--libraryr   r&   TzLibrary to install)choicesrequiredhelpz--cudazCUDA version)typer|   r}   z--archrF   rG   z'Target architecture (x86_64 or aarch64))r{   defaultr}   z--prefixzInstall destination)r~   r   r}   z--actioninstalldumpzAction to perform)rF   amd64zunsupported architecture:    )indent)argparseArgumentParseradd_argumentrR   
parse_argsri   r   unamemachinelowerAssertionErrorrg   r;   rS   abspathactionr:   _deprecation_messagerw   r   rh   jsondumpsrQ   )argsparserparamsr   s       r   mainr      s   $$&F
!+V 4!%1  3 sT+  -
8Y*? $F  H 
d2  4

Y,? )0  2 t$F{{.."**002))"FK	!#FK #=gY!GHH}} 6}}	!"#FKKKK	!	&	 djj8CDur
   __main__rK   )__doc__
__future__r   r   r   r;   r   r7   r=   r4   rY   urllib.requestr^   r   _cutensor_records_nccl_recordsrQ   r	   r   r    appendr$   r*   rD   rw   rU   r   __name__argvr   r
   r   <module>r      s%   #   	    
   .  <.
   .v6 7   .v6 7/
 ).   &
Hh'(* +   &
Hh'(* + ( $$M`4'T z!" r
   