o
    Td                     @   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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
   h/home/ncw/WWW/www-new/content/articles/pi-bbp/venv/lib/python3.10/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      t rdS dS )N)r   bin)r   lib64r   r
   r
   r
   r   _nvvm_lib_dir%      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,      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   r   )Nr   r   r   r
   r
   r
   r   _cudalib_pathA   r!   r/   c                   C   r   )N)libx64)r   r   r
   r
   r
   r   _cuda_home_static_cudalib_pathH   r!   r2   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   r&   r4   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   r2   r   r/   r   r   r
   r
   r   %_get_static_cudalib_dir_path_decisionZ   r&   r6   c                  C      t  \} }t| |S N)r4   r   r   r   r
   r
   r   _get_cudalib_dire      

r:   c                  C   r7   r8   )r6   r   r9   r
   r
   r   _get_static_cudalib_dirj   r;   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   o   s   r   c                  C   s@   t jt jtjd} | sdS td}|sdS t jt|S )MReturn path to directory containing the shared libraries of cudatoolkit.
    
conda-metaNr   )	rA   r$   rB   rC   r>   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|r&t j|s(dS td|d}|s2dS t j	t
|S )zAReturn path to directory containing the NVVM shared library.
    rG   Nr   )r   )rA   r$   rB   rC   r>   rH   r/   isdirr   rI   r*   )rJ   r   rK   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#   rA   r$   rI   rC   )nvvm_ctk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 )rF   Nr   r0   r#   rA   r$   rI   r   rC   )rM   env_dirsubdirr
   r
   r   r3      s   r3   c                  C   sB   t  } | sdS tjtj| }trdnd}tjj|g|R  S )zMReturn path to directory containing the static libraries of cudatoolkit.
    N)Libr1   )r0   rO   )rM   rP   dirsr
   r
   r   r5      s   r5   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)rA   environgetr$   rC   )rD   	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   


rX   c                  C   s0   t tdrtjS t 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static_cudalib_dir)hasattrget_cuda_pathsrY   rX   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)rA   r$   rB   )pkg_libdevice_locationr
   r
   r   r      s   r   ) r>   r(   rA   collectionsr   numba.core.configr   numba.misc.findlibr   r   r   r   r   r    r%   r.   r/   r2   r4   r6   r:   r<   r   r   r#   r   r3   r5   r   rX   r]   r   r
   r
   r
   r   <module>   s8    

