o
    8ήc                     @   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S )$    N)
namedtupleIS_WIN32)find_lib	find_file_env_path_tuplebyinfoc                 C   s&   | D ]\}}|dur||f  S qdS )zFind 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
   </tmp/pip-target-vg8gfxp4/lib/python/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      t rdS dS )N)r   bin)r   lib64r   r
   r
   r
   r   _nvvm_lib_dir$      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+      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_paths5   s
   

r+   c                   C   r   )Nr   r   r   r
   r
   r
   r   _cudalib_path?   r   r,   c                  C   s8   dt  fdtt fdtt fg} t| \}}||fS r    )r   r   r,   r   r   r   r
   r
   r   _get_cudalib_dir_path_decisionF   r#   r-   c                  C   s   t  \} }t| |S )N)r-   r   )r   r   r
   r
   r   _get_cudalib_dirP   s   

r.   c                  G   s8   t jdrd}tj|rtjj|g| R  S d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   U   s   r   c                  C   s@   t jt jtjd} | sdS td}|sdS t jt|S )zMReturn path to directory containing the shared libraries of cudatoolkit.
    z
conda-metaNr   )	r3   r!   r4   r5   r0   prefixr   dirnamer'   )is_conda_envpathsr
   r
   r   r   a   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   N	CUDA_PATH)r3   environgetr!   r5   )r6   	cuda_homer
   r
   r   r   o   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   


r@   c                  C   s,   t tdrtjS t t t d} | t_| 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   cudalib_dir)hasattrget_cuda_pathsrA   r@   r+   r.   )dr
   r
   r   rD      s   
rD   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)r3   r!   r4   )pkg_libdevice_locationr
   r
   r   r      s   r   )r0   r%   r3   collectionsr   numba.core.configr   numba.misc.findlibr   r   r   r   r   r   r"   r+   r,   r-   r.   r   r   r   r@   rD   r   r
   r
   r
   r   <module>   s*    


