U
    hâËd·  ã                   @   sú   d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZm	Z	 edddgƒZ
dd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ ZdS )2é    N)Ú
namedtuple©ÚIS_WIN32)Úfind_libÚ	find_fileÚ_env_path_tupleÚbyÚinfoc                 C   s&   | D ]\}}|dk	r||f  S qdS )z»Find valid path from *options*, which is a list of 2-tuple of
    (name, path).  Return first pair where *path* is not None.
    If no valid path is found, return ('<unknown>', None)
    N)z	<unknown>N© )Úoptionsr   Údatar
   r
   úN/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/numba/cuda/cuda_paths.pyÚ_find_valid_path   s    r   c                  C   sH   dt ƒ fdtƒ fdtddƒfdtddƒfdtƒ fg} t| ƒ\}}||fS )NúConda environmentú"Conda environment (NVIDIA package)Ú	CUDA_HOMEÚnvvmÚ	libdeviceÚSystemzDebian package)Úget_conda_ctkÚget_nvidia_libdevice_ctkÚget_cuda_homeÚget_system_ctkÚget_debian_pkg_libdevicer   ©r   r   Úlibdirr
   r
   r   Ú_get_libdevice_path_decision   s    ûr   c                   C   s   t rdS dS d S )N)r   Úbin)r   Úlib64r   r
   r
   r
   r   Ú_nvvm_lib_dir%   s    r   c                  C   s@   dt ƒ fdtƒ fdttƒ Ž fdttƒ Ž fg} t| ƒ\}}||fS ©Nr   r   r   r   )r   Úget_nvidia_nvvm_ctkr   r   r   r   )r   r   Úpathr
   r
   r   Ú_get_nvvm_path_decision,   s    ür#   c                  C   s4   t ƒ \} }d}tt |¡|ƒ}t|d d�}t| |ƒS )Nzlibdevice(\.\d+)*\.bc$)Údefault)r   r   ÚreÚcompileÚmaxr   )r   r   ÚpatÚ
candidatesÚoutr
   r
   r   Ú_get_libdevice_paths7   s
    
r+   c                   C   s   t rdS dS d S )Nr   r   r   r
   r
   r
   r   Ú_cudalib_pathA   s    r,   c                   C   s   t rdS dS d S )N)ÚlibÚx64)r   r   r
   r
   r
   r   Ú_cuda_home_static_cudalib_pathH   s    r/   c                  C   s@   dt ƒ fdtƒ fdttƒ ƒfdttƒ ƒfg} t| ƒ\}}||fS r    )r   Úget_nvidia_cudalib_ctkr   r,   r   r   r   r
   r
   r   Ú_get_cudalib_dir_path_decisionO   s    ür1   c                  C   s@   dt ƒ fdtƒ fdttƒ Ž fdttƒ ƒfg} t| ƒ\}}||fS r    )r   Úget_nvidia_static_cudalib_ctkr   r/   r   r,   r   r   r
   r
   r   Ú%_get_static_cudalib_dir_path_decisionZ   s    ür3   c                  C   s   t ƒ \} }t| |ƒS ©N)r1   r   ©r   r   r
   r
   r   Ú_get_cudalib_dire   s    
r6   c                  C   s   t ƒ \} }t| |ƒS r4   )r3   r   r5   r
   r
   r   Ú_get_static_cudalib_dirj   s    
r7   c                  G   s2   t j d¡r.d}tj |¡r.tjj|f| žŽ S dS )zJReturn path to system-wide cudatoolkit; or, None if it doesn't exist.
    Úlinuxz/usr/local/cudaN)ÚsysÚplatformÚ
startswithÚosr"   ÚexistsÚjoin)ÚsubdirsÚbaser
   r
   r   r   o   s    r   c                  C   s@   t j t j tjd¡¡} | s dS tdƒ}|s0dS t j t|ƒ¡S )úMReturn path to directory containing the shared libraries of cudatoolkit.
    ú
conda-metaNr   )	r<   r"   r=   r>   r9   Úprefixr   Údirnamer'   )Úis_conda_envÚpathsr
   r
   r   r   {   s    r   c                  C   st   t j t j tjd¡¡} | s dS t j tjdtƒ ¡}t j |¡rLt j |¡sPdS td|d�}|sddS t j 	t
|ƒ¡S )zAReturn path to directory containing the NVVM shared library.
    rB   Nr   )r   )r<   r"   r=   r>   r9   rC   r,   Úisdirr   rD   r'   )rE   r   rF   r
   r
   r   r!   ‰   s    r!   c                  C   s(   t ƒ } | sdS tj | ¡}tj |d¡S )z?Return path to directory containing the libdevice library.
    Nr   )r!   r<   r"   rD   r>   )Únvvm_ctkZnvvm_dirr
   r
   r   r   š   s
    r   c                  C   s<   t ƒ } | sdS tj tj | ¡¡}tr*dnd}tj ||¡S )rA   Nr   r-   ©r!   r<   r"   rD   r   r>   )rH   Úenv_dirÚsubdirr
   r
   r   r0   ¤   s    r0   c                  C   s@   t ƒ } | sdS tj tj | ¡¡}tr*dnd}tjj|f|žŽ S )zMReturn path to directory containing the static libraries of cudatoolkit.
    N)ÚLibr.   )r-   rI   )rH   rJ   Údirsr
   r
   r   r2   ¯   s    r2   c                  G   s>   t j d¡}|dkr t j d¡}|dk	r:t jj|f| žŽ S dS )zqGet paths of CUDA_HOME.
    If *subdirs* are the subdirectory name to be appended in the resulting
    path.
    r   NZ	CUDA_PATH)r<   ÚenvironÚgetr"   r>   )r?   Z	cuda_homer
   r
   r   r   º   s
    r   c                  C   s.   t ƒ \} }td|ƒ}|r t|ƒnd }t| |ƒS )Nr   )r#   r   r'   r   )r   r"   r)   r
   r
   r   Ú_get_nvvm_pathÇ   s    

rP   c                  C   s4   t tdƒrtjS tƒ tƒ tƒ tƒ dœ} | t_| S dS )a@  Returns a dictionary mapping component names to a 2-tuple
    of (source_variable, info).

    The returned dictionary will have the following keys and infos:
    - "nvvm": file_path
    - "libdevice": List[Tuple[arch, file_path]]
    - "cudalib_dir": directory_path

    Note: The result of the function is cached.
    Ú_cached_result)r   r   Zcudalib_dirZstatic_cudalib_dirN)ÚhasattrÚget_cuda_pathsrQ   rP   r+   r6   r7   )Údr
   r
   r   rS   Î   s    
ürS   c                  C   s   d} t j | ¡sdS | S )z]
    Return the Debian NVIDIA Maintainers-packaged libdevice location, if it
    exists.
    z&/usr/lib/nvidia-cuda-toolkit/libdeviceN)r<   r"   r=   )Zpkg_libdevice_locationr
   r
   r   r   é   s    r   ) r9   r%   r<   Úcollectionsr   Znumba.core.configr   Znumba.misc.findlibr   r   r   r   r   r   r#   r+   r,   r/   r1   r3   r6   r7   r   r   r!   r   r0   r2   r   rP   rS   r   r
   r
   r
   r   Ú<module>   s6   

