U
    9%e                     @   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 )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
   T/var/www/html/Darija-Ai-API/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   

