o
    װie-                     @   s   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZejj	j
jZdd ZG dd deZG dd dZdd	d
dZdd Zdd ZdS )    Nc              
   C   s6   z|  W S  |y } z
t |W  Y d }~S d }~ww N)repr)funcerrorse r   B/home/ubuntu/.local/lib/python3.10/site-packages/cupyx/_runtime.py_eval_or_error   s   r	   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )_InstallInfoc                 C   s`   |   }|d ur#tj|d}ttj|dttj|dd}nd d d}|| _|| _d S )Nz.datalibinclude)r   r   )_get_cupy_package_rootospathjoin_dir_or_nonecupy_package_root
data_paths)selfr   	data_rootr   r   r   r   __init__   s   
z_InstallInfo.__init__c                 C   s"   || j vrtd|| j | S )NzInvalid data type: {})r   
ValueErrorformat)r   	data_typer   r   r   get_data_path/   s   

z_InstallInfo.get_data_pathc                 C   s0   zt t}W n
 ty   Y d S w tj|S r   )inspectgetfilecupy	TypeErrorr   r   dirname)r   	cupy_pathr   r   r   r   4   s   z#_InstallInfo._get_cupy_package_rootN)__name__
__module____qualname__r   r   r   r   r   r   r   r
      s    r
   c                   @   s   e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZddddZdd ZdS )_RuntimeInfoNTfullc                   s<  t j| _tst j | _nt j | _tst j	 | _
nt j | _
tt jj | _t jj rWz
dd l}|jj}W n tyK   dd l}|j}Y nw |  jd| d7  _tt jjjt jjj| _tt jjjt jjj| _tt jjt| _d| _|rtdd t| _zddlm   t fddt| _!W n	 ty   Y nw td	d t| _"td
d t| _#d| _$|rtdd t| _$tdd t| _%zdd l&m  m'} | | _(W n	 ty   Y nw tszt jj)* }W n ty   d }Y nw |d u rd| _+n	tt jj,| | _+t j-dr|rt j.d nd| _/| j/| _0zdd l1m  m2  m3} | | _/t|j*|j4| _0W n
 tyD   Y nw t j-dr]|rVt j.d nd| _5| j5| _6z!dd l7m  m2  m8} | | _5|9 }|dkrzd}|| _6W n
 ty   Y nw t jj: | _;zdd l<m  m=}	 |	 | _>W n
 ty   Y nw zdd l?m  m2  m@}
 |
9 | _AW n
 ty   Y nw zdd lBm  m2  mC} | | _DW n
 ty   Y nw t jEjF| _Gz
dd lH}|j| _IW n
 ty    Y nw tJjKjL| _Mzdd lN}|jKjL| _OW d S  ty   Y d S w )Nr   z (CUDA Python: )z(available)c                   S      t jjt jj S r   )r   cudacublas
getVersiondeviceget_cublas_handler   r   r   r   <lambda>       
z'_RuntimeInfo.__init__.<locals>.<lambda>cufftc                      s      S r   )r+   r   r0   r   r   r.      s    c                   S      t jj S r   )r   r)   curandr+   r   r   r   r   r.          c                   S   r2   r   )r   r)   cusolver_getVersionr   r   r   r   r.      r4   c                   S   r(   r   )r   r)   cusparser+   r,   get_cusparse_handler   r   r   r   r.      r/   c                   S   r2   r   )r   r)   nvrtcr+   r   r   r   r   r.      r4   z(NVRTC unavailable)cudnnz0(not loaded; try `import cupy.cuda.cudnn` first)ncclz/(not loaded; try `import cupy.cuda.nccl` first)z	(unknown))Pr   __version__cupy_versionis_hipr)   get_cuda_path	cuda_path_environmentget_rocm_pathget_nvcc_path	nvcc_pathget_hipcc_pathstrdriverget_build_versioncuda_build_version_is_cuda_pythoncuda.bindingsbindingsImportErrorr	   runtimedriverGetVersionCUDARuntimeErrorcuda_driver_versionruntimeGetVersioncuda_runtime_versionget_local_runtime_version	Exceptioncuda_local_runtime_versioncublas_version	cupy.cudar1   cufft_versioncurand_versioncusolver_versioncusparse_versionnvrtc_versioncupy.cuda.thrustthrustthrust_versionr9   r+   cuda_extra_include_dirs$_get_include_dir_from_conda_or_wheel_can_attempt_preload_preload_librarycudnn_build_versioncudnn_versioncupy_backends.cuda.libs.cudnnlibsr:   
CuDNNErrornccl_build_versionnccl_runtime_versioncupy_backends.cuda.libs.ncclr;   get_versioncubcub_build_versioncupy.cuda.jitifyjitifyjitify_build_version cupy_backends.cuda.libs.cutensorcutensorcutensor_version"cupy_backends.cuda.libs.cusparselt
cusparseltcusparselt_version_utilcython_build_vercython_build_versionCythoncython_versionnumpyversionfull_versionnumpy_versionscipyscipy_version)r   r&   r)   cuda_versionr_   r]   r:   r;   rk   rq   rt   rw   r|   r   r   r0   r   r   b   s   








z_RuntimeInfo.__init__c                 C   s  dt   fdt  fd| jfdtsdndfd| jfd| jfd	| jfd
| jfd| jftr-dnd| j	fd| j
fd| jfd| j d| j dfd| jfg}|d| jfd| jfd| jfd| jfd| jfd| jfd| jfd| jfd| jfg	7 }|d| jfd| jfd| jfd | jfd!| jfd"| jfg7 }d#}ztjj ! }W n$ tjj j"y } zd$|j#d# vrt$%d%|  W Y d }~nd }~ww t&|D ]h}tj'|W}tjj (|}d&)||d' * f}d()||j+f}tr
z|d) * }	W n t,y   d*t-|d+  }	Y nw d,)||	f}	nd-)||j.f}	|||	|g7 }W d    n	1 s$w   Y  qt/d.d/ |D d0 }
d1t-|
 d2 }t01 }|D ]\}}|2|)|| qC|3 S )3NOSzPython VersionzCuPy VersionzCuPy PlatformzNVIDIA CUDAzAMD ROCmzNumPy VersionzSciPy VersionzCython Build VersionzCython Runtime Versionz	CUDA Rootz
hipcc PATHz	nvcc PATHzCUDA Build VersionzCUDA Driver VersionzCUDA Runtime Versionz (linked to CuPy) / z (locally installed)zCUDA Extra Include DirszcuBLAS VersionzcuFFT VersionzcuRAND VersionzcuSOLVER VersionzcuSPARSE VersionzNVRTC VersionzThrust VersionzCUB Build VersionzJitify Build VersionzcuDNN Build VersionzcuDNN VersionzNCCL Build VersionzNCCL Runtime VersionzcuTENSOR VersionzcuSPARSELt Build Versionr   ErrorNoDevicez!Failed to detect number of GPUs: zDevice {} NamenamezDevice {} PCI Bus IDgcnArchNamegfxgcnArchzDevice {} ArchzDevice {} Compute Capabilityc                 S   s   g | ]}t |d  qS )r   )len).0rr   r   r   
<listcomp>P  s    z(_RuntimeInfo.__str__.<locals>.<listcomp>   z{:z}: {}
)4platformpython_versionr=   r>   r   r   r{   r}   r@   rD   rI   rQ   rS   rV   ra   rW   rY   rZ   r[   r\   r]   r`   ro   rr   re   rf   rj   rk   ru   rx   r   r)   rN   getDeviceCountrP   argswarningswarnrangeDevicegetDevicePropertiesr   decode
pci_bus_idKeyErrorrF   compute_capabilitymaxioStringIOwritegetvalue)r   recordsdevice_countr   	device_idr,   propsr   pci_busarchwidthfmtskvr   r   r   __str__  s   

	
z_RuntimeInfo.__str__)r!   r"   r#   r=   r@   rI   rQ   rS   rV   rW   rY   rZ   r[   r\   r]   r`   ra   re   rf   rj   rk   ro   rr   ru   rx   r{   r}   r   r   r   r   r   r   r   r   r$   <   s<     *r$   Tr%   c                 C   s
   t | dS )Nr%   )r$   r%   r   r   r   get_runtime_infoY  s   
r   c                   C   s   t  S r   )r
   r   r   r   r   get_install_info]  s   r   c                 C   s   t j| r| S dS )z$Returns None if path does not exist.N)r   r   isdir)r   r   r   r   r   a  s   r   )r   r   r   r   r   r~   r   cupy_backendsr)   apirN   r>   r	   objectr
   r$   r   r   r   r   r   r   r   <module>   s"    
"  