U
    ,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S )$    N)
namedtupleIS_WIN32)find_lib	find_file_env_path_tuplebyinfoc                 C   s&   | D ]\}}|dk	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
   9/tmp/pip-unpacked-wheel-eu7e0c37/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 dS d S )N)r   bin)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   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   s   t rdS dS d S )Nr   r   r   r
   r
   r
   r   _cudalib_path?   s    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   s    r*   c                  C   s   t  \} }t| |S )N)r*   r   )r   r   r
   r
   r   _get_cudalib_dirP   s    
r+   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   U   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   )	r0   r   r1   r2   r-   prefixr   dirnamer$   )Zis_conda_envpathsr
   r
   r   r   a   s    r   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)r0   environgetr   r2   )r3   Z	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   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_pathsr;   r:   r(   r+   )dr
   r
   r   r=      s    
r=   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)r0   r   r1   )Zpkg_libdevice_locationr
   r
   r   r      s    r   )r-   r"   r0   collectionsr   Znumba.core.configr   Znumba.misc.findlibr   r   r   r   r   r   r    r(   r)   r*   r+   r   r   r   r:   r=   r   r
   r
   r
   r   <module>   s(   


