a
    –§»aI  ã                   @   sÊ   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 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S )$é    N)ÚdefaultdictÚ
namedtuple©ÚIS_WIN32ÚIS_OSX)Úfind_libÚ	find_fileÚ_env_path_tupleÚbyÚinfoc                 C   s&   | D ]\}}|du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   úO/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/numba/cuda/cuda_paths.pyÚ_find_valid_path   s    r   c                  C   s@   dt ƒ fdtddƒfdtddƒfdtƒ fg} t| ƒ\}}||fS )NúConda environmentÚ	CUDA_HOMEÚnvvmÚ	libdeviceÚSystemzDebian package)Úget_conda_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 trdS dS d S )N)r   Úbin)r   Úlib)r   Úlib64r   r   r   r   r   Ú_nvvm_lib_dir$   s
    r    c                  C   s8   dt ƒ fdttƒ Ž fdttƒ Ž fg} t| ƒ\}}||fS ©Nr   r   r   )r   r   r    r   r   )r   r
   Úpathr   r   r   Ú_get_nvvm_path_decision-   s    ýr#   c                  C   sp   t ƒ \} }d}tt |¡|ƒ}ttƒ}|D ](}t ||¡}| d¡}||  |¡ q*dd„ | 	¡ D ƒ}t
| |ƒS )Nz0libdevice(\.(?P<arch>compute_\d+))?(\.\d+)*\.bc$Úarchc                 S   s   i | ]\}}|t |ƒ“qS r   )Úmax)Ú.0ÚkÚvr   r   r   Ú
<dictcomp>C   ó    z(_get_libdevice_paths.<locals>.<dictcomp>)r   r   ÚreÚcompiler   ÚlistÚsearchÚgroupÚappendÚitemsr	   )r
   r   ÚpatÚ
candidatesÚoutr"   Úmr$   r   r   r   Ú_get_libdevice_paths7   s    

r6   c                   C   s   t rdS trdS dS d S )Nr   r   r   r   r   r   r   r   Ú_cudalib_pathG   s
    r7   c                  C   s8   dt ƒ fdttƒ ƒfdttƒ ƒfg} t| ƒ\}}||fS r!   )r   r   r7   r   r   r   r   r   r   Ú_get_cudalib_dir_path_decisionP   s    ýr8   c                  C   s   t ƒ \} }t| |ƒS )N)r8   r	   )r
   r   r   r   r   Ú_get_cudalib_dirZ   s    
r9   c                  G   s4   t j d¡r0d}tj |¡r0tjj|g| ¢R Ž 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   _   s    r   c                  C   s@   t j t j tjd¡¡} | s dS tdƒ}|s0dS t j t|ƒ¡S )zMReturn path to directory containing the shared libraries of cudatoolkit.
    z
conda-metaNr   )	r>   r"   r?   r@   r;   Úprefixr   Údirnamer%   )Zis_conda_envÚpathsr   r   r   r   k   s    r   c                  G   s@   t j d¡}|du r t j d¡}|dur<t jj|g| ¢R Ž 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@   )rA   Z	cuda_homer   r   r   r   y   s
    r   c                  C   s.   t ƒ \} }td|ƒ}|r t|ƒnd }t| |ƒS )Nr   )r#   r   r%   r	   )r
   r"   r3   r   r   r   Ú_get_nvvm_path†   s    

rH   c                  C   s0   t tdƒrtjS 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_dirN)ÚhasattrÚget_cuda_pathsrI   rH   r6   r9   )Údr   r   r   rK   �   s    
ýrK   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   )r;   r+   r>   Úcollectionsr   r   Znumba.core.configr   r   Znumba.misc.findlibr   r   r	   r   r   r    r#   r6   r7   r8   r9   r   r   r   rH   rK   r   r   r   r   r   Ú<module>   s(   	
	
